support different image filetypes

This commit is contained in:
starmorph
2025-05-19 12:48:30 -07:00
parent 5e7a8ee03e
commit 217fd43eac

View File

@@ -5,11 +5,22 @@ import { convertToOpenAIImageBlock } from "@langchain/core/messages";
export async function fileToImageBlock(
file: File,
): Promise<Base64ContentBlock> {
const supportedTypes = [
"image/jpeg",
"image/png",
"image/gif",
"image/webp",
];
if (!supportedTypes.includes(file.type)) {
throw new Error(
`Unsupported image type: ${file.type}. Supported types are: ${supportedTypes.join(", ")}`,
);
}
const data = await fileToBase64(file);
return {
type: "image",
source_type: "base64",
mime_type: "image/jpeg",
mime_type: file.type,
data,
metadata: { name: file.name },
};