| | |
| | |
| | |
| |
|
| |
|
| | import { getFileTypeCategory } from '$lib/utils';
|
| | import { FileTypeCategory } from '$lib/enums';
|
| | import type { ModalityCapabilities } from '$lib/types';
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | export function isFileTypeSupportedByModel(
|
| | filename: string,
|
| | mimeType: string | undefined,
|
| | capabilities: ModalityCapabilities
|
| | ): boolean {
|
| | const category = mimeType ? getFileTypeCategory(mimeType) : null;
|
| |
|
| |
|
| | if (!category) {
|
| |
|
| |
|
| | return true;
|
| | }
|
| |
|
| | switch (category) {
|
| | case FileTypeCategory.TEXT:
|
| |
|
| | return true;
|
| |
|
| | case FileTypeCategory.PDF:
|
| |
|
| | return true;
|
| |
|
| | case FileTypeCategory.IMAGE:
|
| |
|
| | return capabilities.hasVision;
|
| |
|
| | case FileTypeCategory.AUDIO:
|
| |
|
| | return capabilities.hasAudio;
|
| |
|
| | default:
|
| |
|
| | return true;
|
| | }
|
| | }
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | export function filterFilesByModalities(
|
| | files: File[],
|
| | capabilities: ModalityCapabilities
|
| | ): {
|
| | supportedFiles: File[];
|
| | unsupportedFiles: File[];
|
| | modalityReasons: Record<string, string>;
|
| | } {
|
| | const supportedFiles: File[] = [];
|
| | const unsupportedFiles: File[] = [];
|
| | const modalityReasons: Record<string, string> = {};
|
| |
|
| | const { hasVision, hasAudio } = capabilities;
|
| |
|
| | for (const file of files) {
|
| | const category = getFileTypeCategory(file.type);
|
| | let isSupported = true;
|
| | let reason = '';
|
| |
|
| | switch (category) {
|
| | case FileTypeCategory.IMAGE:
|
| | if (!hasVision) {
|
| | isSupported = false;
|
| | reason = 'Images require a vision-capable model';
|
| | }
|
| | break;
|
| |
|
| | case FileTypeCategory.AUDIO:
|
| | if (!hasAudio) {
|
| | isSupported = false;
|
| | reason = 'Audio files require an audio-capable model';
|
| | }
|
| | break;
|
| |
|
| | case FileTypeCategory.TEXT:
|
| | case FileTypeCategory.PDF:
|
| |
|
| | break;
|
| |
|
| | default:
|
| |
|
| |
|
| | break;
|
| | }
|
| |
|
| | if (isSupported) {
|
| | supportedFiles.push(file);
|
| | } else {
|
| | unsupportedFiles.push(file);
|
| | modalityReasons[file.name] = reason;
|
| | }
|
| | }
|
| |
|
| | return { supportedFiles, unsupportedFiles, modalityReasons };
|
| | }
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | export function generateModalityErrorMessage(
|
| | unsupportedFiles: File[],
|
| | modalityReasons: Record<string, string>,
|
| | capabilities: ModalityCapabilities
|
| | ): string {
|
| | if (unsupportedFiles.length === 0) return '';
|
| |
|
| | const { hasVision, hasAudio } = capabilities;
|
| |
|
| | let message = '';
|
| |
|
| | if (unsupportedFiles.length === 1) {
|
| | const file = unsupportedFiles[0];
|
| | const reason = modalityReasons[file.name];
|
| | message = `The file "${file.name}" cannot be uploaded: ${reason}.`;
|
| | } else {
|
| | const fileNames = unsupportedFiles.map((f) => f.name).join(', ');
|
| | message = `The following files cannot be uploaded: ${fileNames}.`;
|
| | }
|
| |
|
| |
|
| | const supportedTypes: string[] = ['text files', 'PDFs'];
|
| | if (hasVision) supportedTypes.push('images');
|
| | if (hasAudio) supportedTypes.push('audio files');
|
| |
|
| | message += ` This model supports: ${supportedTypes.join(', ')}.`;
|
| |
|
| | return message;
|
| | }
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| |
|