fix: use OpenAI client for Ollama endpoint

This commit is contained in:
shenlan 2025-08-12 23:39:32 +08:00
parent 37410d2dc8
commit b57433caef
2 changed files with 3 additions and 8 deletions

View File

@ -12,7 +12,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/ollama"
"github.com/tmc/langchaingo/llms/openai"
"gopkg.in/yaml.v3"
)
@ -125,7 +124,7 @@ func loadConfig() (string, string, string, string, time.Duration, int) {
switch provider {
case "ollama":
if endpoint == "" {
endpoint = "http://localhost:11434/v1/chat/completions"
endpoint = "http://localhost:11434/v1"
}
if model == "" {
model = "llama2:13b"
@ -163,11 +162,7 @@ func callLLM(question string) (string, error) {
switch provider {
case "ollama":
llm, err = ollama.New(
ollama.WithModel(model),
ollama.WithServerURL(url),
ollama.WithHTTPClient(httpClient),
)
fallthrough
default:
llm, err = openai.New(
openai.WithToken(token),

View File

@ -29,7 +29,7 @@ models:
provider: "ollama"
models:
- 'llama2:13b'
endpoint: "http://127.0.0.1:11434/v1/chat/completions"
endpoint: "http://127.0.0.1:11434/v1"
token: ""
# For PROD
#models: