for await (const part of v) { console.log(part); if (part.event === ChatEventType.CONVERSATION_CHAT_CREATED) { // opt.chatCreated && opt.chatCreated(part.data); const res = await (part.data.conversation_id, part.data.id) console.log('client.chat.cancel', res);
} else if (part.event === ChatEventType.CONVERSATION_MESSAGE_DELTA) {
opt.callback && opt.callback(part.data.content);
} else if (part.event === ChatEventType.CONVERSATION_MESSAGE_COMPLETED) {
const {
role,
type,
content
} = part.data;
if (role === 'assistant' && type === 'answer') {
opt.callback && opt.callback('\n');
} else if (role === 'assistant' && type === 'follow_up') {
opt.followUpCallback && opt.followUpCallback(content)
}
} else if (part.event === ChatEventType.CONVERSATION_CHAT_COMPLETED) {
console.log(part.data.usage);
} else if (part.event === ChatEventType.DONE) {
console.log(part.data);
opt.done && opt.done();
} else if (part.event === ChatEventType.ERROR) {
opt.error && opt.error();
}
}