refactor: clean up legacy vision model settings (#4777)

This commit is contained in:
Louis 2025-03-06 09:53:31 +07:00 committed by GitHub
parent 8dc30dd047
commit 4f7a8d58ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 53 deletions

View File

@ -147,36 +147,10 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
override async loadModel(
model: Model & { file_path?: string }
): Promise<void> {
if (
(model.engine === InferenceEngine.nitro || model.settings.vision_model) &&
model.settings.llama_model_path
) {
// Legacy chat model support
model.settings = {
...model.settings,
llama_model_path: await getModelFilePath(
model,
model.settings.llama_model_path
),
}
} else {
const { llama_model_path, ...settings } = model.settings
model.settings = settings
}
// Cortex will handle these settings
const { llama_model_path, mmproj, ...settings } = model.settings
model.settings = settings
if (
(model.engine === InferenceEngine.nitro || model.settings.vision_model) &&
model.settings.mmproj
) {
// Legacy clip vision model support
model.settings = {
...model.settings,
mmproj: await getModelFilePath(model, model.settings.mmproj),
}
} else {
const { mmproj, ...settings } = model.settings
model.settings = settings
}
const controller = new AbortController()
const { signal } = controller
@ -334,22 +308,3 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
)
}
}
/// Legacy
const getModelFilePath = async (
model: Model & { file_path?: string },
file: string
): Promise<string> => {
// Symlink to the model file
if (
!model.sources[0]?.url.startsWith('http') &&
(await fs.existsSync(model.sources[0].url))
) {
return model.sources[0]?.url
}
if (model.file_path) {
await joinPath([await dirName(model.file_path), file])
}
return joinPath([await getJanDataFolderPath(), 'models', model.id, file])
}
///

View File

@ -173,16 +173,16 @@ export default class JanModelExtension extends ModelExtension {
toImportModels.map(async (model: Model & { file_path: string }) => {
return this.importModel(
model.id,
model.sources[0].url.startsWith('http') ||
!(await fs.existsSync(model.sources[0].url))
model.sources?.[0]?.url.startsWith('http') ||
!(await fs.existsSync(model.sources?.[0]?.url))
? await joinPath([
await dirName(model.file_path),
model.sources[0]?.filename ??
model.sources?.[0]?.filename ??
model.settings?.llama_model_path ??
model.sources[0]?.url.split('/').pop() ??
model.sources?.[0]?.url.split('/').pop() ??
model.id,
]) // Copied models
: model.sources[0].url, // Symlink models,
: model.sources?.[0]?.url, // Symlink models,
model.name
)
.then((e) => {