Documentation
¶
Index ¶
- func RemoveSurroundingMarkdown(content string) string
- func RenderTemplateString(tpl string, data map[string]string) (string, error)
- func SaveInteractionsToFile(interactions []Interaction, filename string) error
- type Attr
- type CaptureConfig
- type CaptureMiddleware
- func (c *CaptureMiddleware) CountTokens(ctx context.Context, p Prompt, debug bool, args ...string) (*TokenCount, error)
- func (c *CaptureMiddleware) CountTokensAttr(ctx context.Context, p Prompt, debug bool, attrs []Attr) (*TokenCount, error)
- func (c *CaptureMiddleware) GenerateContent(ctx context.Context, prompt Prompt, debug bool, args ...string) (string, error)
- func (c *CaptureMiddleware) GenerateContentAttr(ctx context.Context, prompt Prompt, debug bool, attrs []Attr) (string, error)
- func (c *CaptureMiddleware) GetCapture() *InteractionCapture
- func (c *CaptureMiddleware) GetCapturedInteractions() []Interaction
- func (c *CaptureMiddleware) GetLastInteraction() *Interaction
- func (c *CaptureMiddleware) GetStatus() *Status
- func (c *CaptureMiddleware) LoadCapture(filename string) error
- func (c *CaptureMiddleware) PrintCaptureSummary()
- func (c *CaptureMiddleware) SaveCapture(filename string) error
- type CapturedAttr
- type CapturedError
- type CapturedFunction
- type CapturedPrompt
- type FunctionDeclaration
- type FunctionResponse
- type Gen
- type HandlerFunc
- type Image
- type Interaction
- type InteractionCapture
- func (ic *InteractionCapture) Clear()
- func (ic *InteractionCapture) CompleteInteraction(interaction *Interaction, response string, err error, duration time.Duration)
- func (ic *InteractionCapture) GetInteractionByID(id string) *Interaction
- func (ic *InteractionCapture) GetInteractions() []Interaction
- func (ic *InteractionCapture) GetLastInteraction() *Interaction
- func (ic *InteractionCapture) GetSummary() string
- func (ic *InteractionCapture) LoadFromFile(filename string) error
- func (ic *InteractionCapture) SaveToFile(filename string) error
- func (ic *InteractionCapture) SetOutputFile(filename string)
- func (ic *InteractionCapture) StartInteraction(prompt Prompt, args []string) *Interaction
- type MockGen
- func (m *MockGen) CountTokens(ctx context.Context, p Prompt, debug bool, args ...string) (*TokenCount, error)
- func (m *MockGen) GenerateContent(ctx context.Context, prompt Prompt, debug bool, args ...string) (string, error)
- func (m *MockGen) GenerateContentAttr(ctx context.Context, prompt Prompt, debug bool, attrs []Attr) (string, error)
- func (m *MockGen) GetStatus() *Status
- type Prompt
- type RetryConfig
- type RetryMiddleware
- func (r *RetryMiddleware) CountTokens(ctx context.Context, p Prompt, debug bool, args ...string) (*TokenCount, error)
- func (r *RetryMiddleware) CountTokensAttr(ctx context.Context, p Prompt, debug bool, attrs []Attr) (*TokenCount, error)
- func (r *RetryMiddleware) GenerateContent(ctx context.Context, p Prompt, debug bool, args ...string) (string, error)
- func (r *RetryMiddleware) GenerateContentAttr(ctx context.Context, p Prompt, debug bool, attrs []Attr) (string, error)
- func (r *RetryMiddleware) GetStatus() *Status
- type Schema
- type Status
- type TokenCount
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RemoveSurroundingMarkdown ¶
RemoveSurroundingMarkdown removes first and last lines if they start with ``` and removes empty lines at the beginning and end
func RenderTemplateString ¶
func SaveInteractionsToFile ¶
func SaveInteractionsToFile(interactions []Interaction, filename string) error
SaveInteractionsToFile is a convenience function to save interactions to a file
Types ¶
type CaptureConfig ¶
CaptureConfig configures the capture middleware
func GetCaptureConfigFromEnv ¶
func GetCaptureConfigFromEnv(providerName string) CaptureConfig
GetCaptureConfigFromEnv creates capture config from environment variables
type CaptureMiddleware ¶
type CaptureMiddleware struct {
// contains filtered or unexported fields
}
CaptureMiddleware wraps any AI Gen implementation to capture interactions
func EnableCaptureForTesting ¶
func EnableCaptureForTesting(underlying Gen) *CaptureMiddleware
EnableCaptureForTesting enables capture with in-memory storage for testing
func EnableDebugCaptureForTesting ¶
func EnableDebugCaptureForTesting(underlying Gen) *CaptureMiddleware
EnableDebugCaptureForTesting enables capture with debug output for testing
func (*CaptureMiddleware) CountTokens ¶
func (c *CaptureMiddleware) CountTokens(ctx context.Context, p Prompt, debug bool, args ...string) (*TokenCount, error)
CountTokens delegates to the underlying LLM client
func (*CaptureMiddleware) CountTokensAttr ¶
func (c *CaptureMiddleware) CountTokensAttr(ctx context.Context, p Prompt, debug bool, attrs []Attr) (*TokenCount, error)
CountTokens delegates to the underlying LLM client
func (*CaptureMiddleware) GenerateContent ¶
func (c *CaptureMiddleware) GenerateContent(ctx context.Context, prompt Prompt, debug bool, args ...string) (string, error)
GenerateContent implements the Gen interface with capture
func (*CaptureMiddleware) GenerateContentAttr ¶
func (c *CaptureMiddleware) GenerateContentAttr(ctx context.Context, prompt Prompt, debug bool, attrs []Attr) (string, error)
GenerateContentAttr implements the Gen interface with capture
func (*CaptureMiddleware) GetCapture ¶
func (c *CaptureMiddleware) GetCapture() *InteractionCapture
GetCapture returns the underlying capture for inspection
func (*CaptureMiddleware) GetCapturedInteractions ¶
func (c *CaptureMiddleware) GetCapturedInteractions() []Interaction
GetCapturedInteractions returns all captured interactions
func (*CaptureMiddleware) GetLastInteraction ¶
func (c *CaptureMiddleware) GetLastInteraction() *Interaction
GetLastInteraction returns the most recent interaction
func (*CaptureMiddleware) GetStatus ¶
func (c *CaptureMiddleware) GetStatus() *Status
GetStatus delegates to the underlying LLM client
func (*CaptureMiddleware) LoadCapture ¶
func (c *CaptureMiddleware) LoadCapture(filename string) error
LoadCapture loads interactions from a file (for replay scenarios)
func (*CaptureMiddleware) PrintCaptureSummary ¶
func (c *CaptureMiddleware) PrintCaptureSummary()
PrintCaptureSummary prints a summary of captured interactions
func (*CaptureMiddleware) SaveCapture ¶
func (c *CaptureMiddleware) SaveCapture(filename string) error
SaveCapture saves captured interactions to a file
type CapturedAttr ¶
CapturedAttr represents an attribute for serialization
type CapturedError ¶
CapturedError represents an error that can be serialized
type CapturedFunction ¶
type CapturedFunction struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters map[string]interface{} `json:"parameters,omitempty"`
}
CapturedFunction represents a function declaration for serialization
type CapturedPrompt ¶
type CapturedPrompt struct {
Name string `json:"name"`
Text string `json:"text"`
Instruction string `json:"instruction"`
Functions []CapturedFunction `json:"functions,omitempty"`
Context map[string]interface{} `json:"context,omitempty"`
}
CapturedPrompt represents a prompt that can be serialized
type FunctionDeclaration ¶
type FunctionResponse ¶
type Gen ¶
type Gen interface {
GenerateContent(ctx context.Context, p Prompt, debug bool, args ...string) (string, error)
GenerateContentAttr(ctx context.Context, prompt Prompt, debug bool, attrs []Attr) (string, error)
CountTokens(ctx context.Context, p Prompt, debug bool, args ...string) (*TokenCount, error)
CountTokensAttr(ctx context.Context, p Prompt, debug bool, attrs []Attr) (*TokenCount, error)
GetStatus() *Status
}
func NewCaptureMiddleware ¶
func NewCaptureMiddleware(underlying Gen, config CaptureConfig) Gen
NewCaptureMiddleware creates a new capture middleware
type HandlerFunc ¶
type Interaction ¶
type Interaction struct {
ID string `json:"id"`
Timestamp time.Time `json:"timestamp"`
Prompt CapturedPrompt `json:"prompt"`
Args []string `json:"args"`
Attrs []CapturedAttr `json:"attrs,omitempty"`
Response string `json:"response"`
Error *CapturedError `json:"error,omitempty"`
Duration time.Duration `json:"duration"`
LLMProvider string `json:"llm_provider"`
Tools []string `json:"tools"`
Context map[string]interface{} `json:"context,omitempty"`
Debug bool `json:"debug"`
}
Interaction represents a complete LLM interaction for capture and replay
func LoadInteractionsFromFile ¶
func LoadInteractionsFromFile(filename string) ([]Interaction, error)
LoadInteractionsFromFile is a convenience function to load interactions from a file
type InteractionCapture ¶
type InteractionCapture struct {
// contains filtered or unexported fields
}
InteractionCapture manages the recording and storage of LLM interactions
func NewInteractionCapture ¶
func NewInteractionCapture() *InteractionCapture
NewInteractionCapture creates a new interaction capture instance
func (*InteractionCapture) Clear ¶
func (ic *InteractionCapture) Clear()
Clear removes all captured interactions
func (*InteractionCapture) CompleteInteraction ¶
func (ic *InteractionCapture) CompleteInteraction(interaction *Interaction, response string, err error, duration time.Duration)
CompleteInteraction finishes recording an interaction
func (*InteractionCapture) GetInteractionByID ¶
func (ic *InteractionCapture) GetInteractionByID(id string) *Interaction
GetInteractionByID finds an interaction by its ID
func (*InteractionCapture) GetInteractions ¶
func (ic *InteractionCapture) GetInteractions() []Interaction
GetInteractions returns all captured interactions
func (*InteractionCapture) GetLastInteraction ¶
func (ic *InteractionCapture) GetLastInteraction() *Interaction
GetLastInteraction returns the most recent interaction
func (*InteractionCapture) GetSummary ¶
func (ic *InteractionCapture) GetSummary() string
GetSummary returns a human-readable summary of captured interactions
func (*InteractionCapture) LoadFromFile ¶
func (ic *InteractionCapture) LoadFromFile(filename string) error
LoadFromFile loads interactions from a JSON file
func (*InteractionCapture) SaveToFile ¶
func (ic *InteractionCapture) SaveToFile(filename string) error
SaveToFile saves all captured interactions to a JSON file
func (*InteractionCapture) SetOutputFile ¶
func (ic *InteractionCapture) SetOutputFile(filename string)
SetOutputFile configures where interactions should be saved
func (*InteractionCapture) StartInteraction ¶
func (ic *InteractionCapture) StartInteraction(prompt Prompt, args []string) *Interaction
StartInteraction begins recording a new interaction
type MockGen ¶
type MockGen struct {
ResponseQueue []string
CallCounts map[string]int
UsedPrompts []Prompt
LastAttrs []Attr
// contains filtered or unexported fields
}
MockGen implements the Gen interface for testing
func NewSharedMockGen ¶
func NewSharedMockGen() *MockGen
NewSharedMockGen creates a new mock generator for testing
func (*MockGen) CountTokens ¶
func (*MockGen) GenerateContent ¶
func (m *MockGen) GenerateContent(ctx context.Context, prompt Prompt, debug bool, args ...string) (string, error)
GenerateContent implements the Gen interface
type Prompt ¶
type Prompt struct {
Name string `yaml:"name"`
Instruction string `yaml:"instruction"`
Text string `yaml:"text"`
Images []*Image `yaml:"images"`
RequiredTools []string `yaml:"required_tools"`
Functions []*FunctionDeclaration
ResponseSchema *Schema `yaml:"response_schema"`
Handlers map[string]HandlerFunc `yaml:"-"`
ModelName string `yaml:"model_name"`
MaxTokens int32 `yaml:"max_tokens"`
Temperature float32 `yaml:"temperature"`
TopP float32 `yaml:"top_p"`
}
type RetryConfig ¶ added in v0.1.6
RetryConfig configures the retry middleware
func GetRetryConfigFromEnv ¶ added in v0.1.6
func GetRetryConfigFromEnv(configManager config.Manager) RetryConfig
GetRetryConfigFromEnv creates retry config from environment variables
type RetryMiddleware ¶ added in v0.1.6
type RetryMiddleware struct {
// contains filtered or unexported fields
}
RetryMiddleware wraps an AI Gen implementation to add retry logic
func NewRetryMiddleware ¶ added in v0.1.6
func NewRetryMiddleware(underlying Gen, config RetryConfig) *RetryMiddleware
NewRetryMiddleware creates a new RetryMiddleware
func (*RetryMiddleware) CountTokens ¶ added in v0.1.6
func (r *RetryMiddleware) CountTokens(ctx context.Context, p Prompt, debug bool, args ...string) (*TokenCount, error)
CountTokens delegates to the underlying LLM client
func (*RetryMiddleware) CountTokensAttr ¶ added in v0.1.6
func (r *RetryMiddleware) CountTokensAttr(ctx context.Context, p Prompt, debug bool, attrs []Attr) (*TokenCount, error)
CountTokensAttr delegates to the underlying LLM client
func (*RetryMiddleware) GenerateContent ¶ added in v0.1.6
func (r *RetryMiddleware) GenerateContent(ctx context.Context, p Prompt, debug bool, args ...string) (string, error)
GenerateContent implements the Gen interface with retry logic
func (*RetryMiddleware) GenerateContentAttr ¶ added in v0.1.6
func (r *RetryMiddleware) GenerateContentAttr(ctx context.Context, p Prompt, debug bool, attrs []Attr) (string, error)
GenerateContentAttr implements the Gen interface with retry logic
func (*RetryMiddleware) GetStatus ¶ added in v0.1.6
func (r *RetryMiddleware) GetStatus() *Status
GetStatus delegates to the underlying LLM client
type Schema ¶
type Schema struct {
Type Type `yaml:"type"`
Format string `yaml:"format"`
Title string `yaml:"title"`
Description string `yaml:"description"`
Nullable bool `yaml:"nullable"`
Items *Schema `yaml:"items"`
MinItems int64 `yaml:"min_items"`
MaxItems int64 `yaml:"max_items"`
Enum []string `yaml:"enum"`
Properties map[string]*Schema `yaml:"properties"`
Required []string `yaml:"required"`
MinProperties int64 `yaml:"min_properties"`
MaxProperties int64 `yaml:"max_properties"`
Minimum float64 `yaml:"minimum"`
Maximum float64 `yaml:"maximum"`
MinLength int64 `yaml:"min_length"`
MaxLength int64 `yaml:"max_length"`
Pattern string `yaml:"pattern"`
}