From ed7ba0230d7c3e1d25304ae199d8f40e0449c99d Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 16 十月 2024 15:26:30 +0800 Subject: [PATCH] 对话兼容报错没data前缀,ragflow会话历史传空时创建会话 --- app/service/ragflow.py | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) diff --git a/app/service/ragflow.py b/app/service/ragflow.py index 934af1a..e4d5657 100644 --- a/app/service/ragflow.py +++ b/app/service/ragflow.py @@ -80,3 +80,29 @@ for item in data ] return result + + async def set_session(self, token: str, dialog_id: str, name: str, chat_id: str, is_new: bool) -> list: + url = f"{self.base_url}/v1/conversation/set?dialog_id={dialog_id}" + headers = { + "Authorization": token + } + + data = {"dialog_id": dialog_id, + "name": name, + "is_new": is_new, + "conversation_id": chat_id, + } + + async with httpx.AsyncClient() as client: + response = await client.post(url, headers=headers, json=data) + if response.status_code != 200: + return [] + return [{ + "content": "浣犲ソ锛� 鎴戞槸浣犵殑鍔╃悊锛屾湁浠�涔堝彲浠ュ府鍒颁綘鐨勫悧锛�", + "role": "assistant" + }, + { + "content": name, + "doc_ids": [], + "role": "user" + }] -- Gitblit v1.8.0