fix: improve make it real action (#6830)

This commit is contained in:
fundon
2024-05-09 08:15:34 +00:00
parent 917ad1965a
commit d8b3a0b6d5
5 changed files with 78 additions and 11 deletions

View File

@@ -79,16 +79,24 @@ export class OpenAIProvider
): OpenAI.Chat.Completions.ChatCompletionMessageParam[] {
// filter redundant fields
return messages.map(({ role, content, attachments }) => {
content = content.trim();
if (Array.isArray(attachments)) {
const contents = [
{ type: 'text', text: content },
...attachments
const contents: OpenAI.Chat.Completions.ChatCompletionContentPart[] =
[];
if (content.length) {
contents.push({
type: 'text',
text: content,
});
}
contents.push(
...(attachments
.filter(url => SIMPLE_IMAGE_URL_REGEX.test(url))
.map(url => ({
type: 'image_url',
image_url: { url, detail: 'high' },
})),
];
})) as OpenAI.Chat.Completions.ChatCompletionContentPartImage[])
);
return {
role,
content: contents,