diff --git a/godo/ai/server/llms.go b/godo/ai/server/llms.go index 58fc1e2..ce94137 100644 --- a/godo/ai/server/llms.go +++ b/godo/ai/server/llms.go @@ -3,6 +3,7 @@ package server import ( "fmt" "godo/libs" + "log" ) // ollama openai deepseek bigmodel alibaba 01ai cloudflare groq mistral anthropic llamafamily @@ -49,7 +50,8 @@ func GetHeadersAndUrl(req map[string]interface{}, chattype string) (map[string]s } else if engine == "gitee" { url = GetGiteeUrl(model, chattype) } else if engine == "ollama" { - url = GetOllamaUrl() + url = GetOllamaUrl() + "/v1" + log.Printf("get ollama url is %v", url) } } diff --git a/godo/ai/server/ollama.go b/godo/ai/server/ollama.go index 5063032..dc985ed 100644 --- a/godo/ai/server/ollama.go +++ b/godo/ai/server/ollama.go @@ -396,11 +396,11 @@ func GetOllamaModelDir() string { } func GetOllamaUrl() string { if s := strings.TrimSpace(Var("OLLAMA_HOST")); s != "" { - return s + return "http://" + s } ollamaUrl, ok := libs.GetConfig("ollamaUrl") if ok { - return ollamaUrl.(string) + return "http://" + ollamaUrl.(string) } else { return "http://localhost:11434" } diff --git a/godo/libs/dir.go b/godo/libs/dir.go index 68a407e..5af8944 100644 --- a/godo/libs/dir.go +++ b/godo/libs/dir.go @@ -25,6 +25,7 @@ import ( "os" "path/filepath" "runtime" + "strings" ) func InitServer() error { @@ -71,13 +72,21 @@ func InitOsDir() (string, error) { } func InitOllamaModelPath() { ollamaDir, ok := GetConfig("ollamaDir") - if ok && ollamaDir.(string) != "" { - os.Setenv("OLLAMA_MODELS", ollamaDir.(string)) + if ok { + dirStr, ok := ollamaDir.(string) + if ok && dirStr != "" { + os.Setenv("OLLAMA_MODELS", ollamaDir.(string)) + } } ollamaUrl, ok := GetConfig("ollamaUrl") - if ok && ollamaUrl.(string) != "" { - os.Setenv("OLLAMA_HOST", ollamaUrl.(string)) + if ok { + urlStr, ok := ollamaUrl.(string) + if ok && urlStr != "" { + urlStr = strings.TrimPrefix(strings.TrimPrefix(urlStr, "http://"), "https://") + os.Setenv("OLLAMA_HOST", urlStr) + } } + } func GetOsDir() (string, error) { osDir, ok := GetConfig("osPath")