Documentation
¶
Index ¶
- Variables
- type BootstrapFewShot
- type Copro
- type InstructionGenerator
- type MIPRO
- type MIPROConfig
- type MIPROMetrics
- type MIPROOption
- func WithMaxLabeledDemos(maxDemos int) MIPROOption
- func WithMiniBatchSize(size int) MIPROOption
- func WithMode(mode RunMode) MIPROOption
- func WithModels(promptModel, taskModel core.LLM) MIPROOption
- func WithNumCandidates(num int) MIPROOption
- func WithNumModules(numModules int) MIPROOption
- func WithNumTrials(trials int) MIPROOption
- func WithRandomSeed(seed int64) MIPROOption
- func WithSearchStrategy(strategy SearchStrategy) MIPROOption
- func WithTPEGamma(gamma float64) MIPROOption
- func WithTPEGenerations(generations int) MIPROOption
- func WithTeacherSettings(settings map[string]interface{}) MIPROOption
- type OptimizationState
- type OptimizationStep
- type PromptComponent
- type PromptVersion
- type RunMode
- type SearchConfig
- type SearchStrategy
- type TPEConfig
- type TPEOptimizer
- func (t *TPEOptimizer) GetBestParams() (map[string]interface{}, float64)
- func (t *TPEOptimizer) Initialize(config SearchConfig) error
- func (t *TPEOptimizer) SuggestParams(ctx context.Context) (map[string]interface{}, error)
- func (t *TPEOptimizer) UpdateResults(params map[string]interface{}, score float64) error
- type TeacherStudentOptimizer
Constants ¶
This section is empty.
Variables ¶
var AutoRunSettings = map[RunMode]struct { NumTrials int ValSize int }{ LightMode: {NumTrials: 7, ValSize: 100}, MediumMode: {NumTrials: 25, ValSize: 300}, HeavyMode: {NumTrials: 50, ValSize: 1000}, }
AutoRunSettings defines default configurations for different run modes.
Functions ¶
This section is empty.
Types ¶
type BootstrapFewShot ¶
type BootstrapFewShot struct {
Metric func(example map[string]interface{}, prediction map[string]interface{}, ctx context.Context) bool
MaxBootstrapped int
}
func NewBootstrapFewShot ¶
type Copro ¶ added in v0.1.0
type Copro struct {
Metric func(example, prediction map[string]interface{}, ctx context.Context) bool
MaxBootstrapped int
SubOptimizer core.Optimizer
}
type InstructionGenerator ¶ added in v0.28.0
InstructionGenerator handles the generation of instruction candidates.
type MIPRO ¶ added in v0.1.0
type MIPRO struct {
// contains filtered or unexported fields
}
MIPRO is the main optimizer implementing multi-step interactive prompt optimization.
type MIPROConfig ¶ added in v0.28.0
type MIPROConfig struct {
Mode RunMode
NumTrials int
ValSize int
MiniBatchSize int
AdaptiveParams bool
ScalingFactors struct {
TrialsPerVariable float64
BatchSizeScaling float64
}
TeacherSettings map[string]interface{}
// TPE specific configuration
TPEGamma float64
TPEGenerations int
Seed int64
NumModules int // Number of modules to optimize (can be inferred from program)
MaxLabeledDemos int // Maximum number of labeled demonstrations to use
}
MIPROConfig contains all configuration options for the optimizer.
type MIPROMetrics ¶ added in v0.28.0
type MIPROMetrics struct {
TeacherPerformance float64
StudentPerformance float64
PromptEffectiveness map[string]float64
OptimizationHistory []OptimizationStep
TokenUsage *core.TokenInfo
}
MIPROMetrics tracks comprehensive optimization metrics.
type MIPROOption ¶ added in v0.1.0
type MIPROOption func(*MIPRO)
MIPROOption defines a function type for configuring MIPRO.
func WithMaxLabeledDemos ¶ added in v0.1.0
func WithMaxLabeledDemos(maxDemos int) MIPROOption
WithMaxLabeledDemos sets the maximum number of labeled demos to use.
func WithMiniBatchSize ¶ added in v0.1.0
func WithMiniBatchSize(size int) MIPROOption
func WithMode ¶ added in v0.28.0
func WithMode(mode RunMode) MIPROOption
WithMode sets the optimization mode.
func WithModels ¶ added in v0.28.0
func WithModels(promptModel, taskModel core.LLM) MIPROOption
WithModels explicitly sets the prompt and task models for MIPRO.
func WithNumCandidates ¶ added in v0.1.0
func WithNumCandidates(num int) MIPROOption
func WithNumModules ¶ added in v0.28.0
func WithNumModules(numModules int) MIPROOption
WithNumModules explicitly sets the number of modules to optimize.
func WithNumTrials ¶ added in v0.1.0
func WithNumTrials(trials int) MIPROOption
WithNumTrials sets the number of optimization trials.
func WithRandomSeed ¶ added in v0.28.0
func WithRandomSeed(seed int64) MIPROOption
WithRandomSeed sets a specific random seed for reproducibility.
func WithSearchStrategy ¶ added in v0.28.0
func WithSearchStrategy(strategy SearchStrategy) MIPROOption
WithSearchStrategy sets a custom search strategy.
func WithTPEGamma ¶ added in v0.28.0
func WithTPEGamma(gamma float64) MIPROOption
WithTPEGamma sets the gamma parameter for the TPE optimizer.
func WithTPEGenerations ¶ added in v0.28.0
func WithTPEGenerations(generations int) MIPROOption
WithTPEGenerations sets the number of candidates to generate for each TPE optimization step.
func WithTeacherSettings ¶ added in v0.28.0
func WithTeacherSettings(settings map[string]interface{}) MIPROOption
WithTeacherSettings configures the teacher model settings.
type OptimizationState ¶ added in v0.28.0
type OptimizationState struct {
SuccessfulPatterns []string
PromptEvolution []PromptVersion
TeacherScores map[string]float64
CurrentIteration int
BestScore float64
Convergence float64
}
OptimizationState tracks the progress of optimization.
type OptimizationStep ¶ added in v0.28.0
type OptimizationStep struct {
Trial int
Performance float64
Improvements []string
FailurePoints []string
}
OptimizationStep represents a single step in the optimization process.
type PromptComponent ¶ added in v0.28.0
PromptComponent represents a specific part of a prompt.
type PromptVersion ¶ added in v0.28.0
type PromptVersion struct {
Template string
Performance float64
Components []PromptComponent
}
PromptVersion represents a specific version of a prompt template.
type RunMode ¶ added in v0.28.0
type RunMode string
RunMode defines different optimization intensities for MIPRO.
type SearchConfig ¶ added in v0.28.0
type SearchConfig struct {
ParamSpace map[string][]interface{}
MaxTrials int
Seed int64
Constraints map[string]interface{}
}
SearchConfig contains configuration for search strategies.
type SearchStrategy ¶ added in v0.28.0
type SearchStrategy interface {
SuggestParams(ctx context.Context) (map[string]interface{}, error)
UpdateResults(params map[string]interface{}, score float64) error
GetBestParams() (map[string]interface{}, float64)
Initialize(config SearchConfig) error
}
SearchStrategy defines the interface for optimization search algorithms.
func NewTPEOptimizer ¶ added in v0.28.0
func NewTPEOptimizer(config TPEConfig) SearchStrategy
NewTPEOptimizer creates a new TPE optimizer instance.
type TPEConfig ¶ added in v0.28.0
type TPEConfig struct {
// Gamma is the percentile split between good and bad observations (default: 0.25)
Gamma float64
// Seed is used for random number generation
Seed int64
// NumEIGenerations is the number of random points to evaluate EI on
NumEIGenerations int
// Prior distributions for each parameter (optional)
PriorWeight float64
// Kernel bandwidth factor
BandwidthFactor float64
}
TPEConfig contains configuration for Tree-structured Parzen Estimators.
type TPEOptimizer ¶ added in v0.28.0
type TPEOptimizer struct {
// contains filtered or unexported fields
}
TPEOptimizer implements the Tree-structured Parzen Estimator for Bayesian optimization.
func (*TPEOptimizer) GetBestParams ¶ added in v0.28.0
func (t *TPEOptimizer) GetBestParams() (map[string]interface{}, float64)
GetBestParams returns the best parameters found so far and their score.
func (*TPEOptimizer) Initialize ¶ added in v0.28.0
func (t *TPEOptimizer) Initialize(config SearchConfig) error
Initialize sets up the search space and constraints.
func (*TPEOptimizer) SuggestParams ¶ added in v0.28.0
func (t *TPEOptimizer) SuggestParams(ctx context.Context) (map[string]interface{}, error)
SuggestParams suggests the next set of parameters to try.
func (*TPEOptimizer) UpdateResults ¶ added in v0.28.0
func (t *TPEOptimizer) UpdateResults(params map[string]interface{}, score float64) error
UpdateResults updates the internal state with the results of the last trial.
type TeacherStudentOptimizer ¶ added in v0.28.0
type TeacherStudentOptimizer struct {
Teacher core.LLM
Student core.LLM
TeacherSettings map[string]interface{}
MaxExamples int
// contains filtered or unexported fields
}
TeacherStudentOptimizer handles the teacher-student learning dynamic.
func (*TeacherStudentOptimizer) GenerateDemonstration ¶ added in v0.28.0
func (t *TeacherStudentOptimizer) GenerateDemonstration(ctx context.Context, input core.Example) (core.Example, error)
GenerateDemonstration creates a high-quality demonstration using the teacher.
func (*TeacherStudentOptimizer) Initialize ¶ added in v0.28.0
func (t *TeacherStudentOptimizer) Initialize(ctx context.Context, program core.Program, dataset core.Dataset) error
Initialize sets up the teacher-student optimization.