fix: an edge case when start a model with relative model path

This commit is contained in:
Louis 2024-11-07 14:29:27 +07:00
parent a773e169fc
commit 0847b32e87
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2

View File

@ -15,6 +15,7 @@ import {
InferenceEngine, InferenceEngine,
getJanDataFolderPath, getJanDataFolderPath,
extractModelLoadParams, extractModelLoadParams,
fs,
} from '@janhq/core' } from '@janhq/core'
import PQueue from 'p-queue' import PQueue from 'p-queue'
import ky from 'ky' import ky from 'ky'
@ -96,22 +97,24 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
model.settings = settings model.settings = settings
} }
return await this.queue.add(() => ky return await this.queue.add(() =>
.post(`${CORTEX_API_URL}/v1/models/start`, { ky
json: { .post(`${CORTEX_API_URL}/v1/models/start`, {
...extractModelLoadParams(model.settings), json: {
model: model.id, ...extractModelLoadParams(model.settings),
engine: model: model.id,
model.engine === InferenceEngine.nitro // Legacy model cache engine:
? InferenceEngine.cortex_llamacpp model.engine === InferenceEngine.nitro // Legacy model cache
: model.engine, ? InferenceEngine.cortex_llamacpp
}, : model.engine,
}) },
.json() })
.catch(async (e) => { .json()
throw (await e.response?.json()) ?? e .catch(async (e) => {
}) throw (await e.response?.json()) ?? e
.then()) })
.then()
)
} }
override async unloadModel(model: Model): Promise<void> { override async unloadModel(model: Model): Promise<void> {
@ -159,7 +162,10 @@ export const getModelFilePath = async (
file: string file: string
): Promise<string> => { ): Promise<string> => {
// Symlink to the model file // Symlink to the model file
if (!model.sources[0]?.url.startsWith('http')) { if (
!model.sources[0]?.url.startsWith('http') &&
(await fs.existsSync(model.sources[0].url))
) {
return model.sources[0]?.url return model.sources[0]?.url
} }
return joinPath([await getJanDataFolderPath(), 'models', model.id, file]) return joinPath([await getJanDataFolderPath(), 'models', model.id, file])