From 5c290c0014c2f8b1747fe3c2c2807a36d5a708ad Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 14 Dec 2023 17:44:25 -0300 Subject: [PATCH] Pull start_time out of try block --- src/backend/langflow/api/v1/chat.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index 059ad23b6..de10b318d 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -1,18 +1,21 @@ import time -from fastapi import APIRouter, Depends, HTTPException, Query, WebSocket, WebSocketException, status +from fastapi import (APIRouter, Depends, HTTPException, Query, WebSocket, + WebSocketException, status) from fastapi.responses import StreamingResponse -from loguru import logger -from sqlmodel import Session - from langflow.api.utils import build_input_keys_response, format_elapsed_time -from langflow.api.v1.schemas import BuildStatus, BuiltResponse, InitResponse, StreamData +from langflow.api.v1.schemas import (BuildStatus, BuiltResponse, InitResponse, + StreamData) from langflow.graph.graph.base import Graph -from langflow.services.auth.utils import get_current_active_user, get_current_user_by_jwt +from langflow.services.auth.utils import (get_current_active_user, + get_current_user_by_jwt) from langflow.services.cache.service import BaseCacheService from langflow.services.cache.utils import update_build_status from langflow.services.chat.service import ChatService -from langflow.services.deps import get_cache_service, get_chat_service, get_session +from langflow.services.deps import (get_cache_service, get_chat_service, + get_session) +from loguru import logger +from sqlmodel import Session router = APIRouter(tags=["Chat"]) @@ -149,13 +152,12 @@ async def stream_build( logger.debug("No user_id found in cache_service") user_id = None for i, vertex in enumerate(graph.generator_build(), 1): + start_time = time.perf_counter() try: log_dict = { "log": f"Building node {vertex.vertex_type}", } yield str(StreamData(event="log", data=log_dict)) - # time this - start_time = time.perf_counter() if vertex.is_task: vertex = await try_running_celery_task(vertex, user_id) else: