From cd638fff6c946f6e92746e6e3922efe8e73fa5a2 Mon Sep 17 00:00:00 2001 From: trungtt6 <74585678+trungtt6@users.noreply.github.com> Date: Mon, 16 Feb 2026 11:28:38 +0800 Subject: [PATCH] Add local AI ollama for security purpose (#226) Co-authored-by: PhotoPortfolio Developer --- config/config.example.json | 4 ++++ pkg/config/config.go | 1 + pkg/providers/http_provider.go | 14 +++++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/config/config.example.json b/config/config.example.json index aa75c83..3c9158e 100644 --- a/config/config.example.json +++ b/config/config.example.json @@ -107,6 +107,10 @@ "moonshot": { "api_key": "sk-xxx", "api_base": "" + }, + "ollama": { + "api_key": "", + "api_base": "http://localhost:11434/v1" } }, "tools": { diff --git a/pkg/config/config.go b/pkg/config/config.go index d76ec80..da33748 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -175,6 +175,7 @@ type ProvidersConfig struct { VLLM ProviderConfig `json:"vllm"` Gemini ProviderConfig `json:"gemini"` Nvidia ProviderConfig `json:"nvidia"` + Ollama ProviderConfig `json:"ollama"` Moonshot ProviderConfig `json:"moonshot"` ShengSuanYun ProviderConfig `json:"shengsuanyun"` DeepSeek ProviderConfig `json:"deepseek"` diff --git a/pkg/providers/http_provider.go b/pkg/providers/http_provider.go index 17eb621..60294c4 100644 --- a/pkg/providers/http_provider.go +++ b/pkg/providers/http_provider.go @@ -53,10 +53,10 @@ func (p *HTTPProvider) Chat(ctx context.Context, messages []Message, tools []Too return nil, fmt.Errorf("API base not configured") } - // Strip provider prefix from model name (e.g., moonshot/kimi-k2.5 -> kimi-k2.5) + // Strip provider prefix from model name (e.g., moonshot/kimi-k2.5 -> kimi-k2.5, groq/openai/gpt-oss-120b -> openai/gpt-oss-120b, ollama/qwen2.5:14b -> qwen2.5:14b) if idx := strings.Index(model, "/"); idx != -1 { prefix := model[:idx] - if prefix == "moonshot" || prefix == "nvidia" { + if prefix == "moonshot" || prefix == "nvidia" || prefix == "groq" || prefix == "ollama" { model = model[idx+1:] } } @@ -400,7 +400,15 @@ func CreateProvider(cfg *config.Config) (LLMProvider, error) { if apiBase == "" { apiBase = "https://integrate.api.nvidia.com/v1" } - + case (strings.Contains(lowerModel, "ollama") || strings.HasPrefix(model, "ollama/")) && cfg.Providers.Ollama.APIKey != "": + fmt.Println("Ollama provider selected based on model name prefix") + apiKey = cfg.Providers.Ollama.APIKey + apiBase = cfg.Providers.Ollama.APIBase + proxy = cfg.Providers.Ollama.Proxy + if apiBase == "" { + apiBase = "http://localhost:11434/v1" + } + fmt.Println("Ollama apiBase:", apiBase) case cfg.Providers.VLLM.APIBase != "": apiKey = cfg.Providers.VLLM.APIKey apiBase = cfg.Providers.VLLM.APIBase