Skip to content

Commit

Permalink
fix: broken manual import model with NA fields (janhq#1912)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-menlo authored Feb 3, 2024
1 parent eaa3053 commit afa80b9
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions extensions/model-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export default class JanModelExtension extends ModelExtension {
* model.json file associated with it.
*
* This function will create a model.json file for the model.
* It works only with single binary file model.
*
* @param dirName the director which reside in ~/jan/models but does not have model.json file.
*/
Expand All @@ -302,32 +303,42 @@ export default class JanModelExtension extends ModelExtension {
let binaryFileSize: number | undefined = undefined

for (const file of files) {
if (file.endsWith(JanModelExtension._incompletedModelFileName)) continue
if (file.endsWith('.json')) continue

const path = await joinPath([JanModelExtension._homeDir, dirName, file])
const fileStats = await fs.fileStat(path)
if (fileStats.isDirectory) continue
binaryFileSize = fileStats.size
binaryFileName = file
break
if (file.endsWith(JanModelExtension._supportedModelFormat)) {
const path = await joinPath([JanModelExtension._homeDir, dirName, file])
const fileStats = await fs.fileStat(path)
if (fileStats.isDirectory) continue
binaryFileSize = fileStats.size
binaryFileName = file
break
}
}

if (!binaryFileName) {
console.warn(`Unable to find binary file for model ${dirName}`)
return
}

const defaultModel = await this.getDefaultModel()
const defaultModel = await this.getDefaultModel() as Model
if (!defaultModel) {
console.error('Unable to find default model')
return
}

const model: Model = {
...defaultModel,
// Overwrite default N/A fields
id: dirName,
name: dirName,
sources: [
{
url: binaryFileName,
filename: binaryFileName,
},
],
settings: {
...defaultModel.settings,
llama_model_path: binaryFileName,
},
created: Date.now(),
description: `${dirName} - user self import model`,
metadata: {
Expand Down

0 comments on commit afa80b9

Please sign in to comment.