Versions in this module Expand all Collapse all v1 v1.2.5 Aug 14, 2024 Changes in this version type MOAConfig + AgentTimeout time.Duration + MaxParallel int v1.2.4 Aug 14, 2024 v1.2.3 Aug 14, 2024 Changes in this version + var QuestionAnswerTemplate = NewPromptTemplate("QuestionAnswer", "Answer the given question", ...) + func AnalyzeComparisonResults[T any](results []ComparisonResult[T]) string + func ChainOfThought(ctx context.Context, l LLM, question string, opts ...PromptOption) (string, error) + func CleanResponse(response string) string + func ExtractStructuredData[T any](ctx context.Context, l LLM, text string, opts ...PromptOption) (*T, error) + func GenerateJSONSchema(v interface{}) ([]byte, error) + func OptimizePrompt(ctx context.Context, llm LLM, config OptimizationConfig) (optimizedPrompt string, response string, err error) + func QuestionAnswer(ctx context.Context, l LLM, question string, opts ...PromptOption) (string, error) + func Summarize(ctx context.Context, l LLM, text string, opts ...PromptOption) (string, error) + func Validate(s interface{}) error + type BatchPromptOptimizer struct + LLM LLM + Verbose bool + func NewBatchPromptOptimizer(llm LLM) *BatchPromptOptimizer + func (bpo *BatchPromptOptimizer) OptimizePrompts(ctx context.Context, examples []PromptExample) []OptimizationResult + type ComparisonResult struct + Attempts int + Data T + Error error + Model string + Provider string + Response string + func CompareModels[T any](ctx context.Context, prompt string, validateFunc ValidateFunc[T], ...) ([]ComparisonResult[T], error) + type Config struct + APIKey string + DebugLevel LogLevel + MaxRetries int + MaxTokens int + MemoryOption *MemoryOption + Model string + OllamaEndpoint string + Provider string + RetryDelay time.Duration + Temperature float64 + Timeout time.Duration + func LoadConfig() (*Config, error) + type ConfigOption func(*Config) + func SetAPIKey(apiKey string) ConfigOption + func SetDebugLevel(level LogLevel) ConfigOption + func SetMaxRetries(maxRetries int) ConfigOption + func SetMaxTokens(maxTokens int) ConfigOption + func SetMemory(maxTokens int) ConfigOption + func SetModel(model string) ConfigOption + func SetOllamaEndpoint(endpoint string) ConfigOption + func SetProvider(provider string) ConfigOption + func SetRetryDelay(retryDelay time.Duration) ConfigOption + func SetTemperature(temperature float64) ConfigOption + func SetTimeout(timeout time.Duration) ConfigOption + type Example struct + Content string + type GenerateOption func(*generateConfig) + func WithJSONSchemaValidation() GenerateOption + type IterationCallback func(iteration int, entry OptimizationEntry) + type LLM interface + Debug func(msg string, keysAndValues ...interface{}) + Generate func(ctx context.Context, prompt *Prompt, opts ...GenerateOption) (string, error) + GetDebugLevel func() LogLevel + GetModel func() string + GetPromptJSONSchema func(opts ...SchemaOption) ([]byte, error) + GetProvider func() string + SetOllamaEndpoint func(endpoint string) error + SetOption func(key string, value interface{}) + UpdateDebugLevel func(level LogLevel) + func NewLLM(opts ...ConfigOption) (LLM, error) + type LogLevel int + const LogLevelDebug + const LogLevelError + const LogLevelInfo + const LogLevelOff + const LogLevelWarn + type MOA struct + Aggregator LLM + Config MOAConfig + Layers []MOALayer + func NewMOA(config MOAConfig, modelConfigs [][]ConfigOption, ...) (*MOA, error) + func (moa *MOA) Generate(ctx context.Context, input string) (string, error) + type MOAConfig struct + Iterations int + Layers int + Models int + type MOALayer struct + Models []LLM + type MemoryOption struct + MaxTokens int + type Metric = llm.Metric + type OptimizationConfig struct + Description string + MaxRetries int + Metrics []Metric + Prompt string + RatingSystem string + RetryDelay time.Duration + Threshold float64 + func DefaultOptimizationConfig() OptimizationConfig + type OptimizationEntry = llm.OptimizationEntry + type OptimizationResult struct + Error error + GeneratedContent string + Name string + OptimizedPrompt string + OriginalPrompt string + type OptimizerOption func(*PromptOptimizer) + func WithCustomMetrics(metrics ...Metric) OptimizerOption + func WithIterationCallback(callback IterationCallback) OptimizerOption + func WithIterations(iterations int) OptimizerOption + func WithMaxRetries(maxRetries int) OptimizerOption + func WithMemorySize(size int) OptimizerOption + func WithOptimizationGoal(goal string) OptimizerOption + func WithRatingSystem(system string) OptimizerOption + func WithRetryDelay(delay time.Duration) OptimizerOption + func WithThreshold(threshold float64) OptimizerOption + func WithVerbose() OptimizerOption + type Prompt struct + Context string + Directives []string + Examples []string + Input string + MaxLength int + Output string + func NewPrompt(input string, opts ...PromptOption) *Prompt + func (p *Prompt) Apply(opts ...PromptOption) + func (p *Prompt) GenerateJSONSchema(opts ...SchemaOption) ([]byte, error) + func (p *Prompt) String() string + func (p *Prompt) Validate() error + type PromptExample struct + Description string + Metrics []Metric + Name string + Prompt string + Threshold float64 + type PromptOptimizer struct + func NewPromptOptimizer(l LLM, initialPrompt string, taskDesc string, opts ...OptimizerOption) *PromptOptimizer + func (po *PromptOptimizer) GetOptimizationHistory() []OptimizationEntry + func (po *PromptOptimizer) OptimizePrompt(ctx context.Context) (string, error) + type PromptOption func(*Prompt) + func WithContext(context string) PromptOption + func WithDirectives(directives ...string) PromptOption + func WithExamples(examples ...string) PromptOption + func WithMaxLength(length int) PromptOption + func WithOutput(output string) PromptOption + type PromptTemplate struct + Description string + Name string + Options []PromptOption + Template string + func NewPromptTemplate(name, description, template string, opts ...PromptTemplateOption) *PromptTemplate + func (pt *PromptTemplate) Execute(data map[string]interface{}) (*Prompt, error) + type PromptTemplateOption func(*PromptTemplate) + func WithPromptOptions(options ...PromptOption) PromptTemplateOption + type SchemaOption func(*jsonschema.Reflector) + func WithExpandedStruct(expanded bool) SchemaOption + type ValidateFunc func(T) error