处理首轮传送文件时导致对话合并问题

This commit is contained in:
Vinlic 2024-04-28 17:37:16 +08:00
parent a2770fea93
commit 756c89aaef
2 changed files with 25 additions and 26 deletions

View File

@ -1,6 +1,6 @@
{
"name": "glm-free-api",
"version": "0.0.26",
"version": "0.0.27",
"description": "GLM Free API Server",
"type": "module",
"main": "dist/index.js",

View File

@ -496,6 +496,22 @@ function extractRefFileUrls(messages: any[]) {
* @param isRefConv
*/
function messagesPrepare(messages: any[], refs: any[], isRefConv = false) {
let content;
if (isRefConv || messages.length < 2) {
content = messages.reduce((content, message) => {
if (_.isArray(message.content)) {
return (
message.content.reduce((_content, v) => {
if (!_.isObject(v) || v["type"] != "text") return _content;
return _content + (v["text"] || "") + "\n";
}, content)
);
}
return content + `${message.content}\n`;
}, "");
logger.info("\n透传内容\n" + content);
}
else {
// 检查最新消息是否含有"type": "image_url"或"type": "file",如果有则注入消息
let latestMessage = messages[messages.length - 1];
let hasFileOrImage =
@ -519,23 +535,6 @@ function messagesPrepare(messages: any[], refs: any[], isRefConv = false) {
// messages.splice(messages.length - 1, 0, newTextMessage);
// logger.info("注入提升尾部消息注意力system prompt");
}
let content;
if(isRefConv || messages.length < 2) {
content = messages.reduce((content, message) => {
if (_.isArray(message.content)) {
return (
message.content.reduce((_content, v) => {
if (!_.isObject(v) || v["type"] != "text") return _content;
return _content + (v["text"] || "") + "\n";
}, content)
);
}
return content + `${message.content}\n`;
}, "");
logger.info("\n透传内容\n" + content);
}
else {
content = (
messages.reduce((content, message) => {
const role = message.role