assets.go 873 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package gpu
  2. import (
  3. "fmt"
  4. "log/slog"
  5. "os"
  6. "path/filepath"
  7. "runtime"
  8. "strings"
  9. )
  10. func AssetsDir() (string, error) {
  11. home, err := os.UserHomeDir()
  12. if err != nil {
  13. return "", err
  14. }
  15. return filepath.Join(home, ".ollama", "assets"), nil
  16. }
  17. func UpdatePath(dir string) {
  18. if runtime.GOOS == "windows" {
  19. tmpDir := filepath.Dir(dir)
  20. pathComponents := strings.Split(os.Getenv("PATH"), ";")
  21. i := 0
  22. for _, comp := range pathComponents {
  23. if strings.EqualFold(comp, dir) {
  24. return
  25. }
  26. // Remove any other prior paths to our temp dir
  27. if !strings.HasPrefix(strings.ToLower(comp), strings.ToLower(tmpDir)) {
  28. pathComponents[i] = comp
  29. i++
  30. }
  31. }
  32. newPath := strings.Join(append([]string{dir}, pathComponents...), ";")
  33. slog.Info(fmt.Sprintf("Updating PATH to %s", newPath))
  34. os.Setenv("PATH", newPath)
  35. }
  36. // linux and darwin rely on rpath
  37. }