prompt

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package prompt provides prompt-construction and prompt-optimisation types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeGradientPrompt

func ComputeGradientPrompt(paramName, currentValue, feedback string, examples []string) string

func FormatPromptExamples

func FormatPromptExamples(examples []PromptExample) string

func OptimizePrompt

func OptimizePrompt(ctx context.Context, llm LLMClient, model string, po *PromptOptimizer, paramName, feedback string) (string, error)

Types

type ABTest

type ABTest struct {
	A, B DSPyVariant
}

ABTest pits two prompt variants against each other on incoming traffic.

func NewABTest

func NewABTest(a, b DSPyVariant) *ABTest

NewABTest builds an A/B test between two variants.

type DSPyExample

type DSPyExample = PromptExample

DSPyExample is one (input, output) demonstration backing the optimizer.

type DSPyVariant

type DSPyVariant = PromptVariant

DSPyVariant is a candidate prompt being evaluated.

type LLMClient

type LLMClient interface {
	Chat(ctx context.Context, msgs []types.EyrieMessage, opts types.ChatOptions) (*types.EyrieResponse, error)
}

LLMClient is the minimal interface needed for prompt optimization.

type OptimizationStep

type OptimizationStep struct {
	Timestamp time.Time      `json:"timestamp"`
	Parameter string         `json:"parameter"`
	OldValue  string         `json:"old_value"`
	NewValue  string         `json:"new_value"`
	OldScore  float64        `json:"old_score"`
	NewScore  float64        `json:"new_score"`
	Gradient  PromptGradient `json:"gradient"`
}

type Optimizer

type Optimizer = PromptOptimizer

Optimizer learns better prompts via DSPy-style example mining.

func NewOptimizer

func NewOptimizer() *Optimizer

NewOptimizer returns a fresh prompt optimizer.

type PromptExample

type PromptExample struct {
	Input    string  `json:"input"`
	Output   string  `json:"output"`
	Score    float64 `json:"score"`
	Category string  `json:"category"`
}

type PromptFewShotSelector

type PromptFewShotSelector struct {
	Examples []PromptExample
}

func (*PromptFewShotSelector) Select

func (fs *PromptFewShotSelector) Select(query string, k int) []PromptExample

type PromptGradient

type PromptGradient struct {
	Parameter string  `json:"parameter"`
	Feedback  string  `json:"feedback"`
	Direction string  `json:"direction"`
	Magnitude float64 `json:"magnitude"`
}

type PromptOptimizer

type PromptOptimizer struct {
	Parameters map[string]*PromptParameter
	History    []OptimizationStep
	Path       string
}

func NewPromptOptimizer

func NewPromptOptimizer() *PromptOptimizer

func (*PromptOptimizer) ApplyGradient

func (po *PromptOptimizer) ApplyGradient(paramName, newValue string, gradient PromptGradient)

func (*PromptOptimizer) Get

func (po *PromptOptimizer) Get(name string) string

func (*PromptOptimizer) NeedsOptimization

func (po *PromptOptimizer) NeedsOptimization(threshold float64) []*PromptParameter

func (*PromptOptimizer) RecordFailure

func (po *PromptOptimizer) RecordFailure(paramName, feedback string)

func (*PromptOptimizer) RecordSuccess

func (po *PromptOptimizer) RecordSuccess(paramName string)

func (*PromptOptimizer) Register

func (po *PromptOptimizer) Register(name, initialValue string)

type PromptParameter

type PromptParameter struct {
	Name    string  `json:"name"`
	Value   string  `json:"value"`
	Score   float64 `json:"score"`
	Version int     `json:"version"`
}

type PromptTuner

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

func NewPromptTuner

func NewPromptTuner() *PromptTuner

func (*PromptTuner) BestVariant

func (pt *PromptTuner) BestVariant(section string) (string, float64)

func (*PromptTuner) RecordOutcome

func (pt *PromptTuner) RecordOutcome(section, content string, success bool)

func (*PromptTuner) Report

func (pt *PromptTuner) Report() string

type PromptVariant

type PromptVariant struct {
	Section   string    `json:"section"`
	Content   string    `json:"content"`
	Score     float64   `json:"score"`
	Uses      int       `json:"uses"`
	Successes int       `json:"successes"`
	LastUsed  time.Time `json:"last_used"`
}

type Tuner

type Tuner = PromptTuner

Tuner is a lighter-weight prompt-tuning helper for online adjustments.

func NewTuner

func NewTuner() *Tuner

NewTuner returns a fresh prompt tuner.

type Variant

type Variant = PromptVariant

Variant is a tuned prompt the Tuner emits.

Jump to

Keyboard shortcuts

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