llm

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCompletion

func CreateCompletion(ctx context.Context, client *Client, prompt string, options *CreateOptions) (string, error)

CreateCompletion creates a simple text completion

func CreateList

func CreateList[T any](ctx context.Context, client *Client, prompt string, options *CreateOptions) ([]*T, error)

CreateList creates a list of structured responses of type T with automatic validation retry

func CreateStructured

func CreateStructured[T any](ctx context.Context, client *Client, prompt string, options *CreateOptions) (*T, error)

CreateStructured creates a structured response of type T with automatic validation retry

Types

type Client

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

Client provides high-level LLM operations with validation

func NewClient

func NewClient(prov provider.Provider, config ClientConfig) *Client

NewClient creates a new LLM client

func NewClientWithProvider

func NewClientWithProvider(providerName string, config ClientConfig) (*Client, error)

Helper function to create a client with a provider name

type ClientConfig

type ClientConfig struct {
	// DefaultModel to use if not specified in requests
	DefaultModel string

	// DefaultTemperature to use if not specified
	DefaultTemperature float64

	// MaxRetries for validation failures (default: 3, set to 1 to disable retry)
	MaxRetries int

	// DisableValidationRetry disables automatic retry on validation failures
	// When true, validation errors will fail immediately without retry
	DisableValidationRetry bool

	// StrictValidation enables strict mode (no type coercion)
	StrictValidation bool
}

ClientConfig configures the LLM client

type CreateOptions

type CreateOptions struct {
	// Model to use (overrides default)
	Model string

	// Temperature (overrides default)
	Temperature float64

	// MaxTokens limits response length
	MaxTokens int

	// SystemPrompt sets the system message
	SystemPrompt string

	// Schema is the JSON Schema for the response (optional - will be generated from type if not provided)
	Schema json.RawMessage

	// ValidationMode can be "strict" or "lax"
	ValidationMode string
}

CreateOptions contains options for creation requests

type Validator

type Validator struct{ Schema map[string]any }

func NewValidator

func NewValidator(schema map[string]any) *Validator

func (*Validator) Validate

func (v *Validator) Validate(input map[string]any) error

Directories

Path Synopsis
runtime

Jump to

Keyboard shortcuts

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