Documentation
¶
Overview ¶
*
- Copyright © 2025 Magdiel Campelo <github.com/MagdielCAS/magi-cli>
- This file is part of the magi-cli
*
Package llm centralizes AI service construction for magi commands. The service builder enforces shared defaults (timeouts, provider selection, base URL overrides, and hardened HTTP clients) that are consumed by cmd/commit.go, cmd/pr.go, and future commands that need to talk to LLMs.
*
- Copyright © 2025 Magdiel Campelo <github.com/MagdielCAS/magi-cli>
- This file is part of the magi-cli
*
Index ¶
- func FixCommitMessage(ctx context.Context, runtime *shared.RuntimeContext, ...) (string, error)
- func GenerateCommitMessage(ctx context.Context, runtime *shared.RuntimeContext, diff string) (string, error)
- type ChatCompletionRequest
- type ChatMessage
- type ModelVariant
- type Service
- type ServiceBuilder
- func (b *ServiceBuilder) Build() (*Service, error)
- func (b *ServiceBuilder) UseFallbackModel() *ServiceBuilder
- func (b *ServiceBuilder) UseHeavyModel() *ServiceBuilder
- func (b *ServiceBuilder) UseLightModel() *ServiceBuilder
- func (b *ServiceBuilder) WithAPIKey(key string) *ServiceBuilder
- func (b *ServiceBuilder) WithBaseURL(baseURL string) *ServiceBuilder
- func (b *ServiceBuilder) WithHTTPClient(client *http.Client) *ServiceBuilder
- func (b *ServiceBuilder) WithModel(model string) *ServiceBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FixCommitMessage ¶
func FixCommitMessage(ctx context.Context, runtime *shared.RuntimeContext, diff, previousMessage string, validationErr error) (string, error)
FixCommitMessage reparses the diff with guidance about the validation failure and returns a corrected message.
func GenerateCommitMessage ¶
func GenerateCommitMessage(ctx context.Context, runtime *shared.RuntimeContext, diff string) (string, error)
GenerateCommitMessage requests an AI-generated conventional commit message for the supplied diff.
Types ¶
type ChatCompletionRequest ¶
type ChatCompletionRequest struct {
Messages []ChatMessage
Temperature float64
MaxTokens float64
TopP float64
FrequencyPenalty float64
PresencePenalty float64
}
ChatCompletionRequest represents a chat completion call.
type ChatMessage ¶
ChatMessage represents a message in a chat completion request.
type ModelVariant ¶
type ModelVariant int
ModelVariant defines the logical model buckets (light/heavy/fallback) available to commands.
const ( ModelVariantHeavy ModelVariant = iota ModelVariantLight ModelVariantFallback )
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service executes LLM requests using the resolved configuration.
func (*Service) ChatCompletion ¶
ChatCompletion sends a chat completion request and returns the assistant response text.
type ServiceBuilder ¶
type ServiceBuilder struct {
// contains filtered or unexported fields
}
ServiceBuilder lets commands configure which model tier, API key, and endpoint should be used.
func NewServiceBuilder ¶
func NewServiceBuilder(runtime *shared.RuntimeContext) *ServiceBuilder
NewServiceBuilder creates a builder tied to the given runtime context.
func (*ServiceBuilder) Build ¶
func (b *ServiceBuilder) Build() (*Service, error)
Build resolves the requested configuration and returns a ready-to-use LLM service.
func (*ServiceBuilder) UseFallbackModel ¶
func (b *ServiceBuilder) UseFallbackModel() *ServiceBuilder
UseFallbackModel selects the configured fallback model tier.
func (*ServiceBuilder) UseHeavyModel ¶
func (b *ServiceBuilder) UseHeavyModel() *ServiceBuilder
UseHeavyModel selects the heavy model tier (default).
func (*ServiceBuilder) UseLightModel ¶
func (b *ServiceBuilder) UseLightModel() *ServiceBuilder
UseLightModel selects the light model tier configured in the runtime context.
func (*ServiceBuilder) WithAPIKey ¶
func (b *ServiceBuilder) WithAPIKey(key string) *ServiceBuilder
WithAPIKey overrides the API key used for the service.
func (*ServiceBuilder) WithBaseURL ¶
func (b *ServiceBuilder) WithBaseURL(baseURL string) *ServiceBuilder
WithBaseURL overrides the base URL used for the service.
func (*ServiceBuilder) WithHTTPClient ¶
func (b *ServiceBuilder) WithHTTPClient(client *http.Client) *ServiceBuilder
WithHTTPClient overrides the HTTP client (otherwise RuntimeContext HTTP client is reused).
func (*ServiceBuilder) WithModel ¶
func (b *ServiceBuilder) WithModel(model string) *ServiceBuilder
WithModel overrides the model identifier entirely.