Documentation
¶
Index ¶
- Variables
- 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{}, opts ...SchemaOption) ([]byte, 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 ComparisonResult
- type Config
- type ConfigOption
- func SetAPIKey(apiKey string) ConfigOption
- func SetDebugLevel(level LogLevel) ConfigOption
- func SetMaxRetries(maxRetries int) ConfigOption
- func SetMaxTokens(maxTokens int) ConfigOption
- func SetModel(model 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
- type GenerateOption
- type LLM
- type LogLevel
- type Prompt
- type PromptOption
- type PromptTemplate
- type PromptTemplateOption
- type SchemaOption
- type ValidateFunc
Constants ¶
This section is empty.
Variables ¶
var QuestionAnswerTemplate = NewPromptTemplate( "QuestionAnswer", "Answer the given question", "Answer the following question:\n\n{{.Question}}", WithPromptOptions( WithDirectives("Provide a clear and concise answer"), WithOutput("Answer:"), ), )
Functions ¶
func AnalyzeComparisonResults ¶ added in v0.0.4
func AnalyzeComparisonResults[T any](results []ComparisonResult[T]) string
func ChainOfThought ¶
func ChainOfThought(ctx context.Context, l LLM, question string, opts ...PromptOption) (string, error)
ChainOfThought performs a chain of thought reasoning
func CleanResponse ¶ added in v0.0.4
CleanResponse removes markdown code block syntax and trims the JSON response
func ExtractStructuredData ¶ added in v0.0.5
func ExtractStructuredData[T any](ctx context.Context, l LLM, text string, opts ...PromptOption) (*T, error)
ExtractStructuredData extracts structured data from text based on a given struct type
func GenerateJSONSchema ¶ added in v0.0.4
func GenerateJSONSchema(v interface{}, opts ...SchemaOption) ([]byte, error)
GenerateJSONSchema returns the JSON Schema for the given struct
func QuestionAnswer ¶
func QuestionAnswer(ctx context.Context, l LLM, question string, opts ...PromptOption) (string, error)
QuestionAnswer performs question answering
Types ¶
type ComparisonResult ¶ added in v0.0.4
type ComparisonResult[T any] struct { Provider string Model string Response string Data T Error error Attempts int }
func CompareModels ¶ added in v0.0.4
func CompareModels[T any](ctx context.Context, prompt string, validateFunc ValidateFunc[T], configs ...*Config) ([]ComparisonResult[T], error)
CompareModels now uses a generic type T and accepts a validation function
type Config ¶ added in v0.0.4
type Config struct {
Provider string
Model string
Temperature float64
MaxTokens int
Timeout time.Duration
MaxRetries int
RetryDelay time.Duration
APIKey string
DebugLevel LogLevel
}
Config holds the configuration for the LLM
func LoadConfig ¶ added in v0.0.4
LoadConfig loads the configuration from environment variables
type ConfigOption ¶ added in v0.0.3
type ConfigOption func(*Config)
ConfigOption is a function type for modifying Config
func SetAPIKey ¶ added in v0.0.3
func SetAPIKey(apiKey string) ConfigOption
SetAPIKey sets the API key for the current provider in the Config
func SetDebugLevel ¶ added in v0.0.4
func SetDebugLevel(level LogLevel) ConfigOption
SetDebugLevel sets the debug level in the Config
func SetMaxRetries ¶ added in v0.0.4
func SetMaxRetries(maxRetries int) ConfigOption
SetMaxRetries sets the maximum number of retries in the Config
func SetMaxTokens ¶ added in v0.0.3
func SetMaxTokens(maxTokens int) ConfigOption
SetMaxTokens sets the max tokens in the Config
func SetModel ¶ added in v0.0.3
func SetModel(model string) ConfigOption
SetModel sets the model in the Config
func SetProvider ¶ added in v0.0.3
func SetProvider(provider string) ConfigOption
SetProvider sets the provider in the Config
func SetRetryDelay ¶ added in v0.0.4
func SetRetryDelay(retryDelay time.Duration) ConfigOption
SetRetryDelay sets the delay between retries in the Config
func SetTemperature ¶ added in v0.0.3
func SetTemperature(temperature float64) ConfigOption
SetTemperature sets the temperature in the Config
func SetTimeout ¶ added in v0.0.3
func SetTimeout(timeout time.Duration) ConfigOption
SetTimeout sets the timeout in the Config
type GenerateOption ¶ added in v0.0.4
type GenerateOption func(*generateConfig)
GenerateOption is a function type for configuring generate options
func WithJSONSchemaValidation ¶ added in v0.0.4
func WithJSONSchemaValidation() GenerateOption
WithJSONSchemaValidation returns a GenerateOption that enables JSON schema validation
type LLM ¶
type LLM interface {
// Generate produces a response given a context, prompt, and optional generate options
Generate(ctx context.Context, prompt *Prompt, opts ...GenerateOption) (string, error)
// SetOption sets an option for the LLM
SetOption(key string, value interface{})
// GetPromptJSONSchema returns the JSON schema for the prompt
GetPromptJSONSchema(opts ...SchemaOption) ([]byte, error)
// GetProvider returns the provider of the LLM
GetProvider() string
// GetModel returns the model of the LLM
GetModel() string
// UpdateDebugLevel updates the debug level of the LLM
UpdateDebugLevel(level LogLevel)
// Debug logs a debug message with optional key-value pairs
Debug(msg string, keysAndValues ...interface{})
// GetDebugLevel returns the current debug level of the LLM
GetDebugLevel() LogLevel
}
LLM is the interface that wraps the basic LLM operations
type Prompt ¶
type Prompt struct {
Input string `json:"input" jsonschema:"required,description=The main input text for the LLM" validate:"required"`
Output string `json:"output,omitempty" jsonschema:"description=Specification for the expected output format"`
Directives []string `json:"directives,omitempty" jsonschema:"description=List of directives to guide the LLM"`
Context string `json:"context,omitempty" jsonschema:"description=Additional context for the LLM"`
MaxLength int `` /* 128-byte string literal not displayed */
Examples []string `json:"examples,omitempty" jsonschema:"description=List of examples to guide the LLM"`
}
Prompt represents a structured prompt for an LLM
func NewPrompt ¶
func NewPrompt(input string, opts ...PromptOption) *Prompt
NewPrompt creates a new Prompt with the given input and applies any provided options
func (*Prompt) Apply ¶ added in v0.0.3
func (p *Prompt) Apply(opts ...PromptOption)
Apply applies the given options to the Prompt
func (*Prompt) GenerateJSONSchema ¶ added in v0.0.4
func (p *Prompt) GenerateJSONSchema(opts ...SchemaOption) ([]byte, error)
GenerateJSONSchema returns the JSON Schema for the Prompt struct
type PromptOption ¶ added in v0.0.3
type PromptOption func(*Prompt)
PromptOption is a function type that modifies a Prompt
func WithContext ¶ added in v0.0.3
func WithContext(context string) PromptOption
WithContext adds context to the Prompt
func WithDirectives ¶ added in v0.0.3
func WithDirectives(directives ...string) PromptOption
WithDirectives adds directives to the Prompt
func WithExamples ¶ added in v0.0.3
func WithExamples(examples ...string) PromptOption
WithExamples adds examples to the Prompt
func WithMaxLength ¶ added in v0.0.3
func WithMaxLength(length int) PromptOption
WithMaxLength sets the maximum length for the output
func WithOutput ¶ added in v0.0.3
func WithOutput(output string) PromptOption
WithOutput adds an output specification to the Prompt
type PromptTemplate ¶ added in v0.0.3
type PromptTemplate struct {
Name string
Description string
Template string
Options []PromptOption
}
PromptTemplate represents a template for generating prompts
func NewPromptTemplate ¶ added in v0.0.3
func NewPromptTemplate(name, description, template string, opts ...PromptTemplateOption) *PromptTemplate
NewPromptTemplate creates a new PromptTemplate with the given name, description, and template
type PromptTemplateOption ¶ added in v0.0.3
type PromptTemplateOption func(*PromptTemplate)
PromptTemplateOption is a function type that modifies a PromptTemplate
func WithPromptOptions ¶ added in v0.0.3
func WithPromptOptions(options ...PromptOption) PromptTemplateOption
WithPromptOptions adds PromptOptions to the PromptTemplate
type SchemaOption ¶ added in v0.0.4
type SchemaOption func(*jsonschema.Reflector)
SchemaOption is a function type for schema generation options
func WithExpandedStruct ¶ added in v0.0.4
func WithExpandedStruct(expanded bool) SchemaOption
WithExpandedStruct sets the ExpandedStruct option for schema generation
type ValidateFunc ¶ added in v0.0.4
ValidateFunc is a function type for custom validation logic