@@ -866,65 +866,69 @@ export default class llamacpp_extension extends AIEngine {
866866
867867 const files = await fs . readdirSync ( currentDir )
868868 for ( const child of files ) {
869- const childPath = await joinPath ( [ currentDir , child ] )
870- const stat = await fs . fileStat ( childPath )
871- if (
872- files . some ( ( e ) => e . endsWith ( 'model.yml' ) ) &&
873- ! child . endsWith ( 'model.yml' )
874- )
875- continue
876- if ( ! stat . isDirectory && child . endsWith ( '.yml' ) ) {
877- // check if model.yml exists
878- const modelConfigPath = child
879- if ( await fs . existsSync ( modelConfigPath ) ) {
880- const legacyModelConfig = await invoke < {
881- files : string [ ]
882- model : string
883- } > ( 'read_yaml' , {
884- path : modelConfigPath ,
885- } )
886- const legacyModelPath = legacyModelConfig . files ?. [ 0 ]
887- if ( ! legacyModelPath ) continue
888- // +1 to remove the leading slash
889- // NOTE: this does not handle Windows path \\
890- let modelId = currentDir . slice ( modelsDir . length + 1 )
891-
892- modelId =
893- modelId !== 'imported'
894- ? modelId . replace ( / ^ ( c o r t e x \. s o | h u g g i n g f a c e \. c o ) [ \/ \\ ] / , '' )
895- : ( await basename ( child ) ) . replace ( '.yml' , '' )
896-
897- const modelName = legacyModelConfig . model ?? modelId
898- const configPath = await joinPath ( [
899- await this . getProviderPath ( ) ,
900- 'models' ,
901- modelId ,
902- 'model.yml' ,
903- ] )
904- if ( await fs . existsSync ( configPath ) ) continue // Don't reimport
905-
906- // this is relative to Jan's data folder
907- const modelDir = `${ this . providerId } /models/${ modelId } `
908-
909- let size_bytes = (
910- await fs . fileStat (
911- await joinPath ( [ janDataFolderPath , legacyModelPath ] )
912- )
913- ) . size
914-
915- const modelConfig = {
916- model_path : legacyModelPath ,
917- mmproj_path : undefined , // legacy models do not have mmproj
918- name : modelName ,
919- size_bytes,
920- } as ModelConfig
921- await fs . mkdir ( await joinPath ( [ janDataFolderPath , modelDir ] ) )
922- await invoke < void > ( 'write_yaml' , {
923- data : modelConfig ,
924- savePath : configPath ,
925- } )
869+ try {
870+ const childPath = await joinPath ( [ currentDir , child ] )
871+ const stat = await fs . fileStat ( childPath )
872+ if (
873+ files . some ( ( e ) => e . endsWith ( 'model.yml' ) ) &&
874+ ! child . endsWith ( 'model.yml' )
875+ )
926876 continue
877+ if ( ! stat . isDirectory && child . endsWith ( '.yml' ) ) {
878+ // check if model.yml exists
879+ const modelConfigPath = child
880+ if ( await fs . existsSync ( modelConfigPath ) ) {
881+ const legacyModelConfig = await invoke < {
882+ files : string [ ]
883+ model : string
884+ } > ( 'read_yaml' , {
885+ path : modelConfigPath ,
886+ } )
887+ const legacyModelPath = legacyModelConfig . files ?. [ 0 ]
888+ if ( ! legacyModelPath ) continue
889+ // +1 to remove the leading slash
890+ // NOTE: this does not handle Windows path \\
891+ let modelId = currentDir . slice ( modelsDir . length + 1 )
892+
893+ modelId =
894+ modelId !== 'imported'
895+ ? modelId . replace ( / ^ ( c o r t e x \. s o | h u g g i n g f a c e \. c o ) [ \/ \\ ] / , '' )
896+ : ( await basename ( child ) ) . replace ( '.yml' , '' )
897+
898+ const modelName = legacyModelConfig . model ?? modelId
899+ const configPath = await joinPath ( [
900+ await this . getProviderPath ( ) ,
901+ 'models' ,
902+ modelId ,
903+ 'model.yml' ,
904+ ] )
905+ if ( await fs . existsSync ( configPath ) ) continue // Don't reimport
906+
907+ // this is relative to Jan's data folder
908+ const modelDir = `${ this . providerId } /models/${ modelId } `
909+
910+ let size_bytes = (
911+ await fs . fileStat (
912+ await joinPath ( [ janDataFolderPath , legacyModelPath ] )
913+ )
914+ ) . size
915+
916+ const modelConfig = {
917+ model_path : legacyModelPath ,
918+ mmproj_path : undefined , // legacy models do not have mmproj
919+ name : modelName ,
920+ size_bytes,
921+ } as ModelConfig
922+ await fs . mkdir ( await joinPath ( [ janDataFolderPath , modelDir ] ) )
923+ await invoke < void > ( 'write_yaml' , {
924+ data : modelConfig ,
925+ savePath : configPath ,
926+ } )
927+ continue
928+ }
927929 }
930+ } catch ( error ) {
931+ console . error ( `Error migrating model ${ child } :` , error )
928932 }
929933 }
930934
@@ -1093,9 +1097,7 @@ export default class llamacpp_extension extends AIEngine {
10931097 attempts ++
10941098 }
10951099
1096- throw new Error (
1097- 'Failed to find an available port for the model to load'
1098- )
1100+ throw new Error ( 'Failed to find an available port for the model to load' )
10991101 }
11001102
11011103 private async sleep ( ms : number ) : Promise < void > {
0 commit comments