From c0d11dac469251c71b036c757c788615285c9683 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 15 十一月 2024 10:57:10 +0800
Subject: [PATCH] 毕昇对话历史只返回了一条修正,按时间正序排列吧,json乱码修正

---
 app/service/bisheng.py |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/app/service/bisheng.py b/app/service/bisheng.py
index ad5d084..e55dbb7 100644
--- a/app/service/bisheng.py
+++ b/app/service/bisheng.py
@@ -73,6 +73,30 @@
             ]
             return result
 
+    async def get_session_log(self, token: str, agent_id: str, conversation_id: str):
+        url = (
+            f"{self.base_url}/api/v1/chat/history?"
+            f"flow_id={agent_id}&"
+            f"chat_id={conversation_id}&page_size=30&id="
+        )
+        headers = {'cookie': f"access_token_cookie={token};"}
+        async with httpx.AsyncClient() as client:
+            response = await client.get(url, headers=headers)
+            response.raise_for_status()
+            data = self._check_response(response)
+            session_log = [
+                    {
+                        "message": message.get("message"),
+                        "role": message.get("category"),
+                        "ts": message.get("create_time")
+                    }
+                    for message in data
+                ]
+
+            # 鎶妔ession_log 鎸塼s 鍗囧簭鎺掑簭
+            session_log.sort(key=lambda x: x['ts'])
+            return session_log
+
     async def variable_list(self, token: str, agent_id: str) -> list:
         url = f"{self.base_url}/api/v1/variable/list?flow_id={agent_id}"
         headers = {'cookie': f"access_token_cookie={token};"}

--
Gitblit v1.8.0