fix: broken manual import model with NA fields (#1912)

This commit is contained in:
Louis 2024-02-03 15:20:42 +07:00 committed by GitHub
parent eaa3053d40
commit afa80b92a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -286,6 +286,7 @@ export default class JanModelExtension extends ModelExtension {
* model.json file associated with it. * model.json file associated with it.
* *
* This function will create a model.json file for the model. * 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. * @param dirName the director which reside in ~/jan/models but does not have model.json file.
*/ */
@ -302,15 +303,14 @@ export default class JanModelExtension extends ModelExtension {
let binaryFileSize: number | undefined = undefined let binaryFileSize: number | undefined = undefined
for (const file of files) { for (const file of files) {
if (file.endsWith(JanModelExtension._incompletedModelFileName)) continue if (file.endsWith(JanModelExtension._supportedModelFormat)) {
if (file.endsWith('.json')) continue const path = await joinPath([JanModelExtension._homeDir, dirName, file])
const fileStats = await fs.fileStat(path)
const path = await joinPath([JanModelExtension._homeDir, dirName, file]) if (fileStats.isDirectory) continue
const fileStats = await fs.fileStat(path) binaryFileSize = fileStats.size
if (fileStats.isDirectory) continue binaryFileName = file
binaryFileSize = fileStats.size break
binaryFileName = file }
break
} }
if (!binaryFileName) { if (!binaryFileName) {
@ -318,7 +318,7 @@ export default class JanModelExtension extends ModelExtension {
return return
} }
const defaultModel = await this.getDefaultModel() const defaultModel = await this.getDefaultModel() as Model
if (!defaultModel) { if (!defaultModel) {
console.error('Unable to find default model') console.error('Unable to find default model')
return return
@ -326,8 +326,19 @@ export default class JanModelExtension extends ModelExtension {
const model: Model = { const model: Model = {
...defaultModel, ...defaultModel,
// Overwrite default N/A fields
id: dirName, id: dirName,
name: dirName, name: dirName,
sources: [
{
url: binaryFileName,
filename: binaryFileName,
},
],
settings: {
...defaultModel.settings,
llama_model_path: binaryFileName,
},
created: Date.now(), created: Date.now(),
description: `${dirName} - user self import model`, description: `${dirName} - user self import model`,
metadata: { metadata: {