Documentation
¶
Overview ¶
Package llm provides provider-agnostic LLM completion for the sx app. The user picks ONE configured provider (an installed CLI, a local Ollama server, or a hosted API reached with their own key) and every caller — extensions via the sx.llm bridge, future core features — goes through the same Complete call. Nothing in the request or response types is specific to any vendor.
Index ¶
Constants ¶
const ( ProviderClaudeCLI = "claude-cli" ProviderCodexCLI = "codex-cli" ProviderGeminiCLI = "gemini-cli" ProviderOllama = "ollama" ProviderAnthropic = "anthropic" ProviderOpenAI = "openai" ProviderGoogle = "google" )
Provider IDs. These are the values persisted in the app's LLM config and shown in the settings picker; they never change meaning.
const DefaultMaxTokens = 8192
DefaultMaxTokens bounds output when the caller doesn't ask for a specific budget.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Provider string `json:"provider"`
Model string `json:"model,omitempty"`
BaseURL string `json:"baseUrl,omitempty"`
}
Config is the user's provider selection, persisted by the app. The API key is resolved from the OS keyring at call time and never stored here. BaseURL overrides the provider's default endpoint: Ollama's server address, an OpenAI-compatible endpoint (OpenRouter, Groq, vLLM, LM Studio, …), or a gateway in front of Anthropic or Google. CLI providers ignore it.
type Message ¶
Message is one turn of a conversation. Role is "system", "user", or "assistant"; providers that have no native system slot fold system messages into the prompt.
type Provider ¶
type Provider interface {
ID() string
Complete(ctx context.Context, req Request) (Response, error)
}
Provider is one way of reaching a model. Implementations must be safe for concurrent use.
type ProviderInfo ¶
type ProviderInfo struct {
ID string `json:"id"`
Kind string `json:"kind"` // "cli" | "local" | "api"
Label string `json:"label"`
Detail string `json:"detail,omitempty"` // binary path, server URL, …
// Available: the provider can be selected right now. CLI providers
// need the binary installed; Ollama needs a responding server; API
// providers are always selectable (the key is entered in settings).
Available bool `json:"available"`
// Models: for Ollama, the locally pulled models to choose from.
Models []string `json:"models,omitempty"`
// NeedsAPIKey / NeedsModel drive which settings inputs to show.
NeedsAPIKey bool `json:"needsApiKey"`
NeedsModel bool `json:"needsModel"`
}
ProviderInfo describes one provider option for the settings picker.
func DetectProviders ¶
func DetectProviders(ctx context.Context, baseURL string) []ProviderInfo
DetectProviders enumerates every provider option and its current availability. baseURL is the user's configured Ollama address ("" for the default).
type Request ¶
type Request struct {
Messages []Message `json:"messages"`
Schema json.RawMessage `json:"schema,omitempty"`
Model string `json:"model,omitempty"`
MaxTokens int `json:"maxTokens,omitempty"`
}
Request is a provider-neutral completion request. When Schema (a JSON Schema document) is set, the provider must return a JSON document matching it in Response.Text — natively where the backend supports constrained output, via prompt instruction plus extraction otherwise.