Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

feat(llamacpp): use gguf general.name for imported model name

Akarshan00cdc85843d5
diff --git a/extensions/llamacpp-extension/src/index.ts b/extensions/llamacpp-extension/src/index.ts
index 8202dcc2b..447372ae6 100644
--- a/extensions/llamacpp-extension/src/index.ts
+++ b/extensions/llamacpp-extension/src/index.ts
@@ -2342,6 +2342,7 @@ export default class llamacpp_extension extends AIEngine {
const fullModelPath = await joinPath([janDataFolderPath, modelPath])
let isEmbedding = false
let mtpLayers = 0
+ let resolvedName: string | undefined
try {
// Validate main model file
@@ -2355,6 +2356,12 @@ export default class llamacpp_extension extends AIEngine {
}
mtpLayers = detectMtpLayersFromGgufMeta(modelMetadata.metadata)
+ const rawName = modelMetadata.metadata?.['general.name']
+ if (typeof rawName === 'string') {
+ const normalized = rawName.trim().replace(/\s+/g, '-')
+ if (normalized.length > 0) resolvedName = normalized
+ }
+
// Validate mmproj file if present
if (mmprojPath) {
const fullMmprojPath = await joinPath([janDataFolderPath, mmprojPath])
@@ -2380,12 +2387,16 @@ export default class llamacpp_extension extends AIEngine {
).size
}
- // TODO: add name as import() argument
+ if (!resolvedName) {
+ const base = opts.modelPath.split(/[\\/]/).pop() ?? modelId
+ resolvedName = base.replace(/\.gguf$/i, '') || modelId
+ }
+
// TODO: add updateModelConfig() method
const modelConfig = {
model_path: modelPath,
mmproj_path: mmprojPath,
- name: modelId,
+ name: resolvedName,
size_bytes,
model_sha256: opts.modelSha256,
model_size_bytes: opts.modelSize,