15fb8e19a8
Foreman is a private queued Ollama endpoint with observability. Since it speaks native Ollama on the wire, the constructor delegates to the existing ollama provider — no new code paths. Streaming, tool use, and think all work transparently. baseURL is positional and required (no sensible default for a private daemon). apiKey can be empty for network-trusted deployments. See ADR-0011 in the foreman repo for the integration design.
164 lines
4.6 KiB
Go
164 lines
4.6 KiB
Go
package llm
|
|
|
|
import (
|
|
anthProvider "gitea.stevedudenhoeffer.com/steve/go-llm/v2/anthropic"
|
|
deepseekProvider "gitea.stevedudenhoeffer.com/steve/go-llm/v2/deepseek"
|
|
googleProvider "gitea.stevedudenhoeffer.com/steve/go-llm/v2/google"
|
|
groqProvider "gitea.stevedudenhoeffer.com/steve/go-llm/v2/groq"
|
|
moonshotProvider "gitea.stevedudenhoeffer.com/steve/go-llm/v2/moonshot"
|
|
ollamaProvider "gitea.stevedudenhoeffer.com/steve/go-llm/v2/ollama"
|
|
openaiProvider "gitea.stevedudenhoeffer.com/steve/go-llm/v2/openai"
|
|
xaiProvider "gitea.stevedudenhoeffer.com/steve/go-llm/v2/xai"
|
|
)
|
|
|
|
// OpenAI creates an OpenAI client.
|
|
//
|
|
// Example:
|
|
//
|
|
// model := llm.OpenAI("sk-...").Model("gpt-4o")
|
|
func OpenAI(apiKey string, opts ...ClientOption) *Client {
|
|
cfg := &clientConfig{}
|
|
for _, opt := range opts {
|
|
opt(cfg)
|
|
}
|
|
return NewClient(openaiProvider.New(apiKey, cfg.baseURL))
|
|
}
|
|
|
|
// Anthropic creates an Anthropic client.
|
|
//
|
|
// Example:
|
|
//
|
|
// model := llm.Anthropic("sk-ant-...").Model("claude-sonnet-4-20250514")
|
|
func Anthropic(apiKey string, opts ...ClientOption) *Client {
|
|
cfg := &clientConfig{}
|
|
for _, opt := range opts {
|
|
opt(cfg)
|
|
}
|
|
_ = cfg // Anthropic doesn't support custom base URL in the SDK
|
|
return NewClient(anthProvider.New(apiKey))
|
|
}
|
|
|
|
// Google creates a Google (Gemini) client.
|
|
//
|
|
// Example:
|
|
//
|
|
// model := llm.Google("...").Model("gemini-2.0-flash")
|
|
func Google(apiKey string, opts ...ClientOption) *Client {
|
|
cfg := &clientConfig{}
|
|
for _, opt := range opts {
|
|
opt(cfg)
|
|
}
|
|
_ = cfg // Google doesn't support custom base URL in the SDK
|
|
return NewClient(googleProvider.New(apiKey))
|
|
}
|
|
|
|
// DeepSeek creates a DeepSeek client (OpenAI-compatible).
|
|
//
|
|
// Example:
|
|
//
|
|
// model := llm.DeepSeek("sk-...").Model("deepseek-chat")
|
|
func DeepSeek(apiKey string, opts ...ClientOption) *Client {
|
|
cfg := &clientConfig{}
|
|
for _, opt := range opts {
|
|
opt(cfg)
|
|
}
|
|
return NewClient(deepseekProvider.New(apiKey, cfg.baseURL))
|
|
}
|
|
|
|
// Moonshot creates a Moonshot AI (Kimi) client (OpenAI-compatible).
|
|
//
|
|
// Example:
|
|
//
|
|
// model := llm.Moonshot("sk-...").Model("kimi-k2-0711-preview")
|
|
func Moonshot(apiKey string, opts ...ClientOption) *Client {
|
|
cfg := &clientConfig{}
|
|
for _, opt := range opts {
|
|
opt(cfg)
|
|
}
|
|
return NewClient(moonshotProvider.New(apiKey, cfg.baseURL))
|
|
}
|
|
|
|
// XAI creates an xAI (Grok) client (OpenAI-compatible).
|
|
//
|
|
// Example:
|
|
//
|
|
// model := llm.XAI("xai-...").Model("grok-2")
|
|
func XAI(apiKey string, opts ...ClientOption) *Client {
|
|
cfg := &clientConfig{}
|
|
for _, opt := range opts {
|
|
opt(cfg)
|
|
}
|
|
return NewClient(xaiProvider.New(apiKey, cfg.baseURL))
|
|
}
|
|
|
|
// Groq creates a Groq client (OpenAI-compatible).
|
|
//
|
|
// Example:
|
|
//
|
|
// model := llm.Groq("gsk-...").Model("llama-3.3-70b-versatile")
|
|
func Groq(apiKey string, opts ...ClientOption) *Client {
|
|
cfg := &clientConfig{}
|
|
for _, opt := range opts {
|
|
opt(cfg)
|
|
}
|
|
return NewClient(groqProvider.New(apiKey, cfg.baseURL))
|
|
}
|
|
|
|
// Ollama creates a client for a local Ollama instance using the native
|
|
// /api/chat endpoint. No API key is required. Use WithBaseURL to point at a
|
|
// non-default host/port.
|
|
//
|
|
// Example:
|
|
//
|
|
// model := llm.Ollama().Model("llama3.2")
|
|
func Ollama(opts ...ClientOption) *Client {
|
|
cfg := &clientConfig{}
|
|
for _, opt := range opts {
|
|
opt(cfg)
|
|
}
|
|
return NewClient(ollamaProvider.New("", cfg.baseURL))
|
|
}
|
|
|
|
// OllamaCloud creates a client targeting Ollama Cloud (https://ollama.com).
|
|
// The apiKey is required and is sent as `Authorization: Bearer <key>`. Use
|
|
// WithBaseURL to point at a private Ollama deployment that requires auth.
|
|
//
|
|
// Example:
|
|
//
|
|
// model := llm.OllamaCloud(os.Getenv("OLLAMA_API_KEY")).Model("kimi-k2.5")
|
|
func OllamaCloud(apiKey string, opts ...ClientOption) *Client {
|
|
cfg := &clientConfig{}
|
|
for _, opt := range opts {
|
|
opt(cfg)
|
|
}
|
|
baseURL := cfg.baseURL
|
|
if baseURL == "" {
|
|
baseURL = ollamaProvider.DefaultCloudBaseURL
|
|
}
|
|
return NewClient(ollamaProvider.New(apiKey, baseURL))
|
|
}
|
|
|
|
// Foreman creates a client targeting a foreman daemon (a private, authenticated
|
|
// Ollama endpoint with queuing and observability). baseURL is required
|
|
// (e.g. "http://foreman:8080"). apiKey is the optional static bearer token; pass
|
|
// "" for an unauthenticated (network-trusted) deployment.
|
|
//
|
|
// foreman speaks native Ollama on the wire, so this delegates to the ollama
|
|
// provider unchanged — streaming, tool use, and think all work transparently.
|
|
//
|
|
// See: https://gitea.stevedudenhoeffer.com/steve/foreman
|
|
//
|
|
// Example:
|
|
//
|
|
// model := llm.Foreman("http://foreman.orgrimmar:8080", token).Model("qwen3:30b")
|
|
func Foreman(baseURL, apiKey string, opts ...ClientOption) *Client {
|
|
cfg := &clientConfig{}
|
|
for _, opt := range opts {
|
|
opt(cfg)
|
|
}
|
|
if cfg.baseURL != "" {
|
|
baseURL = cfg.baseURL
|
|
}
|
|
return NewClient(ollamaProvider.New(apiKey, baseURL))
|
|
}
|