Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,24 @@ export async function convertToOpenAIResponsesInput({
}

case "user": {
const supportedImageTypes = ["image/jpeg", "image/png", "image/gif", "image/webp"]
const filteredContent = content.filter((part) => {
if (part.type === "text") return true
if (part.type === "file") {
return supportedImageTypes.includes(part.mediaType) || part.mediaType === "application/pdf"
}
return false
})

input.push({
role: "user",
content: content.map((part, index) => {
content: filteredContent.map((part, index) => {
switch (part.type) {
case "text": {
return { type: "input_text", text: part.text }
}
case "file": {
if (part.mediaType.startsWith("image/")) {
if (supportedImageTypes.includes(part.mediaType)) {
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType

return {
Expand Down Expand Up @@ -103,10 +112,6 @@ export async function convertToOpenAIResponsesInput({
file_data: `data:application/pdf;base64,${convertToBase64(part.data)}`,
}),
}
} else {
throw new UnsupportedFunctionalityError({
functionality: `file part media type ${part.mediaType}`,
})
}
}
}
Expand Down