Merge pull request #4122 from continuedev/dallin/openai-images

Fix OpenAI adapter image messages
This commit is contained in:
Nate Sesti 2025-02-13 07:48:30 -08:00 • committed by GitHub
commit cceca5e931
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -57,30 +57,34 @@ export function toChatMessage(
}
return msg;
} else {
if (typeof message.content === "string") {
return {
role: "user",
content: message.content ?? " ", // LM Studio (and other providers) don't accept empty content
};
}
// If no multi-media is in the message, just send as text
// for compatibility with OpenAI-"compatible" servers
// that don't support multi-media format
return {
role: "user",
content:
typeof message.content === "string"
? message.content || " " // LM Studio (and other providers) don't accept empty content
: // If no multi-media is in the message, just send as text
// for compatibility with OpenAI-"compatible" servers
// that don't support multi-media format
message.content.some((item) => item.type !== "text")
? message.content
.map((item) => (item as TextMessagePart).text)
.join("") || " "
: message.content.map((part) => {
if (part.type === "imageUrl") {
return {
type: "image_url" as const,
image_url: {
url: part.imageUrl.url,
detail: "auto" as const,
},
};
}
return part;
}),
content: !message.content.some((item) => item.type !== "text")
? message.content
.map((item) => (item as TextMessagePart).text)
.join("") || " "
: message.content.map((part) => {
if (part.type === "imageUrl") {
return {
type: "image_url" as const,
image_url: {
url: part.imageUrl.url,
detail: "auto" as const,
},
};
}
return part;
}),
};
}
}