| | |
| | | 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()) |