修复消息中出现插件调用失败内容的问题

This commit is contained in:
Vinlic 2024-03-28 18:43:44 +08:00
parent 6abc2d760f
commit 3bb2a93211

View File

@ -323,8 +323,7 @@ function messagesPrepare(messages: any[]) {
return _content + (v["text"] || ""); return _content + (v["text"] || "");
}, content); }, content);
} }
return (content += `<|im_start|>${message.role || "user"}\n${ return (content += `<|im_start|>${message.role || "user"}\n${message.content
message.content
}<|im_end|>\n`); }<|im_end|>\n`);
}, ""); }, "");
return [ return [
@ -383,7 +382,9 @@ async function receiveStream(stream: any): Promise<any> {
throw new Error(`Stream response invalid: ${event.data}`); throw new Error(`Stream response invalid: ${event.data}`);
if (!data.id && result.sessionId) data.id = result.sessionId; if (!data.id && result.sessionId) data.id = result.sessionId;
const text = (result.contents || []).reduce((str, part) => { const text = (result.contents || []).reduce((str, part) => {
const { role, content } = part; const { contentType, role, content } = part;
console.log(part);
if (contentType != 'text' && contentType != 'text2image') return str;
if (role != "assistant" && !_.isString(content)) return str; if (role != "assistant" && !_.isString(content)) return str;
return str + content; return str + content;
}, ""); }, "");
@ -467,7 +468,8 @@ function createTransStream(stream: any, endCallback?: Function) {
if (_.isError(result)) if (_.isError(result))
throw new Error(`Stream response invalid: ${event.data}`); throw new Error(`Stream response invalid: ${event.data}`);
const text = (result.contents || []).reduce((str, part) => { const text = (result.contents || []).reduce((str, part) => {
const { role, content } = part; const { contentType, role, content } = part;
if (contentType != 'text' && contentType != 'text2image') return str;
if (role != "assistant" && !_.isString(content)) return str; if (role != "assistant" && !_.isString(content)) return str;
return str + content; return str + content;
}, ""); }, "");