From 8760cf7f9a22bb2555c5a16150bbb9d4b4e1dd1e Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Sat, 23 Sep 2023 23:28:56 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(endpoints.py):=20import=20mi?= =?UTF-8?q?ssing=20dependencies=20to=20improve=20code=20readability=20and?= =?UTF-8?q?=20maintainability=20=F0=9F=94=A7=20fix(endpoints.py):=20genera?= =?UTF-8?q?te=20session=20ID=20if=20it=20is=20None=20to=20ensure=20a=20val?= =?UTF-8?q?id=20session=20ID=20is=20used=20=F0=9F=94=A7=20fix(endpoints.py?= =?UTF-8?q?):=20add=20backend=20information=20to=20the=20ProcessResponse?= =?UTF-8?q?=20to=20provide=20additional=20context=20=F0=9F=94=A7=20fix(sch?= =?UTF-8?q?emas.py):=20add=20backend=20field=20to=20the=20ProcessResponse?= =?UTF-8?q?=20schema=20to=20match=20the=20changes=20in=20the=20endpoints.p?= =?UTF-8?q?y=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/endpoints.py | 19 +++++++++++++++++-- src/backend/langflow/api/v1/schemas.py | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/api/v1/endpoints.py b/src/backend/langflow/api/v1/endpoints.py index b0fffebda..d47283839 100644 --- a/src/backend/langflow/api/v1/endpoints.py +++ b/src/backend/langflow/api/v1/endpoints.py @@ -7,7 +7,12 @@ from langflow.services.cache.utils import save_uploaded_file from langflow.services.database.models.flow import Flow from langflow.processing.process import process_graph_cached, process_tweaks from langflow.services.database.models.user.user import User -from langflow.services.getters import get_settings_service, get_task_service +from langflow.services.getters import ( + get_cache_service, + get_session_service, + get_settings_service, + get_task_service, +) from loguru import logger from fastapi import APIRouter, Depends, HTTPException, UploadFile, Body, status import sqlalchemy as sa @@ -122,6 +127,11 @@ async def process_flow( session_id = result.session_id else: + if session_id is None: + # Generate a session ID + session_id = get_session_service().generate_key( + session_id=session_id, data_graph=graph_data + ) task_id, task = await task_service.launch_task( process_graph_cached_task if task_service.use_celery @@ -132,7 +142,12 @@ async def process_flow( session_id, ) task_result = task.status - return ProcessResponse(result=task_result, id=task_id, session_id=session_id) + return ProcessResponse( + result=task_result, + id=task_id, + session_id=session_id, + backend=str(type(task_service.backend)), + ) except sa.exc.StatementError as exc: # StatementError('(builtins.ValueError) badly formed hexadecimal UUID string') if "badly formed hexadecimal UUID string" in str(exc): diff --git a/src/backend/langflow/api/v1/schemas.py b/src/backend/langflow/api/v1/schemas.py index 835c9fcb0..8e48eb3c9 100644 --- a/src/backend/langflow/api/v1/schemas.py +++ b/src/backend/langflow/api/v1/schemas.py @@ -53,6 +53,7 @@ class ProcessResponse(BaseModel): result: Any id: Optional[str] = None session_id: Optional[str] = None + backend: str = None # TaskStatusResponse(