mirror of
https://github.com/ollama/ollama.git
synced 2026-01-22 22:40:07 -05:00
Compare commits
1 Commits
main
...
fix-imageg
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91a3b77553 |
@@ -6,8 +6,9 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/ollama/ollama/envconfig"
|
||||
)
|
||||
|
||||
// ManifestLayer represents a layer in the manifest.
|
||||
@@ -32,33 +33,6 @@ type ModelManifest struct {
|
||||
BlobDir string
|
||||
}
|
||||
|
||||
// DefaultBlobDir returns the default blob storage directory.
|
||||
func DefaultBlobDir() string {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
home = "."
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
return filepath.Join(home, ".ollama", "models", "blobs")
|
||||
case "linux":
|
||||
return filepath.Join(home, ".ollama", "models", "blobs")
|
||||
case "windows":
|
||||
return filepath.Join(home, ".ollama", "models", "blobs")
|
||||
default:
|
||||
return filepath.Join(home, ".ollama", "models", "blobs")
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultManifestDir returns the default manifest storage directory.
|
||||
func DefaultManifestDir() string {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
home = "."
|
||||
}
|
||||
return filepath.Join(home, ".ollama", "models", "manifests")
|
||||
}
|
||||
|
||||
// LoadManifest loads a manifest for the given model name.
|
||||
// Model name format: "modelname" or "modelname:tag" or "host/namespace/name:tag"
|
||||
func LoadManifest(modelName string) (*ModelManifest, error) {
|
||||
@@ -76,7 +50,7 @@ func LoadManifest(modelName string) (*ModelManifest, error) {
|
||||
|
||||
return &ModelManifest{
|
||||
Manifest: &manifest,
|
||||
BlobDir: DefaultBlobDir(),
|
||||
BlobDir: filepath.Join(envconfig.Models(), "blobs"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -107,7 +81,7 @@ func resolveManifestPath(modelName string) string {
|
||||
name = parts[1]
|
||||
}
|
||||
|
||||
return filepath.Join(DefaultManifestDir(), host, namespace, name, tag)
|
||||
return filepath.Join(envconfig.Models(), "manifests", host, namespace, name, tag)
|
||||
}
|
||||
|
||||
// BlobPath returns the full path to a blob given its digest.
|
||||
|
||||
29
x/imagegen/manifest_test.go
Normal file
29
x/imagegen/manifest_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package imagegen
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/ollama/ollama/envconfig"
|
||||
)
|
||||
|
||||
func TestLoadManifestRespectsOLLAMA_MODELS(t *testing.T) {
|
||||
t.Setenv("OLLAMA_MODELS", "/custom/models/path")
|
||||
|
||||
// Verify envconfig.Models() returns our custom path
|
||||
if got := envconfig.Models(); got != "/custom/models/path" {
|
||||
t.Fatalf("envconfig.Models() = %q, want %q", got, "/custom/models/path")
|
||||
}
|
||||
|
||||
// LoadManifest will fail (no manifest exists), but we can verify
|
||||
// the error message contains the custom path
|
||||
_, err := LoadManifest("test-model")
|
||||
if err == nil {
|
||||
t.Fatal("expected error, got nil")
|
||||
}
|
||||
|
||||
expectedPath := filepath.Join("/custom/models/path", "manifests", "registry.ollama.ai", "library", "test-model", "latest")
|
||||
if got := err.Error(); got != "read manifest: open "+expectedPath+": no such file or directory" {
|
||||
t.Errorf("error = %q, want path to contain %q", got, expectedPath)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user