Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用WS接口调用技能API,返回仍然非流式。 #1010

Open
WJMismybestfriend opened this issue Dec 13, 2024 · 0 comments
Open

使用WS接口调用技能API,返回仍然非流式。 #1010

WJMismybestfriend opened this issue Dec 13, 2024 · 0 comments

Comments

@WJMismybestfriend
Copy link

WJMismybestfriend commented Dec 13, 2024

结合api文档和前端真实请求,调用/api/v2/chat/ws/{} 接口,技能返回仍然非流式。我的请求方式如下,官方能否给个标准的针对/api/v2/chat/ws/{} 接口的流式请求脚本。
url = f"ws://10.5.5.107:3001/api/v2/chat/ws/e7abbbd1-d87e-4d1a-86b0-6ab92cd51f0f"
messages = [
{
"chatHistory": [],
"flow_id": "ad73174e-351a-424c-8691-23361ad8ee67",
"chat_id": "",
"name": "合规知识库",
"description": "安全合规pdf",
"inputs": {
"question": "HI请问我想问怎么理解安全合规的安全漏洞管理?",
"id": "ConversationalRetrievalChain-0db28"
}
},
{
"source_documents": [],
"is_bot": True,
"message": "",
"type": "begin",
"category": "system",
"intermediate_steps": "",
"files": [],
"user_id": 1,
"message_id": None,
"source": 0,
"sender": None,
"receiver": None,
"liked": 0,
"extra": "{}",
"flow_id": "ad73174e-351a-424c-8691-23361ad8ee67",
"chat_id": ""
},
{"source_documents": [], "is_bot": True, "message": "", "type": "start", "category": "system",
"intermediate_steps": "", "files": [], "user_id": 1, "message_id": None, "source": 0, "sender": None,
"receiver": None, "liked": 0, "extra": "{}", "flow_id": "ad73174e-351a-424c-8691-23361ad8ee67",
"chat_id": ""},
{"source_documents": [], "is_bot": True, "message": "", "type": "end", "category": "",
"intermediate_steps": "", "files": [], "user_id": 1, "message_id": None, "source": 0, "sender": None,
"receiver": None, "liked": 0, "extra": "{}", "flow_id": "ad73174e-351a-424c-8691-23361ad8ee67",
"chat_id": ""},
{"source_documents": [], "is_bot": True, "message": "", "type": "close", "category": "system",
"intermediate_steps": "", "files": [], "user_id": 1, "message_id": None, "source": 0, "sender": None,
"receiver": None, "liked": 0, "extra": "{}", "flow_id": "ad73174e-351a-424c-8691-23361ad8ee67",
"chat_id": ""},
]
# 发送WebSocket请求
async with websockets.connect(uri) as websocket:
# 发送握手请求,包括可选的查询参数
handshake_payload = {
"chat_id": chat_id,
"tweak": tweak,
"knowledge_id": ""
}
await websocket.send(json.dumps(handshake_payload))

        # 按顺序发送消息
        for message in messages:
            await websocket.send(json.dumps(message))
            print(f"Sent: {message}")

            # 接收服务器的响应
            response = await websocket.recv()
            response = json.loads(response)
            print(f"Received: {response}")
            try:
                print(f"message: {response['message']}")
            except:
                print("None")
        # 关闭连接
        await websocket.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant