Merge pull request #3961 from janhq/chore/support-customized-openai-model-json

chore: support customized OpenAI model.json
This commit is contained in:
Louis 2024-11-06 17:29:57 +07:00 committed by GitHub
commit 0e653793eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View File

@ -1,5 +1,13 @@
import { InferenceEngine, Model, fs, joinPath } from '@janhq/core' import { InferenceEngine, Model, fs, joinPath } from '@janhq/core'
//// LEGACY MODEL FOLDER //// //// LEGACY MODEL FOLDER ////
const LocalEngines = [
InferenceEngine.cortex,
InferenceEngine.cortex_llamacpp,
InferenceEngine.cortex_tensorrtllm,
InferenceEngine.cortex_onnx,
InferenceEngine.nitro_tensorrt_llm,
InferenceEngine.nitro,
]
/** /**
* Scan through models folder and return downloaded models * Scan through models folder and return downloaded models
* @returns * @returns
@ -57,7 +65,11 @@ export const scanModelsFolder = async (): Promise<Model[]> => {
!source.url.startsWith(`https://`) !source.url.startsWith(`https://`)
) )
) )
if (existFiles.every((exist) => exist)) return model if (
!LocalEngines.includes(model.engine) ||
existFiles.every((exist) => exist)
)
return model
const result = await fs const result = await fs
.readdirSync(await joinPath([_homeDir, dirName])) .readdirSync(await joinPath([_homeDir, dirName]))

View File

@ -43,7 +43,13 @@ const useModels = () => {
.models.values() .models.values()
.toArray() .toArray()
.filter((e) => !isLocalEngine(e.engine)) .filter((e) => !isLocalEngine(e.engine))
const toUpdate = [...localModels, ...remoteModels] const toUpdate = [
...localModels,
...remoteModels.filter(
(e: Model) => !localModels.some((g: Model) => g.id === e.id)
),
]
setDownloadedModels(toUpdate) setDownloadedModels(toUpdate)
let isUpdated = false let isUpdated = false