llm

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2025 License: BSD-2-Clause Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	CommitSchema = &openai.ChatCompletionNewParamsResponseFormatUnion{
		OfJSONSchema: &openaiShared.ResponseFormatJSONSchemaParam{
			JSONSchema: openaiShared.ResponseFormatJSONSchemaJSONSchemaParam{
				Name:        "commit_message",
				Description: openai.String("A conventional commit message"),
				Schema: interface{}(map[string]interface{}{
					"type": "object",
					"properties": map[string]interface{}{
						"type":        map[string]interface{}{"type": "string", "enum": []string{"feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"}},
						"scope":       map[string]interface{}{"type": "string"},
						"gitmoji":     map[string]interface{}{"type": "string"},
						"description": map[string]interface{}{"type": "string"},
					},
					"required":             []string{"type", "scope", "gitmoji", "description"},
					"additionalProperties": false,
				}),
				Strict: openai.Bool(true),
			},
		},
	}
)

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
	ResponseFormat   *openai.ChatCompletionNewParamsResponseFormatUnion
}

ChatCompletionRequest represents a chat completion call.

type ChatMessage

type ChatMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

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

func (s *Service) ChatCompletion(ctx context.Context, req ChatCompletionRequest) (string, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL