mirror of
https://github.com/ollama/ollama.git
synced 2026-01-29 07:12:03 +03:00
61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"runtime"
|
|
|
|
"github.com/ollama/ollama/envconfig"
|
|
)
|
|
|
|
// Claude implements Runner for Claude Code integration
|
|
type Claude struct{}
|
|
|
|
func (c *Claude) String() string { return "Claude Code" }
|
|
|
|
func (c *Claude) args(model string) []string {
|
|
if model != "" {
|
|
return []string{"--model", model}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (c *Claude) findPath() (string, error) {
|
|
if p, err := exec.LookPath("claude"); err == nil {
|
|
return p, nil
|
|
}
|
|
home, err := os.UserHomeDir()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
name := "claude"
|
|
if runtime.GOOS == "windows" {
|
|
name = "claude.exe"
|
|
}
|
|
fallback := filepath.Join(home, ".claude", "local", name)
|
|
if _, err := os.Stat(fallback); err != nil {
|
|
return "", err
|
|
}
|
|
return fallback, nil
|
|
}
|
|
|
|
func (c *Claude) Run(model string) error {
|
|
claudePath, err := c.findPath()
|
|
if err != nil {
|
|
return fmt.Errorf("claude is not installed, install from https://code.claude.com/docs/en/quickstart")
|
|
}
|
|
|
|
cmd := exec.Command(claudePath, c.args(model)...)
|
|
cmd.Stdin = os.Stdin
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
cmd.Env = append(os.Environ(),
|
|
"ANTHROPIC_BASE_URL="+envconfig.Host().String(),
|
|
"ANTHROPIC_API_KEY=",
|
|
"ANTHROPIC_AUTH_TOKEN=ollama",
|
|
)
|
|
return cmd.Run()
|
|
}
|