veylant/internal/provider/ollama/adapter.go
2026-02-23 13:35:04 +01:00

33 lines
1.0 KiB
Go

// Package ollama provides a provider.Adapter for local Ollama (and vLLM) servers.
// Ollama exposes an OpenAI-compatible /v1/chat/completions endpoint — we delegate
// directly to openai.New with no auth key required.
package ollama
import (
"github.com/veylant/ia-gateway/internal/provider/openai"
)
// Config holds Ollama adapter configuration.
type Config struct {
BaseURL string // default: http://localhost:11434/v1
TimeoutSeconds int // longer default (120s) because local models are slower
MaxConns int
}
// New creates an Ollama adapter backed by the OpenAI-compatible local API.
// Supported models: llama3, phi3, qwen2, gemma, and any model served by Ollama/vLLM.
func New(cfg Config) *openai.Adapter {
if cfg.BaseURL == "" {
cfg.BaseURL = "http://localhost:11434/v1"
}
if cfg.TimeoutSeconds == 0 {
cfg.TimeoutSeconds = 120
}
return openai.New(openai.Config{
APIKey: "", // Ollama does not require an API key
BaseURL: cfg.BaseURL,
TimeoutSeconds: cfg.TimeoutSeconds,
MaxConns: cfg.MaxConns,
})
}