From 51433cba2f35b9a2571023236006ebc69d1d4d2d Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期二, 07 一月 2025 16:04:31 +0800
Subject: [PATCH] tnp

---
 app/service/v2/chat.py |   27 ++++++++++++++++++---------
 1 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/app/service/v2/chat.py b/app/service/v2/chat.py
index df8cb0f..136a113 100644
--- a/app/service/v2/chat.py
+++ b/app/service/v2/chat.py
@@ -1,17 +1,26 @@
+import json
+
+from app.service.v2.app_driver.chat_dialog import ChatDialog
 
 
-async def service_chat_dialog(question: str, session_id: str):
-
-    if session_id:
-        ...
-
-
-
+async def service_chat_dialog(chat_id:str, question: str, session_id: str):
+    token = "ragflow-YzMzE1NDRjYzMyZjExZWY5ZjkxMDI0Mm"
+    url = f"/api/v1/chats/{chat_id}/completions"
+    chat = ChatDialog(token)
+    data = {
+        "question": question,
+        "stream": True,
+        "session_id": session_id
+    }
+    headers = {
+        'Content-Type': 'application/json',
+        'Authorization': f"Bearer {token}"
+    }
     try:
-        for ans in chat(dia, msg, True, **req):
+        for ans in chat.chat_completions(url, data, headers):
 
             yield "data:" + json.dumps({"code": 0, "message": "", "data": ans}, ensure_ascii=False) + "\n\n"
-        ConversationService.update_by_id(conv.id, conv.to_dict())
+        ChatSessionModel.update_by_id(conv.id, conv.to_dict())
     except Exception as e:
         yield "data:" + json.dumps({"code": 500, "message": str(e),
                                     "data": {"answer": "**ERROR**: " + str(e), "reference": []}},

--
Gitblit v1.8.0