图像解析支持

This commit is contained in:
Vinlic 2024-03-17 18:18:11 +08:00
parent 9868897d07
commit cbb14b0198

View File

@ -316,14 +316,23 @@ function messagesPrepare(messages: any[], refs: any[]) {
const role = message.role.replace('user', '我').replace('assistant', '你') || '我'; const role = message.role.replace('user', '我').replace('assistant', '你') || '我';
return content += `${role}:${message.content}\n你:`; return content += `${role}:${message.content}\n你:`;
}, ''); }, '');
const fileRefs = refs.filter(ref => !ref.width && !ref.height);
const imageRefs = refs.filter(ref => ref.width || ref.height).map(ref => {
ref.image_url = ref.file_url;
return ref;
});
return [ return [
{ {
role: 'user', role: 'user',
content: [ content: [
{ type: 'text', text: headPrompt + content }, { type: 'text', text: headPrompt + content },
...(refs.length == 0 ? [] : [{ ...(fileRefs.length == 0 ? [] : [{
type: 'file', type: 'file',
file: refs file: fileRefs
}]),
...(imageRefs.length == 0 ? [] : [{
type: 'image',
image: imageRefs
}]) }])
] ]
} }