Files
aichat/llm/ollama.go
T
2026-06-17 11:29:51 +08:00

47 lines
1.1 KiB
Go

package llm
import (
"errors"
"net/url"
"strings"
)
func IsOllamaProfile(profile *Profile) bool {
if profile == nil {
return false
}
u, err := url.Parse(strings.TrimSpace(profile.Config.BaseURL))
if err != nil {
return strings.Contains(profile.Config.BaseURL, ":11434")
}
host := strings.ToLower(u.Hostname())
port := u.Port()
return port == "11434" && (host == "127.0.0.1" || host == "localhost" || host == "::1")
}
func ShouldParseThinkTags(profile *Profile) bool {
if profile == nil {
return false
}
if profile.Config.ParseThinkTags != nil {
return *profile.Config.ParseThinkTags
}
return IsOllamaProfile(profile)
}
func OllamaBaseURL(profile *Profile) (string, error) {
if profile == nil {
return "", errors.New("Ollama 配置为空")
}
u, err := url.Parse(strings.TrimSpace(profile.Config.BaseURL))
if err != nil {
return "", err
}
if strings.TrimRight(u.Path, "/") == "/v1" {
u.Path = strings.TrimSuffix(strings.TrimRight(u.Path, "/"), "/v1")
}
u.RawQuery = ""
u.Fragment = ""
return strings.TrimRight(u.String(), "/"), nil
}