optimizer

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccuracyMatch

func AccuracyMatch(output, expected any) float64

AccuracyMatch checks if outputs exactly match

func EM

func EM(prediction string, answersList []string) float64

EM calculates the exact match score between the prediction and the list of answers.

func F1

func F1(prediction string, answersList []string) float64

F1 calculates the F1 score between the prediction and the list of answers.

func F1Score

func F1Score(output, expected interface{}) float64

F1Score calculates F1 score for classification tasks

func HotPotF1

func HotPotF1(prediction string, answersList []string) float64

HotPotF1 calculates the HotPot F1 score between the prediction and the list of answers.

func NewSemanticF1

func NewSemanticF1(ctx context.Context) *semanticF1

NewSemanticF1 ...

func StringSimilarity

func StringSimilarity(output, expected any) float64

StringSimilarity calculates string similarity using Levenshtein distance

Types

type Candidate

type Candidate struct {
	Program     program.Program
	Score       float64
	Instruction string
	Prefix      string
	Depth       int
}

Candidate represents a candidate for optimization.

type CoproOptimizer

type CoproOptimizer struct {
	Breadth         int
	Depth           int
	InitTemperature float64
	TrackStats      bool
	// contains filtered or unexported fields
}

CoproOptimizer represents the teleprompter for optimizing signatures.

func NewCoproOptimizer

func NewCoproOptimizer(breadth, depth int, metric Metric) *CoproOptimizer

NewCoproOptimizer creates a new CoproOptimizer.

func (*CoproOptimizer) Optimize

func (co *CoproOptimizer) Optimize(ctx context.Context, student program.Program, trainset []*Example) program.Program

Optimize optimizes the program.

type CritiqueNOptimizer

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

CritiqueNOptimizer defines the CritiqueN optimizer

func NewCritiqueNOptimizer

func NewCritiqueNOptimizer(opts ...Option) *CritiqueNOptimizer

NewCritiqueNOptimizer ...

func (*CritiqueNOptimizer) Optimize

func (o *CritiqueNOptimizer) Optimize(ctx context.Context, target any, trainset []*Example) (*program.Program, error)

Optimize ...

type Evaluator

type Evaluator struct {
	Program    string // prompt or agent
	Parameters map[string]interface{}
	// contains filtered or unexported fields
}

Evaluator ...

func NewEvaluator

func NewEvaluator(concurrentNum int, trainset []*Example, metric Metric) *Evaluator

NewEvaluator ...

func (*Evaluator) Score

func (e *Evaluator) Score(ctx context.Context, program any) float64

Score ...

type Example

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

Example ...

func Examplex

func Examplex(pairs ...any) *Example

Examplex ...

func (*Example) Get

func (ex *Example) Get(key string) any

Get ...

func (*Example) Inputs

func (ex *Example) Inputs(keys ...string) map[string]any

Inputs ...

func (*Example) Set

func (ex *Example) Set(pairs ...string)

Set ...

func (*Example) WithInputKeys

func (ex *Example) WithInputKeys(keys ...string) *Example

WithInputKeys ...

type Metric

type Metric func(*Example, any) float64

Metric ...

func SemanticF1

func SemanticF1() Metric

SemanticF1 ...

type OptimizeOption

type OptimizeOption func(options *OptimizeOptions)

OptimizeOption ...

func WithDescription

func WithDescription(desc string) OptimizeOption

WithDescription ...

func WithInitialInstruction

func WithInitialInstruction(instruction string) OptimizeOption

WithInitialInstruction ...

func WithOutputs

func WithOutputs(out string) OptimizeOption

WithOutputs ...

type OptimizeOptions

type OptimizeOptions struct {
	InitialInstruction string
	Description        string
	Inputs             string
	Outputs            string
}

OptimizeOptions ...

func NewOptimizeOptions

func NewOptimizeOptions() *OptimizeOptions

NewOptimizeOptions ...

type OptimizeResult

type OptimizeResult struct {
	BestProgram    program.Program
	BestScore      float64
	History        []*OptimizeStep
	BestParameters map[string]interface{}
}

OptimizeResult contains the results of optimization

type OptimizeStep

type OptimizeStep struct {
	Program    program.Program
	Score      float64
	Parameters map[string]interface{}
	Timestamp  int64
}

OptimizeStep represents a single optimization step

type Optimizer

type Optimizer interface {
	// Optimize performs optimization and returns the best result
	Optimize(context.Context, any, ...OptimizeOption) (*OptimizeResult, error)
}

Optimizer defines the interface for optimization

type Option

type Option func(options *Options)

Option ...

func WithLLM

func WithLLM(llm *llm.Instance, model string) Option

WithLLM ...

func WithMetric

func WithMetric(metric Metric) Option

WithMetric ...

func WithTrainset

func WithTrainset(exs []*Example) Option

WithTrainset ...

type Options

type Options struct {
	LLM      *llm.Instance
	LLMModel string
	// contains filtered or unexported fields
}

Options ...

func NewOptions

func NewOptions(opts ...Option) *Options

NewOptions ...

type Strategy

type Strategy interface {
	Mutate(p *prompt.Prompt) *prompt.Prompt
}

type TemplateModifier

type TemplateModifier struct {
}

Example mutation strategy

func (*TemplateModifier) Mutate

func (tm *TemplateModifier) Mutate(p *prompt.Prompt) *prompt.Prompt

Jump to

Keyboard shortcuts

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