Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix: MLX import dialog uses folder picker instead of safetensor file picker (#7554)
Louis2e3855abaff6
diff --git a/extensions/mlx-extension/src/index.ts b/extensions/mlx-extension/src/index.tsindex 13541e011..86ed23e8f 100644--- a/extensions/mlx-extension/src/index.ts+++ b/extensions/mlx-extension/src/index.ts@@ -682,32 +682,31 @@ export default class mlx_extension extends AIEngine {capabilities: capabilities,})} else {- // Local file - use absolute path directly+ // Local folder - use absolute folder path directlyif (!(await fs.existsSync(sourcePath))) {- throw new Error(`File not found: ${sourcePath}`)+ throw new Error(`Folder not found: ${sourcePath}`)}- // Get file size+ // Get folder sizeconst stat = await fs.fileStat(sourcePath)const size_bytes = stat.size- // Detect capabilities by checking model directory+ // Detect capabilities by checking model folderconst isVision = await this.isVisionSupported(sourcePath)// Build capabilities arrayconst capabilities: string[] = []if (isVision) capabilities.push('vision')- // Create model.yml with absolute path+ // Create model.yml with absolute folder pathconst modelConfig: any = {model_path: sourcePath,name: modelId,size_bytes,}- // For vision models, add mmproj_path pointing to model.safetensors+ // For vision models, add mmproj_pathif (isVision) {- const modelDir = sourcePath.substring(0, sourcePath.lastIndexOf('/'))modelConfig.mmproj_path = sourcePathlogger.info(`Vision model detected: ${modelId}`)}@@ -797,7 +796,12 @@ export default class mlx_extension extends AIEngine {async isVisionSupported(modelPath: string): Promise<boolean> {// Check if model is a Vision Language Model by examining config.json- const modelDir = modelPath.substring(0, modelPath.lastIndexOf('/'))+ // modelPath can be a folder path or a file path; resolve to directory+ const stat = await fs.fileStat(modelPath).catch(() => null)+ const modelDir =+ stat && stat.isDirectory+ ? modelPath+ : modelPath.substring(0, modelPath.lastIndexOf('/'))const configPath = await joinPath([modelDir, 'config.json'])if (!(await fs.existsSync(configPath))) {diff --git a/web-app/src/containers/dialogs/ImportMlxModelDialog.tsx b/web-app/src/containers/dialogs/ImportMlxModelDialog.tsxindex 49f44a486..3520655f6 100644--- a/web-app/src/containers/dialogs/ImportMlxModelDialog.tsx+++ b/web-app/src/containers/dialogs/ImportMlxModelDialog.tsx@@ -36,17 +36,7 @@ export const ImportMlxModelDialog = ({const handleFileSelect = async () => {const result = await serviceHub.dialog().open({multiple: false,- directory: false,- filters: [- {- name: 'Safetensor Files',- extensions: ['safetensors'],- },- {- name: 'All Files',- extensions: ['*'],- },- ],+ directory: true,})if (result && typeof result === 'string') {@@ -65,7 +55,7 @@ export const ImportMlxModelDialog = ({const handleImport = async () => {if (!selectedPath) {- toast.error('Please select a safetensor file or folder')+ toast.error('Please select a model folder')return}@@ -161,8 +151,9 @@ export const ImportMlxModelDialog = ({Import MLX Model</DialogTitle><DialogDescription>- Import a safetensor model file or folder for use with MLX. MLX models- are typically downloaded from HuggingFace and use the safetensors format.+ Import a local MLX model folder for use with MLX. MLX models are+ typically downloaded from HuggingFace and contain safetensors files+ along with config and tokenizer files.</DialogDescription></DialogHeader>@@ -188,7 +179,7 @@ export const ImportMlxModelDialog = ({<div className="border rounded-lg p-4 space-y-3"><div className="flex items-center gap-2"><h3 className="font-medium">- Safetensor File or Folder+ Model Folder</h3><span className="text-xs bg-secondary px-2 py-1 rounded-sm">Required@@ -222,7 +213,7 @@ export const ImportMlxModelDialog = ({disabled={importing}className="w-full h-12 border border-dashed text-muted-foreground">- Select Safetensor File or Folder+ Select Model Folder</Button>)}</div>