74b3c53f36
Ollama Cloud (https://ollama.com) requires a Bearer-token API key and exposes the same /api/chat surface as local Ollama. OllamaCloud(apiKey) returns a client preconfigured for the cloud endpoint; Ollama() remains the local-instance constructor. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
140 lines
3.8 KiB
Go
140 lines
3.8 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))
|
|
}
|