api 接口调用

当调用接口 http://xxx.xxx.cn/api/application/chat_message/{chat_id} 发送聊天消息之后
{
“message”: “写一首诗”,
“re_chat”: false,
“stream”: true
}

传递参数为 stream 为true的时候 返回的内容应该如何进行解析。
返回内容如下

{
“chat_id”: “4e971bb4-f80b-11ef-9e83-220cc222225b7bb”,
“chat_record_id”: “9d90dc8c-f80b-11ef-12388-220cc665b7bb”,
“operate”: true,
“content”: “”,
“node_id”: “ai-chat-node”,
“up_node_id_list”: [],
“is_end”: true,
“usage”: {
“completion_tokens”: 46,
“prompt_tokens”: 1069,
“total_tokens”: 1115
},
“node_is_end”: true,
“view_type”: “many_view”,
“node_type”: “ai-chat-node”
}

会话接口请求参数如果是stream:false,会返回中文内容,如果stream:true,会返回unicode编码,就需要解析。

这个我知道 我说的是 “stream”: true 为true的时候 怎么解析返回的内容。

具体的解析脚本可以让AI提供一些示例。

当参数 stream:true 的时候 返回的不是你说的这种格式 是如下这种

{
“chat_id”: “4e971bb4-f80b-11ef-9e83-220cc665b7bb”,
“chat_record_id”: “9b6e96ce-f96e-11ef-9334-463f80f58d66”,
“operate”: true,
“content”: “”,
“node_id”: “ai-chat-node”,
“up_node_id_list”: [],
“is_end”: true,
“usage”: {
“completion_tokens”: 8172,
“prompt_tokens”: 44,
“total_tokens”: 8216
},
“node_is_end”: true,
“view_type”: “many_view”,
“node_type”: “ai-chat-node”
}

怎么解析呢?

感觉你这调用得不对,content字段里都没有内容。
https://zhuanlan.zhihu.com/p/703991870

使用maxkb 官方生成的swagger api 当参数 stream:true 调用 的时候也是这样返回的。

页面抓包一下,用实际会话的参数去调用是最准的。