From 02fb7a88e3afb3317b6c71872ad99db49af18f1c Mon Sep 17 00:00:00 2001 From: Kevin Hu Date: Wed, 4 Sep 2024 19:11:55 +0800 Subject: [PATCH] fix issue wrong agent prologue for api (#2246) ### What problem does this PR solve? #2242 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- agent/canvas.py | 5 ++++- api/apps/api_app.py | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/agent/canvas.py b/agent/canvas.py index 0561c44b2..cb939a0f3 100644 --- a/agent/canvas.py +++ b/agent/canvas.py @@ -299,4 +299,7 @@ class Canvas(ABC): pat = " => ".join([p.split(":")[0] for p in path[0:l]]) return pat + " => " + pat - return False + return + + def get_prologue(self): + return self.components["begin"]["obj"]._param.prologue diff --git a/api/apps/api_app.py b/api/apps/api_app.py index 483243e4d..601774a05 100644 --- a/api/apps/api_app.py +++ b/api/apps/api_app.py @@ -151,14 +151,17 @@ def set_conversation(): req = request.json try: if objs[0].source == "agent": - e, c = UserCanvasService.get_by_id(objs[0].dialog_id) + e, cvs = UserCanvasService.get_by_id(objs[0].dialog_id) if not e: return server_error_response("canvas not found.") + if not isinstance(cvs.dsl, str): + cvs.dsl = json.dumps(cvs.dsl, ensure_ascii=False) + canvas = Canvas(cvs.dsl, objs[0].tenant_id) conv = { "id": get_uuid(), - "dialog_id": c.id, + "dialog_id": cvs.id, "user_id": request.args.get("user_id", ""), - "message": [{"role": "assistant", "content": "Hi there!"}], + "message": [{"role": "assistant", "content": canvas.get_prologue()}], "source": "agent" } API4ConversationService.save(**conv)