Documentation
¶
Overview ¶
Package provider selects, configures and drives the LLM providers used to generate commit messages. Provider access goes through Fantasy (charm.land/fantasy), a multi-provider AI SDK, behind the small LLM interface.
Index ¶
- Constants
- func Aliases() map[string]string
- func CallLLM(ctx context.Context, llm LLM, llmAPICallTimeout time.Duration, prompt string) (string, error)
- func ChunkDiff(maxChars int, diff string) ([]string, error)
- func GenerateCommitMessage(ctx context.Context, llm LLM, llmAPICallTimeout time.Duration, ...) (string, error)
- func GenerateCommitMessageLoop(llm LLM, llmAPICallTimeout time.Duration, stats string, chunks []string, ...) (string, error)
- func HandleTryAgain() string
- func Names() []string
- type Config
- type Kind
- type LLM
- type Spec
Constants ¶
const ( Anthropic = "anthropic" Azure = "azure" Bedrock = "bedrock" DeepSeek = "deepseek" Google = "google" Groq = "groq" HuggingFace = "huggingface" Mistral = "mistral" Ollama = "ollama" OpenAI = "openai" OpenAICompatible = "openai-compatible" OpenRouter = "openrouter" XAI = "xai" )
Names of the supported providers, as accepted by the --provider flag.
const DefaultMaxOutputTokens int64 = 16384
DefaultMaxOutputTokens bounds the size of a generated commit message. It is generous on purpose: reasoning models spend part of this budget thinking before they answer.
Variables ¶
This section is empty.
Functions ¶
func CallLLM ¶
func CallLLM( ctx context.Context, llm LLM, llmAPICallTimeout time.Duration, prompt string, ) (string, error)
CallLLM asks the LLM for a completion, bounding the call with the given timeout on top of the caller's context.
func GenerateCommitMessage ¶
func GenerateCommitMessage( ctx context.Context, llm LLM, llmAPICallTimeout time.Duration, stats, diff string, chunkNumber, totalChunks int, additionalInstructions string, ) (string, error)
GenerateCommitMessage generates a commit message using LLM API with additional instructions.
Types ¶
type Config ¶ added in v0.2.0
type Config struct {
// Provider is a canonical provider name or alias, see Lookup.
Provider string
// Model overrides the provider's default model.
Model string
// BaseURL overrides the provider endpoint.
BaseURL string
// MaxOutputTokens caps the response size. Zero means
// DefaultMaxOutputTokens.
MaxOutputTokens int64
}
Config selects and configures the LLM provider.
type Kind ¶ added in v0.2.0
type Kind string
Kind identifies which Fantasy provider package backs a Spec.
type LLM ¶ added in v0.2.0
type LLM interface {
// Generate returns the model's text response to a single user prompt.
Generate(ctx context.Context, prompt string) (string, error)
// Provider returns the provider name.
Provider() string
// Model returns the model identifier.
Model() string
}
LLM is the minimal language model surface committer needs. It hides the underlying SDK so the rest of the application, and the tests, don't depend on it.
type Spec ¶ added in v0.2.0
type Spec struct {
// Name is the identifier accepted by the --provider flag.
Name string
// Description is a short, human readable summary shown in help.
Description string
// Kind selects the Fantasy provider package used to talk to the API.
Kind Kind
// APIKeyEnvs are the environment variables checked, in order, for the
// API key. The first non-empty value wins.
APIKeyEnvs []string
// APIKeyRequired makes initialization fail early when no API key is
// found. Providers whose SDK resolves credentials on its own (for
// example Anthropic auth tokens, or AWS credentials for Bedrock) or that
// need no key at all (Ollama) leave it false.
APIKeyRequired bool
// BaseURLEnvs are the environment variables checked, in order, for an
// endpoint override. The --base-url flag takes precedence over them.
BaseURLEnvs []string
// DefaultBaseURL is used when neither the flag nor the environment
// provide one. Empty means the SDK default.
DefaultBaseURL string
// BaseURLRequired makes initialization fail early when no base URL is
// available.
BaseURLRequired bool
// DefaultModel is used when --model is not set. Empty means the model
// must be provided explicitly.
DefaultModel string
}
Spec describes how committer reaches one LLM provider.
func Lookup ¶ added in v0.2.0
Lookup finds a provider by canonical name or alias. Matching is case-insensitive and ignores surrounding whitespace.
func Specs ¶ added in v0.2.0
func Specs() []Spec
Specs returns the supported providers in display order.