refactor: add session_id to vertices without it in build_and_cache_graph_from_db
This commit is contained in:
parent
d309c2bd85
commit
a6dfe39882
1 changed files with 8 additions and 5 deletions
|
|
@ -204,16 +204,18 @@ def format_elapsed_time(elapsed_time: float) -> str:
|
||||||
return f"{minutes} {minutes_unit}, {seconds} {seconds_unit}"
|
return f"{minutes} {minutes_unit}, {seconds} {seconds_unit}"
|
||||||
|
|
||||||
|
|
||||||
async def build_and_cache_graph_from_db(
|
async def build_and_cache_graph_from_db(flow_id: str, session: Session, chat_service: "ChatService"):
|
||||||
flow_id: str,
|
|
||||||
session: Session,
|
|
||||||
chat_service: "ChatService",
|
|
||||||
):
|
|
||||||
"""Build and cache the graph."""
|
"""Build and cache the graph."""
|
||||||
flow: Optional[Flow] = session.get(Flow, flow_id)
|
flow: Optional[Flow] = session.get(Flow, flow_id)
|
||||||
if not flow or not flow.data:
|
if not flow or not flow.data:
|
||||||
raise ValueError("Invalid flow ID")
|
raise ValueError("Invalid flow ID")
|
||||||
graph = Graph.from_payload(flow.data, flow_id)
|
graph = Graph.from_payload(flow.data, flow_id)
|
||||||
|
for vertex_id in graph._has_session_id_vertices:
|
||||||
|
vertex = graph.get_vertex(vertex_id)
|
||||||
|
if vertex is None:
|
||||||
|
raise ValueError(f"Vertex {vertex_id} not found")
|
||||||
|
if vertex._raw_params.get("session_id") is None:
|
||||||
|
vertex.update_raw_params({"session_id": flow_id})
|
||||||
await chat_service.set_cache(flow_id, graph)
|
await chat_service.set_cache(flow_id, graph)
|
||||||
return graph
|
return graph
|
||||||
|
|
||||||
|
|
@ -317,3 +319,4 @@ def parse_exception(exc):
|
||||||
if hasattr(exc, "body"):
|
if hasattr(exc, "body"):
|
||||||
return exc.body["message"]
|
return exc.body["message"]
|
||||||
return str(exc)
|
return str(exc)
|
||||||
|
return str(exc)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue