Przeglądaj źródła

use filepath for os compat

Michael Yang 1 rok temu
rodzic
commit
743e957d88
3 zmienionych plików z 13 dodań i 13 usunięć
  1. 3 3
      cmd/cmd.go
  2. 6 6
      server/models.go
  3. 4 4
      server/routes.go

+ 3 - 3
cmd/cmd.go

@@ -9,7 +9,7 @@ import (
 	"net"
 	"net"
 	"net/http"
 	"net/http"
 	"os"
 	"os"
-	"path"
+	"path/filepath"
 	"strings"
 	"strings"
 	"time"
 	"time"
 
 
@@ -27,7 +27,7 @@ func cacheDir() string {
 		panic(err)
 		panic(err)
 	}
 	}
 
 
-	return path.Join(home, ".ollama")
+	return filepath.Join(home, ".ollama")
 }
 }
 
 
 func RunRun(cmd *cobra.Command, args []string) error {
 func RunRun(cmd *cobra.Command, args []string) error {
@@ -209,7 +209,7 @@ func NewCLI() *cobra.Command {
 		},
 		},
 		PersistentPreRunE: func(_ *cobra.Command, args []string) error {
 		PersistentPreRunE: func(_ *cobra.Command, args []string) error {
 			// create the models directory and it's parent
 			// create the models directory and it's parent
-			return os.MkdirAll(path.Join(cacheDir(), "models"), 0o700)
+			return os.MkdirAll(filepath.Join(cacheDir(), "models"), 0o700)
 		},
 		},
 	}
 	}
 
 

+ 6 - 6
server/models.go

@@ -7,7 +7,7 @@ import (
 	"io"
 	"io"
 	"net/http"
 	"net/http"
 	"os"
 	"os"
-	"path"
+	"path/filepath"
 	"strconv"
 	"strconv"
 )
 )
 
 
@@ -32,14 +32,14 @@ func (m *Model) FullName() string {
 		panic(err)
 		panic(err)
 	}
 	}
 
 
-	return path.Join(home, ".ollama", "models", m.Name+".bin")
+	return filepath.Join(home, ".ollama", "models", m.Name+".bin")
 }
 }
 
 
 func (m *Model) TempFile() string {
 func (m *Model) TempFile() string {
 	fullName := m.FullName()
 	fullName := m.FullName()
-	return path.Join(
-		path.Dir(fullName),
-		fmt.Sprintf(".%s.part", path.Base(fullName)),
+	return filepath.Join(
+		filepath.Dir(fullName),
+		fmt.Sprintf(".%s.part", filepath.Base(fullName)),
 	)
 	)
 }
 }
 
 
@@ -118,7 +118,7 @@ func saveModel(model *Model, fn func(total, completed int64)) error {
 			return os.Rename(model.TempFile(), model.FullName())
 			return os.Rename(model.TempFile(), model.FullName())
 		}
 		}
 
 
-		n , err := io.CopyN(out, resp.Body, 8192)
+		n, err := io.CopyN(out, resp.Body, 8192)
 		if err != nil && !errors.Is(err, io.EOF) {
 		if err != nil && !errors.Is(err, io.EOF) {
 			return err
 			return err
 		}
 		}

+ 4 - 4
server/routes.go

@@ -10,7 +10,7 @@ import (
 	"net"
 	"net"
 	"net/http"
 	"net/http"
 	"os"
 	"os"
-	"path"
+	"path/filepath"
 	"strings"
 	"strings"
 	"text/template"
 	"text/template"
 	"time"
 	"time"
@@ -32,7 +32,7 @@ func cacheDir() string {
 		panic(err)
 		panic(err)
 	}
 	}
 
 
-	return path.Join(home, ".ollama")
+	return filepath.Join(home, ".ollama")
 }
 }
 
 
 func generate(c *gin.Context) {
 func generate(c *gin.Context) {
@@ -55,7 +55,7 @@ func generate(c *gin.Context) {
 			c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
 			c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
 			return
 			return
 		}
 		}
-		req.Model = path.Join(cacheDir(), "models", req.Model+".bin")
+		req.Model = filepath.Join(cacheDir(), "models", req.Model+".bin")
 	}
 	}
 
 
 	templateNames := make([]string, 0, len(templates.Templates()))
 	templateNames := make([]string, 0, len(templates.Templates()))
@@ -63,7 +63,7 @@ func generate(c *gin.Context) {
 		templateNames = append(templateNames, template.Name())
 		templateNames = append(templateNames, template.Name())
 	}
 	}
 
 
-	match, _ := matchRankOne(path.Base(req.Model), templateNames)
+	match, _ := matchRankOne(filepath.Base(req.Model), templateNames)
 	if template := templates.Lookup(match); template != nil {
 	if template := templates.Lookup(match); template != nil {
 		var sb strings.Builder
 		var sb strings.Builder
 		if err := template.Execute(&sb, req); err != nil {
 		if err := template.Execute(&sb, req); err != nil {