fix: scan the models folder recursive to find model metadata file (#2982)
Co-authored-by: James <james@jan.ai>
This commit is contained in:
parent
f6581059ab
commit
d7f161f668
@ -417,6 +417,30 @@ export default class JanModelExtension extends ModelExtension {
|
||||
)
|
||||
}
|
||||
|
||||
private async getModelJsonPath(
|
||||
folderFullPath: string
|
||||
): Promise<string | undefined> {
|
||||
// try to find model.json recursively inside each folder
|
||||
if (!(await fs.existsSync(folderFullPath))) return undefined
|
||||
const files: string[] = await fs.readdirSync(folderFullPath)
|
||||
if (files.length === 0) return undefined
|
||||
if (files.includes(JanModelExtension._modelMetadataFileName)) {
|
||||
return joinPath([
|
||||
folderFullPath,
|
||||
JanModelExtension._modelMetadataFileName,
|
||||
])
|
||||
}
|
||||
// continue recursive
|
||||
for (const file of files) {
|
||||
const path = await joinPath([folderFullPath, file])
|
||||
const fileStats = await fs.fileStat(path)
|
||||
if (fileStats.isDirectory) {
|
||||
const result = await this.getModelJsonPath(path)
|
||||
if (result) return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async getModelsMetadata(
|
||||
selector?: (path: string, model: Model) => Promise<boolean>
|
||||
): Promise<Model[]> {
|
||||
@ -438,11 +462,11 @@ export default class JanModelExtension extends ModelExtension {
|
||||
const readJsonPromises = allDirectories.map(async (dirName) => {
|
||||
// filter out directories that don't match the selector
|
||||
// read model.json
|
||||
const jsonPath = await joinPath([
|
||||
const folderFullPath = await joinPath([
|
||||
JanModelExtension._homeDir,
|
||||
dirName,
|
||||
JanModelExtension._modelMetadataFileName,
|
||||
])
|
||||
const jsonPath = await this.getModelJsonPath(folderFullPath)
|
||||
|
||||
if (await fs.existsSync(jsonPath)) {
|
||||
// if we have the model.json file, read it
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user