mirror of
https://github.com/LLM-Red-Team/glm-free-api.git
synced 2024-11-01 16:09:24 +08:00
处理首轮传送文件时导致对话合并问题
This commit is contained in:
parent
a2770fea93
commit
756c89aaef
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "glm-free-api",
|
"name": "glm-free-api",
|
||||||
"version": "0.0.26",
|
"version": "0.0.27",
|
||||||
"description": "GLM Free API Server",
|
"description": "GLM Free API Server",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -496,6 +496,22 @@ function extractRefFileUrls(messages: any[]) {
|
|||||||
* @param isRefConv 是否为引用会话
|
* @param isRefConv 是否为引用会话
|
||||||
*/
|
*/
|
||||||
function messagesPrepare(messages: any[], refs: any[], isRefConv = false) {
|
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",如果有则注入消息
|
// 检查最新消息是否含有"type": "image_url"或"type": "file",如果有则注入消息
|
||||||
let latestMessage = messages[messages.length - 1];
|
let latestMessage = messages[messages.length - 1];
|
||||||
let hasFileOrImage =
|
let hasFileOrImage =
|
||||||
@ -519,23 +535,6 @@ function messagesPrepare(messages: any[], refs: any[], isRefConv = false) {
|
|||||||
// messages.splice(messages.length - 1, 0, newTextMessage);
|
// messages.splice(messages.length - 1, 0, newTextMessage);
|
||||||
// logger.info("注入提升尾部消息注意力system prompt");
|
// 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 = (
|
content = (
|
||||||
messages.reduce((content, message) => {
|
messages.reduce((content, message) => {
|
||||||
const role = message.role
|
const role = message.role
|
||||||
|
Loading…
Reference in New Issue
Block a user