diff --git a/electron/handlers/native.ts b/electron/handlers/native.ts index fd882f6c1a..0740cdd176 100644 --- a/electron/handlers/native.ts +++ b/electron/handlers/native.ts @@ -235,18 +235,9 @@ export function handleAppIPCs() { for (const modelName of allModelFolders) { const modelFolderPath = join(janModelFolderPath, modelName) const filesInModelFolder = readdirSync(modelFolderPath) - if (filesInModelFolder.length <= 1) { - // if only have model.json file or empty folder, we skip it - continue - } const destinationPath = join(cortexModelFolderPath, modelName) - // create folder if not exist - if (!existsSync(destinationPath)) { - mkdirSync(destinationPath, { recursive: true }) - } - try { const modelJsonFullPath = join( janModelFolderPath, @@ -256,10 +247,23 @@ export function handleAppIPCs() { const model = JSON.parse(readFileSync(modelJsonFullPath, 'utf-8')) const fileNames: string[] = model.sources.map((x: any) => x.filename) - // prepend fileNames with cortexModelFolderPath - const files = fileNames.map((x: string) => - join(cortexModelFolderPath, model.id, x) - ) + let files: string[] = [] + + if(filesInModelFolder.length > 1) { + // prepend fileNames with cortexModelFolderPath + files = fileNames.map((x: string) => + join(cortexModelFolderPath, model.id, x) + ) + } else if(model.sources.length && !/^(http|https):\/\/[^/]+\/.*/.test(model.sources[0].url)) { + // Symlink case + files = [ model.sources[0].url ] + } else continue; + + // create folder if not exist + // only for local model files + if (!existsSync(destinationPath) && filesInModelFolder.length > 1) { + mkdirSync(destinationPath, { recursive: true }) + } const engine = 'cortex.llamacpp' @@ -288,24 +292,27 @@ export function handleAppIPCs() { max_tokens: model.parameters?.max_tokens ?? 2048, stream: model.parameters?.stream ?? true, } - - const { err } = await reflect({ - src: modelFolderPath, - dest: destinationPath, - recursive: true, - exclude: ['model.json'], - delete: false, - overwrite: true, - errorOnExist: false, - }) - if (err) console.error(err) - else { - // create the model.yml file - const modelYamlData = dump(updatedModelFormat) - const modelYamlPath = join(cortexModelFolderPath, `${modelName}.yaml`) - - writeFileSync(modelYamlPath, modelYamlData) + if(filesInModelFolder.length > 1 ) { + const { err } = await reflect({ + src: modelFolderPath, + dest: destinationPath, + recursive: true, + exclude: ['model.json'], + delete: false, + overwrite: true, + errorOnExist: false, + }) + + if (err) { + console.error(err); + continue; + } } + // create the model.yml file + const modelYamlData = dump(updatedModelFormat) + const modelYamlPath = join(cortexModelFolderPath, `${modelName}.yaml`) + + writeFileSync(modelYamlPath, modelYamlData) } catch (err) { console.error(err) } @@ -336,9 +343,9 @@ export function handleAppIPCs() { 'messages.jsonl' ) const lines = readFileSync(messageFullPath, 'utf-8') - .toString() - .split('\n') - .filter((line: any) => line !== '') + .toString() + .split('\n') + .filter((line: any) => line !== '') for (const line of lines) { messages.push(JSON.parse(line)) }