Add duration tracking to build_vertex function

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-01-31 17:22:04 -03:00
commit 29bcf3e43f
2 changed files with 7 additions and 2 deletions

View file

@ -287,6 +287,8 @@ async def build_vertex(
cache = chat_service.get_cache(flow_id)
graph = cache.get("result")
result_dict = {}
duration = ""
start_time = time.perf_counter()
if tweaks:
graph = process_tweaks_on_graph(graph, tweaks)
if not isinstance(graph, Graph):
@ -303,7 +305,8 @@ async def build_vertex(
# to the frontend
vertex.set_artifacts()
artifacts = vertex.artifacts
result_dict = ResultDict(results=result_dict, artifacts=artifacts)
duration = format_elapsed_time(time.perf_counter() - start_time)
result_dict = ResultDict(results=result_dict, artifacts=artifacts, duration=duration)
except Exception as exc:
params = str(exc)
valid = False

View file

@ -221,9 +221,11 @@ class VerticesOrderResponse(BaseModel):
class ResultDict(BaseModel):
"""Outputs of the vertex build process."""
results: Optional[Any] = Field(default_factory=dict)
artifacts: Optional[Any] = Field(default_factory=dict)
"""Outputs of the vertex build process."""
duration: Optional[float] = None
class VertexBuildResponse(BaseModel):