From 3c43a7aee853a4d6fd108c5dbc39a6f876a22f6f Mon Sep 17 00:00:00 2001 From: so95 Date: Wed, 12 Mar 2025 16:01:44 +0700 Subject: [PATCH] =?UTF-8?q?For=20an=20Agent=20with=20an=20Input=20Begin=20?= =?UTF-8?q?value,=20on=20the=20first=20call=20the=20return=20=E2=80=A6=20(?= =?UTF-8?q?#5957)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …session_id does not exist in the session For an Agent with an Input Begin value, on the first call the return session_id does not exist in the session ### What problem does this PR solve? ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/db/services/canvas_service.py | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/api/db/services/canvas_service.py b/api/db/services/canvas_service.py index 9e26510a9..3fbb29610 100644 --- a/api/db/services/canvas_service.py +++ b/api/db/services/canvas_service.py @@ -86,21 +86,9 @@ def completion(tenant_id, agent_id, question, session_id=None, stream=True, **kw "dsl": cvs.dsl } API4ConversationService.save(**conv) - if query: - yield "data:" + json.dumps({"code": 0, - "message": "", - "data": { - "session_id": session_id, - "answer": canvas.get_prologue(), - "reference": [], - "param": canvas.get_preset_param() - } - }, - ensure_ascii=False) + "\n\n" - yield "data:" + json.dumps({"code": 0, "message": "", "data": True}, ensure_ascii=False) + "\n\n" - return - else: - conv = API4Conversation(**conv) + + + conv = API4Conversation(**conv) else: e, conv = API4ConversationService.get_by_id(session_id) assert e, "Session not found!" @@ -130,7 +118,7 @@ def completion(tenant_id, agent_id, question, session_id=None, stream=True, **kw continue for k in ans.keys(): final_ans[k] = ans[k] - ans = {"answer": ans["content"], "reference": ans.get("reference", [])} + ans = {"answer": ans["content"], "reference": ans.get("reference", []), "param": canvas.get_preset_param()} ans = structure_answer(conv, ans, message_id, session_id) yield "data:" + json.dumps({"code": 0, "message": "", "data": ans}, ensure_ascii=False) + "\n\n" @@ -160,8 +148,8 @@ def completion(tenant_id, agent_id, question, session_id=None, stream=True, **kw canvas.reference.append(final_ans["reference"]) conv.dsl = json.loads(str(canvas)) - result = {"answer": final_ans["content"], "reference": final_ans.get("reference", [])} + result = {"answer": final_ans["content"], "reference": final_ans.get("reference", []) , "param": canvas.get_preset_param()} result = structure_answer(conv, result, message_id, session_id) API4ConversationService.append_message(conv.id, conv.to_dict()) yield result - break \ No newline at end of file + break