Add build_graph_and_generate_result function to process.py
This commit is contained in:
parent
0b68decdfc
commit
2a69254eda
1 changed files with 18 additions and 2 deletions
|
|
@ -7,9 +7,11 @@ from langchain.schema import AgentAction, Document
|
||||||
from langchain.vectorstores.base import VectorStore
|
from langchain.vectorstores.base import VectorStore
|
||||||
from langchain_core.messages import AIMessage
|
from langchain_core.messages import AIMessage
|
||||||
from langchain_core.runnables.base import Runnable
|
from langchain_core.runnables.base import Runnable
|
||||||
|
from langflow.graph.graph.base import Graph
|
||||||
from langflow.interface.custom.custom_component import CustomComponent
|
from langflow.interface.custom.custom_component import CustomComponent
|
||||||
from langflow.interface.run import build_sorted_vertices, get_memory_key, update_memory_keys
|
from langflow.interface.run import build_sorted_vertices, get_memory_key, update_memory_keys
|
||||||
from langflow.services.deps import get_session_service
|
from langflow.services.deps import get_session_service
|
||||||
|
from langflow.services.session.service import SessionService
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
@ -220,13 +222,27 @@ async def process_graph_cached(
|
||||||
graph, artifacts = session if session else (None, None)
|
graph, artifacts = session if session else (None, None)
|
||||||
if not graph:
|
if not graph:
|
||||||
raise ValueError("Graph not found in the session")
|
raise ValueError("Graph not found in the session")
|
||||||
|
|
||||||
|
result = await build_graph_and_generate_result(graph, inputs, artifacts, session_id, session_service)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
async def build_graph_and_generate_result(
|
||||||
|
graph: "Graph",
|
||||||
|
session_id: str,
|
||||||
|
inputs: Optional[Union[dict, List[dict]]] = None,
|
||||||
|
artifacts: Optional[Dict[str, Any]] = None,
|
||||||
|
session_service: Optional[SessionService] = None,
|
||||||
|
):
|
||||||
|
"""Build the graph and generate the result"""
|
||||||
built_object = await graph.build()
|
built_object = await graph.build()
|
||||||
processed_inputs = process_inputs(inputs, artifacts or {})
|
processed_inputs = process_inputs(inputs, artifacts or {})
|
||||||
result = await generate_result(built_object, processed_inputs)
|
result = await generate_result(built_object, processed_inputs)
|
||||||
# langchain_object is now updated with the new memory
|
# langchain_object is now updated with the new memory
|
||||||
# we need to update the cache with the updated langchain_object
|
# we need to update the cache with the updated langchain_object
|
||||||
session_service.update_session(session_id, (graph, artifacts))
|
if session_id and session_service:
|
||||||
|
session_service.update_session(session_id, (graph, artifacts))
|
||||||
return Result(result=result, session_id=session_id)
|
return Result(result=result, session_id=session_id)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue