Fix absolute path names + gguf detection (#8428)

This commit is contained in:
Patrick Devine 2025-01-14 19:01:24 -08:00 committed by GitHub
parent 61676fb506
commit 2539f2dbf9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 217 additions and 28 deletions

View file

@ -178,12 +178,37 @@ func convertModelFromFiles(files map[string]string, baseLayers []*layerGGML, isA
}
func detectModelTypeFromFiles(files map[string]string) string {
// todo make this more robust by actually introspecting the files
for fn := range files {
if strings.HasSuffix(fn, ".safetensors") {
return "safetensors"
} else if strings.HasSuffix(fn, ".bin") || strings.HasSuffix(fn, ".gguf") {
} else if strings.HasSuffix(fn, ".gguf") {
return "gguf"
} else {
// try to see if we can find a gguf file even without the file extension
blobPath, err := GetBlobsPath(files[fn])
if err != nil {
slog.Error("error getting blobs path", "file", fn)
return ""
}
f, err := os.Open(blobPath)
if err != nil {
slog.Error("error reading file", "error", err)
return ""
}
defer f.Close()
buf := make([]byte, 4)
_, err = f.Read(buf)
if err != nil {
slog.Error("error reading file", "error", err)
return ""
}
ct := llm.DetectGGMLType(buf)
if ct == "gguf" {
return "gguf"
}
}
}