From 7666bdbabfb929f98e94310dbe99eabb435898a2 Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期二, 07 一月 2025 15:03:07 +0800
Subject: [PATCH] tmp
---
app/service/v2/chat.py | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/app/service/v2/chat.py b/app/service/v2/chat.py
index e69de29..f35604a 100644
--- a/app/service/v2/chat.py
+++ b/app/service/v2/chat.py
@@ -0,0 +1,28 @@
+import json
+
+from app.service.v2.app_driver.chat_dialog import ChatDialog
+
+
+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.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())
+ except Exception as e:
+ yield "data:" + json.dumps({"code": 500, "message": str(e),
+ "data": {"answer": "**ERROR**: " + str(e), "reference": []}},
+ ensure_ascii=False) + "\n\n"
+ yield "data:" + json.dumps({"code": 0, "message": "", "data": True}, ensure_ascii=False) + "\n\n"
\ No newline at end of file
--
Gitblit v1.8.0