1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package gpu
- import (
- "fmt"
- "log/slog"
- "os"
- "path/filepath"
- "runtime"
- "strings"
- )
- func AssetsDir() (string, error) {
- home, err := os.UserHomeDir()
- if err != nil {
- return "", err
- }
- return filepath.Join(home, ".ollama", "assets"), nil
- }
- func UpdatePath(dir string) {
- if runtime.GOOS == "windows" {
- tmpDir := filepath.Dir(dir)
- pathComponents := strings.Split(os.Getenv("PATH"), ";")
- i := 0
- for _, comp := range pathComponents {
- if strings.EqualFold(comp, dir) {
- return
- }
- // Remove any other prior paths to our temp dir
- if !strings.HasPrefix(strings.ToLower(comp), strings.ToLower(tmpDir)) {
- pathComponents[i] = comp
- i++
- }
- }
- newPath := strings.Join(append([]string{dir}, pathComponents...), ";")
- slog.Info(fmt.Sprintf("Updating PATH to %s", newPath))
- os.Setenv("PATH", newPath)
- }
- // linux and darwin rely on rpath
- }
|