调用报错id变量未定义
当我在vue中使用如下的代码进行智能体的调用时候,出现报错。具体情况如下:
-
代码: CozeTest.txt
-
错误的现象: 2.1 从浏览器的调试上看,网络请求的响应都是正常的,响应如下: Untitled-1.json
对应的代码是:
*/ async createAndPoll(params, options) {
if (!params.user_id) params.user_id = uuid();
const { conversation_id, ...rest } = params;
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
const payload = {
...rest,
additional_messages: handleAdditionalMessages(params.additional_messages),
shortcut_command: params.shortcut_command ? {
...params.shortcut_command,
parameters: handleParameters(params.shortcut_command.parameters)
} : void 0,
stream: false
};
const result = await this._client.post(apiUrl, payload, false, options);
const chatId = result.data.id;
const conversationId = result.data.conversation_id;
let chat;
while(true){
await sleep(100);
chat = await this.retrieve(conversationId, chatId);
if ('completed' === chat.status || 'failed' === chat.status || 'requires_action' === chat.status) break;
}
const messageList = await this.messages.list(conversationId, chatId);
return {
chat,
messages: messageList
};
}
也就是 const chatId = result.data.id; 出现错误
coze是我在本地使用docker部署的coze-studio,然后在coze-studio上搭建了一个智能体
同样的如果参考chat.ts进行实现,使用streamingChat方法,依然报错,但实际是如下的报错:
[START]
245CozeTest.vue:162
CozeTest.vue:168 [assistant]:[function_call]:{"index":0,"id":"call_uvpsw17i6dkzk2byj7nsf2mh","type":"function","function":{"name":"ts_audio_recognize_audio_recognize","arguments":"{\"url\":\"http://10.1.41.142:8000/download/audio1.mp3\"}"}}
CozeTest.vue:162 **命令类型:** play_music
**命令格式:** song
**命令内容:** 香水有毒
CozeTest.vue:166
CozeTest.vue:168 [assistant]:[tool_response]:**命令类型:** play_music
**命令格式:** song
**命令内容:** 香水有毒
CozeTest.vue:168 [assistant]:[follow_up]:Is this audio file link safe to download?
CozeTest.vue:168 [assistant]:[follow_up]:What is the content of the audio file at this link?
CozeTest.vue:168 [assistant]:[follow_up]:What is the audio quality (such as bitrate or duration) of audio1.mp3?
CozeTest.vue:168 [assistant]:[verbose]:{"msg_type":"generate_answer_finish","data":"{\"finish_reason\":0,\"fin_data\":\"\"}","from_unit":""}
CozeTest.vue:171 undefined
runtime-core.esm-bundler.js:51 [Vue warn]: Unhandled error during execution of native event handler
at <CozeTest onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< Proxy(Object) {__v_skip: true} > >
at <RouterView>
at <App>
warn$1 @ runtime-core.esm-bundler.js:51
logError @ runtime-core.esm-bundler.js:263
handleError @ runtime-core.esm-bundler.js:255
eval @ runtime-core.esm-bundler.js:209
index.mjs:455 Uncaught (in promise) CozeError: Could not parse message into JSON:
at Chat.stream (index.mjs:455:1)
at async streamingChat (CozeTest.vue:157:1)
at async test (CozeTest.vue:218:1)
可以看到前面已经将我想要的结果打印出来了,但是在解析 done 数据的时候直接报错了,应该是done的 data是空,然后无法解析成json导致的报错吧?
这个问题能不能解决?
好的问题收到了,我们排查一下
http://10.1.41.71:8888 这个服务你有测试吗?我把 baseURL: COZE_CN_BASE_URL, 测试代码是可以跑的
这个http://10.1.41.71:8888的服务就是我在本地部署的coze-studio,我没有使用baseURL: COZE_CN_BASE_URL进行测试。