support different image filetypes
This commit is contained in:
@@ -5,11 +5,22 @@ import { convertToOpenAIImageBlock } from "@langchain/core/messages";
|
|||||||
export async function fileToImageBlock(
|
export async function fileToImageBlock(
|
||||||
file: File,
|
file: File,
|
||||||
): Promise<Base64ContentBlock> {
|
): 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);
|
const data = await fileToBase64(file);
|
||||||
return {
|
return {
|
||||||
type: "image",
|
type: "image",
|
||||||
source_type: "base64",
|
source_type: "base64",
|
||||||
mime_type: "image/jpeg",
|
mime_type: file.type,
|
||||||
data,
|
data,
|
||||||
metadata: { name: file.name },
|
metadata: { name: file.name },
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user