fix: claude3 image type verification failed (#1038) (#1040)

This commit is contained in:
xiaotian
2024-03-22 13:19:42 +08:00
committed by GitHub
parent a63467d751
commit ef15ca894e
2 changed files with 23 additions and 3 deletions

View File

@@ -9,3 +9,21 @@ export const removeFilesByPaths = (paths: string[]) => {
});
});
};
const imageTypeMap: Record<string, string> = {
'/': 'image/jpeg',
i: 'image/png',
R: 'image/gif',
U: 'image/webp',
Q: 'image/bmp'
};
export const guessImageTypeFromBase64 = (str: string) => {
const defaultType = 'image/jpeg';
if (typeof str !== 'string' || str.length === 0) {
return defaultType;
}
const firstChar = str.charAt(0);
return imageTypeMap[firstChar] || defaultType;
};