Browse Source

change ollama url

master
godo 6 months ago
parent
commit
e73a3a098a
  1. 4
      godo/ai/server/llms.go
  2. 4
      godo/ai/server/ollama.go
  3. 17
      godo/libs/dir.go

4
godo/ai/server/llms.go

@ -3,6 +3,7 @@ package server
import ( import (
"fmt" "fmt"
"godo/libs" "godo/libs"
"log"
) )
// ollama openai deepseek bigmodel alibaba 01ai cloudflare groq mistral anthropic llamafamily // 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" { } else if engine == "gitee" {
url = GetGiteeUrl(model, chattype) url = GetGiteeUrl(model, chattype)
} else if engine == "ollama" { } else if engine == "ollama" {
url = GetOllamaUrl() url = GetOllamaUrl() + "/v1"
log.Printf("get ollama url is %v", url)
} }
} }

4
godo/ai/server/ollama.go

@ -396,11 +396,11 @@ func GetOllamaModelDir() string {
} }
func GetOllamaUrl() string { func GetOllamaUrl() string {
if s := strings.TrimSpace(Var("OLLAMA_HOST")); s != "" { if s := strings.TrimSpace(Var("OLLAMA_HOST")); s != "" {
return s return "http://" + s
} }
ollamaUrl, ok := libs.GetConfig("ollamaUrl") ollamaUrl, ok := libs.GetConfig("ollamaUrl")
if ok { if ok {
return ollamaUrl.(string) return "http://" + ollamaUrl.(string)
} else { } else {
return "http://localhost:11434" return "http://localhost:11434"
} }

17
godo/libs/dir.go

@ -25,6 +25,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings"
) )
func InitServer() error { func InitServer() error {
@ -71,13 +72,21 @@ func InitOsDir() (string, error) {
} }
func InitOllamaModelPath() { func InitOllamaModelPath() {
ollamaDir, ok := GetConfig("ollamaDir") ollamaDir, ok := GetConfig("ollamaDir")
if ok && ollamaDir.(string) != "" { if ok {
os.Setenv("OLLAMA_MODELS", ollamaDir.(string)) dirStr, ok := ollamaDir.(string)
if ok && dirStr != "" {
os.Setenv("OLLAMA_MODELS", ollamaDir.(string))
}
} }
ollamaUrl, ok := GetConfig("ollamaUrl") ollamaUrl, ok := GetConfig("ollamaUrl")
if ok && ollamaUrl.(string) != "" { if ok {
os.Setenv("OLLAMA_HOST", ollamaUrl.(string)) urlStr, ok := ollamaUrl.(string)
if ok && urlStr != "" {
urlStr = strings.TrimPrefix(strings.TrimPrefix(urlStr, "http://"), "https://")
os.Setenv("OLLAMA_HOST", urlStr)
}
} }
} }
func GetOsDir() (string, error) { func GetOsDir() (string, error) {
osDir, ok := GetConfig("osPath") osDir, ok := GetConfig("osPath")

Loading…
Cancel
Save