zhangqian
2024-10-16 3fc9f4f33cf90610c71a1de7b00db0f82b988e98
app/api/chat.py
@@ -29,11 +29,13 @@
    agent = db.query(AgentModel).filter(AgentModel.id == agent_id).first()
    if not agent:
        ret = {"message": "Agent not found", "type": "close"}
        return websocket.send_json(ret)
        await websocket.send_json(ret)
        return
    agent_type = agent.agent_type
    if chat_id == "" or chat_id == "0":
        ret = {"message": "Chat ID not found", "type": "close"}
        return websocket.send_json(ret)
        await websocket.send_json(ret)
        return
    if agent_type == AgentType.RAGFLOW:
        ragflow_service = RagflowService(settings.ragflow_base_url)
@@ -50,7 +52,6 @@
                        if len(chat_history) == 0:
                            result = {"message": "内部错误:创建会话失败", "type": "close"}
                            await websocket.send_json(result)
                            continue
                    async for rag_response in ragflow_service.chat(token, chat_id, chat_history):
                        try:
                            print(f"Received from ragflow: {rag_response}")
@@ -143,5 +144,5 @@
                print(f"Client {chat_id} disconnected")
    else:
        ret = {"message": "Agent not found", "type": "close"}
        return websocket.send_json(ret)
        await websocket.send_json(ret)