From 255f4ccffce0598327b10cdcadeae7a7a7e3aa95 Mon Sep 17 00:00:00 2001 From: Kevin Hu Date: Mon, 9 Dec 2024 17:37:36 +0800 Subject: [PATCH] Fix session API issues. (#3939) ### What problem does this PR solve? ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/apps/sdk/session.py | 4 ++-- api/db/services/canvas_service.py | 2 ++ api/db/services/conversation_service.py | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/api/apps/sdk/session.py b/api/apps/sdk/session.py index 14b840eca34..a779fe9c70e 100644 --- a/api/apps/sdk/session.py +++ b/api/apps/sdk/session.py @@ -374,14 +374,14 @@ def chatbot_completions(dialog_id): req["quote"] = False if req.get("stream", True): - resp = Response(iframe_completion(objs[0].tenant_id, dialog_id, **req), mimetype="text/event-stream") + resp = Response(iframe_completion(dialog_id, **req), mimetype="text/event-stream") resp.headers.add_header("Cache-control", "no-cache") resp.headers.add_header("Connection", "keep-alive") resp.headers.add_header("X-Accel-Buffering", "no") resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8") return resp - for answer in agent_completion(objs[0].tenant_id, dialog_id, **req): + for answer in iframe_completion(dialog_id, **req): return get_result(data=answer) diff --git a/api/db/services/canvas_service.py b/api/db/services/canvas_service.py index cea0998cbc9..c51ffeee573 100644 --- a/api/db/services/canvas_service.py +++ b/api/db/services/canvas_service.py @@ -89,6 +89,8 @@ def completion(tenant_id, agent_id, question, session_id=None, stream=True, **kw assert e, "Session not found!" canvas = Canvas(json.dumps(conv.dsl), tenant_id) + if not conv.message: + conv.message = [] messages = conv.message question = { "role": "user", diff --git a/api/db/services/conversation_service.py b/api/db/services/conversation_service.py index b4aca45e7d1..03092ece598 100644 --- a/api/db/services/conversation_service.py +++ b/api/db/services/conversation_service.py @@ -176,6 +176,8 @@ def iframe_completion(dialog_id, question, session_id=None, stream=True, **kwarg e, conv = API4ConversationService.get_by_id(session_id) assert e, "Session not found!" + if not conv.message: + conv.message = [] messages = conv.message question = { "role": "user",