refactor: embedding messages format

This commit is contained in:
jialin
2026-03-26 17:59:33 +08:00
committed by jialin
parent bb3cef89c1
commit c74118e913
7 changed files with 186 additions and 112 deletions
+24 -2
View File
@@ -49,9 +49,13 @@ export const formatMessageParams = (messageList: any[]) => {
return result;
};
export const generateMessagesByListContent = (messageList: any[]) => {
export const generateMessagesByListContent = (
messageList: any[],
multimodal?: boolean
) => {
if (!messageList.length) return [];
return messageList.map((item: MessageItem) => {
// image
if (item.imgs?.length || item.audio?.length) {
const content: any[] = [];
// image
@@ -90,7 +94,25 @@ export const generateMessagesByListContent = (messageList: any[]) => {
};
}
return _.omit(item, ['uid', 'imgs', 'audio']);
// for multimodal model, if there is text content but no image or audio, also send as multimodal format
if (
multimodal &&
item.content &&
!item.imgs?.length &&
!item.audio?.length
) {
return {
role: item.role,
content: [
{
type: 'text',
text: item.content
}
]
};
}
return _.omit(item, ['uid', 'imgs', 'audio', 'name']);
});
};