Kaynağa Gözat

migrate registry domain

Michael Yang 1 yıl önce
ebeveyn
işleme
bf5ba6065b
3 değiştirilmiş dosya ile 41 ekleme ve 2 silme
  1. 1 1
      docs/api.md
  2. 33 1
      server/modelpath.go
  3. 7 0
      server/routes.go

+ 1 - 1
docs/api.md

@@ -468,7 +468,7 @@ curl http://localhost:11434/api/chat -d '{
 
 ```json
 {
-  "model": "registry.ollama.ai/library/llama3:latest",
+  "model": "ollama.com/library/llama3:latest",
   "created_at": "2023-12-12T14:13:43.416799Z",
   "message": {
     "role": "assistant",

+ 33 - 1
server/modelpath.go

@@ -3,6 +3,8 @@ package server
 import (
 	"errors"
 	"fmt"
+	"io/fs"
+	"log/slog"
 	"net/url"
 	"os"
 	"path/filepath"
@@ -21,7 +23,7 @@ type ModelPath struct {
 }
 
 const (
-	DefaultRegistry       = "registry.ollama.ai"
+	DefaultRegistry       = "ollama.com"
 	DefaultNamespace      = "library"
 	DefaultTag            = "latest"
 	DefaultProtocolScheme = "https"
@@ -151,3 +153,33 @@ func GetBlobsPath(digest string) (string, error) {
 
 	return path, nil
 }
+
+func migrateRegistryDomain() error {
+	manifests, err := GetManifestPath()
+	if err != nil {
+		return err
+	}
+
+	olddomainpath := filepath.Join(manifests, "registry.ollama.ai")
+	newdomainpath := filepath.Join(manifests, DefaultRegistry)
+
+	return filepath.Walk(olddomainpath, func(path string, info fs.FileInfo, err error) error {
+		if err != nil {
+			return err
+		}
+
+		if !info.IsDir() {
+			slog.Info("migrating registry domain", "path", path)
+			newpath := filepath.Join(newdomainpath, strings.TrimPrefix(path, olddomainpath))
+			if err := os.MkdirAll(filepath.Dir(newpath), 0o755); err != nil {
+				return err
+			}
+
+			if err := os.Rename(path, newpath); err != nil {
+				return err
+			}
+		}
+
+		return nil
+	})
+}

+ 7 - 0
server/routes.go

@@ -1070,6 +1070,13 @@ func Serve(ln net.Listener) error {
 		}
 	}
 
+	// migrate registry.ollama.ai to ollama.com
+	if err := migrateRegistryDomain(); err != nil {
+		if !errors.Is(err, os.ErrNotExist) {
+			return err
+		}
+	}
+
 	ctx, done := context.WithCancel(context.Background())
 	schedCtx, schedDone := context.WithCancel(ctx)
 	sched := InitScheduler(schedCtx)