llm

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package llm provides LLM integration for the Guardian CLI tool. It supports multiple LLM providers (DeepSeek, OpenAI, Claude, Custom) and handles API communication, prompt management, and interactive configuration.

Index

Constants

View Source
const (
	ProviderDeepSeek = "deepseek"
	ProviderOpenAI   = "openai"
	ProviderClaude   = "claude"
	ProviderCustom   = "custom"
)

Provider constants identify supported LLM providers.

View Source
const DefaultCheckSystemPrompt = `` /* 1095-byte string literal not displayed */

DefaultCheckSystemPrompt is the built-in system prompt used by guardian check to analyze git diffs against team rules and provide violation explanations.

View Source
const DefaultProposeSystemPrompt = `` /* 280-byte string literal not displayed */

DefaultProposeSystemPrompt is the built-in system prompt used by guardian propose to generate draft proposal text for rule changes.

Variables

View Source
var DefaultModels = map[string]string{
	ProviderDeepSeek: "deepseek-chat",
	ProviderOpenAI:   "gpt-4o",
	ProviderClaude:   "claude-sonnet-4-5-20250929",
}

DefaultModels maps known providers to default model names.

View Source
var ProviderEndpoints = map[string]string{
	ProviderDeepSeek: "https://api.deepseek.com/v1",
	ProviderOpenAI:   "https://api.openai.com/v1",
	ProviderClaude:   "https://api.anthropic.com/v1",
}

ProviderEndpoints maps known providers to their API endpoints.

Functions

func GetCheckPrompt

func GetCheckPrompt(override string) string

GetCheckPrompt returns the check system prompt. If override is non-empty, it is used instead of the built-in default prompt.

func GetProposePrompt

func GetProposePrompt(override string) string

GetProposePrompt returns the propose system prompt. If override is non-empty, it is used instead of the built-in default prompt.

func IsCloudProvider

func IsCloudProvider(provider string) bool

IsCloudProvider returns true for non-local providers that send data to external APIs (deepseek, openai, claude).

func RunConfigure

func RunConfigure(r io.Reader, w io.Writer) (*config.LLMConfig, error)

RunConfigure runs the interactive LLM configuration flow. It reads from r and writes prompts/output to w. Returns the updated LLMConfig based on user selections.

func ValidProviders

func ValidProviders() []string

ValidProviders returns the list of all valid provider names.

Types

type CheckAnalysis

type CheckAnalysis struct {
	Explanations map[string]string // rule_id -> explanation
}

CheckAnalysis represents the LLM response for a check analysis.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the LLM client that communicates with a configured provider.

func NewClient

func NewClient(cfg config.LLMConfig) (*Client, error)

NewClient creates a new LLM client from constitution config. It reads the API key from the GUARDIAN_LLM_API_KEY environment variable. Returns an error if the API key is not set.

func (*Client) AnalyzeCheck

func (c *Client) AnalyzeCheck(diffContent string, rules []config.Rule, violations []Violation, proposals []*config.Proposal) (*CheckAnalysis, error)

AnalyzeCheck sends diff content and violations to the LLM for analysis. It returns explanations keyed by rule ID. If proposals is non-nil, governance context is included in the prompt.

func (*Client) DraftProposal

func (c *Client) DraftProposal(rule config.Rule, context string) (*ProposalDraft, error)

DraftProposal generates a proposal draft using the LLM.

type ProposalDraft

type ProposalDraft struct {
	ChangeDescription string
	ChangeDetails     string
	Reason            string
	Impact            string
}

ProposalDraft represents a draft proposal generated by the LLM.

type Violation

type Violation struct {
	RuleID      string
	Severity    string
	Description string
	FilePath    string
	DiffSnippet string
}

Violation represents a rule violation found by the engine. It is defined here to avoid circular imports with the engine package.

Jump to

Keyboard shortcuts

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