Documentation
¶
Overview ¶
Package execution provides functionality for executing templates against LLM systems.
Package execution provides functionality for executing templates against LLM systems.
Package execution provides functionality for executing templates against LLM systems.
Package execution provides functionality for executing templates against LLM systems.
Package execution provides functionality for executing templates against LLM systems.
Index ¶
- type AggregationStrategy
- type AsyncTemplateExecutor
- func (e *AsyncTemplateExecutor) Execute(ctx context.Context, template *format.Template, options map[string]interface{}) (*interfaces.TemplateResult, error)
- func (e *AsyncTemplateExecutor) ExecuteBatch(ctx context.Context, templates []*format.Template, ...) ([]*interfaces.TemplateResult, error)
- func (e *AsyncTemplateExecutor) GetExecutionStats() map[string]interface{}
- func (e *AsyncTemplateExecutor) Shutdown()
- type CacheStats
- type CompositeDetectionEngine
- type CustomDetector
- type DefaultDetectionEngine
- type DetectionEngine
- type Engine
- func (e *Engine) ExecuteTemplate(ctx context.Context, template *format.Template, data interface{}) (string, error)
- func (e *Engine) ExecuteTemplates(ctx context.Context, templates []*format.Template, data interface{}) ([]string, error)
- func (e *Engine) GetExecutionDelay() time.Duration
- func (e *Engine) GetMaxConcurrent() int
- func (e *Engine) SetExecutionDelay(delay time.Duration)
- func (e *Engine) SetMaxConcurrent(max int)
- type ExecutionOptions
- type ExecutionStats
- type LLMProvider
- type OptimizedTemplateExecutor
- func (e *OptimizedTemplateExecutor) ClearCache()
- func (e *OptimizedTemplateExecutor) Execute(ctx context.Context, template *format.Template, options map[string]interface{}) (*interfaces.TemplateResult, error)
- func (e *OptimizedTemplateExecutor) ExecuteBatch(ctx context.Context, templates []*format.Template, ...) ([]*interfaces.TemplateResult, error)
- func (e *OptimizedTemplateExecutor) GetCacheStats() map[string]interface{}
- func (e *OptimizedTemplateExecutor) GetDetectionEngines() []string
- func (e *OptimizedTemplateExecutor) GetExecutionStats() map[string]interface{}
- func (e *OptimizedTemplateExecutor) GetProviders() []string
- func (e *OptimizedTemplateExecutor) RegisterDetectionEngine(engine interfaces.DetectionEngine)
- func (e *OptimizedTemplateExecutor) RegisterProvider(provider interfaces.LLMProvider)
- func (e *OptimizedTemplateExecutor) SetCacheSize(size int)
- func (e *OptimizedTemplateExecutor) SetCacheTTL(ttl time.Duration)
- func (e *OptimizedTemplateExecutor) SetMaxConcurrent(max int)
- func (e *OptimizedTemplateExecutor) SetWorkerPoolSize(size int)
- type PipelineExecutor
- func (p *PipelineExecutor) AddPostprocessor(postprocessor ResultPostprocessor)
- func (p *PipelineExecutor) AddPreprocessor(preprocessor TemplatePreprocessor)
- func (p *PipelineExecutor) Execute(ctx context.Context, template interfaces.Template, ...) (*interfaces.TemplateResult, error)
- func (p *PipelineExecutor) ExecuteBatch(ctx context.Context, templates []interfaces.Template, ...) ([]*interfaces.TemplateResult, error)
- func (p *PipelineExecutor) GetPipelineStats() map[string]interface{}
- func (p *PipelineExecutor) SetDetectionEngine(detectionEngine DetectionEngine)
- func (p *PipelineExecutor) Shutdown()
- type PipelineStage
- type RateLimiter
- type ResponseCache
- type ResponseCacheEntry
- type ResultPostprocessor
- type TemplateExecutor
- func (e *TemplateExecutor) EnableUserRateLimiting(enabled bool)
- func (e *TemplateExecutor) Execute(ctx context.Context, template *format.Template, options map[string]interface{}) (*interfaces.TemplateResult, error)
- func (e *TemplateExecutor) ExecuteBatch(ctx context.Context, templates []*format.Template, ...) ([]*interfaces.TemplateResult, error)
- func (e *TemplateExecutor) ExecuteBatchForUser(ctx context.Context, templates []*format.Template, userID string, ...) ([]*interfaces.TemplateResult, error)
- func (e *TemplateExecutor) ExecuteForUser(ctx context.Context, template *format.Template, userID string, ...) (*interfaces.TemplateResult, error)
- func (e *TemplateExecutor) GetDetectionEngines() []string
- func (e *TemplateExecutor) GetInputValidator() interfaces.InputValidator
- func (e *TemplateExecutor) GetProviders() []string
- func (e *TemplateExecutor) RegisterDetectionEngine(name string, engine DetectionEngine)
- func (e *TemplateExecutor) RegisterProvider(provider LLMProvider)
- func (e *TemplateExecutor) SetInputValidator(validator interfaces.InputValidator)
- func (e *TemplateExecutor) SetMaxConcurrent(max int)
- func (e *TemplateExecutor) SetSanitizePrompts(sanitize bool)
- func (e *TemplateExecutor) SetStrictValidation(strict bool)
- func (e *TemplateExecutor) SetUserID(userID string)
- type TemplateExecutorAdapter
- func (a *TemplateExecutorAdapter) Execute(ctx context.Context, template interfaces.Template, data interface{}) ([]byte, error)
- func (a *TemplateExecutorAdapter) ExecuteWithOptions(ctx context.Context, template interfaces.Template, data interface{}, ...) ([]byte, error)
- func (a *TemplateExecutorAdapter) RegisterProvider(provider interface{})
- type TemplatePreprocessor
- type WorkPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AggregationStrategy ¶
type AggregationStrategy string
AggregationStrategy is the strategy for aggregating results from multiple detection engines
const ( // AnyDetected considers a vulnerability detected if any engine detects it AnyDetected AggregationStrategy = "any" // AllDetected considers a vulnerability detected only if all engines detect it AllDetected AggregationStrategy = "all" // MajorityDetected considers a vulnerability detected if the majority of engines detect it MajorityDetected AggregationStrategy = "majority" // WeightedScore uses a weighted score from all engines WeightedScore AggregationStrategy = "weighted" )
type AsyncTemplateExecutor ¶
type AsyncTemplateExecutor struct {
// contains filtered or unexported fields
}
AsyncTemplateExecutor is a high-performance template executor with advanced concurrency
func NewAsyncTemplateExecutor ¶
func NewAsyncTemplateExecutor(baseExecutor *OptimizedTemplateExecutor, queueSize int, cacheSize int, cacheTTL time.Duration) *AsyncTemplateExecutor
NewAsyncTemplateExecutor creates a new async template executor
func (*AsyncTemplateExecutor) Execute ¶
func (e *AsyncTemplateExecutor) Execute(ctx context.Context, template *format.Template, options map[string]interface{}) (*interfaces.TemplateResult, error)
Execute executes a template asynchronously
func (*AsyncTemplateExecutor) ExecuteBatch ¶
func (e *AsyncTemplateExecutor) ExecuteBatch(ctx context.Context, templates []*format.Template, options map[string]interface{}) ([]*interfaces.TemplateResult, error)
ExecuteBatch executes multiple templates asynchronously
func (*AsyncTemplateExecutor) GetExecutionStats ¶
func (e *AsyncTemplateExecutor) GetExecutionStats() map[string]interface{}
GetExecutionStats returns statistics about the executor
func (*AsyncTemplateExecutor) Shutdown ¶
func (e *AsyncTemplateExecutor) Shutdown()
Shutdown shuts down the executor
type CacheStats ¶
type CacheStats struct {
// Hits is the number of cache hits
Hits int64
// Misses is the number of cache misses
Misses int64
// Evictions is the number of cache evictions
Evictions int64
// TotalLookups is the total number of lookups
TotalLookups int64
}
CacheStats tracks cache statistics
type CompositeDetectionEngine ¶
type CompositeDetectionEngine struct {
// contains filtered or unexported fields
}
CompositeDetectionEngine combines multiple detection engines
func NewCompositeDetectionEngine ¶
func NewCompositeDetectionEngine(engines []DetectionEngine, strategy AggregationStrategy) *CompositeDetectionEngine
NewCompositeDetectionEngine creates a new composite detection engine
type CustomDetector ¶
type CustomDetector func(ctx context.Context, criteria *format.TemplateDetection, response string) (bool, int, map[string]interface{}, error)
CustomDetector is a function that implements custom detection logic
type DefaultDetectionEngine ¶
type DefaultDetectionEngine struct {
// contains filtered or unexported fields
}
DefaultDetectionEngine is the default implementation of the DetectionEngine interface
func NewDefaultDetectionEngine ¶
func NewDefaultDetectionEngine() *DefaultDetectionEngine
NewDefaultDetectionEngine creates a new default detection engine
func (*DefaultDetectionEngine) Detect ¶
func (e *DefaultDetectionEngine) Detect(ctx context.Context, template interfaces.Template, response string) (bool, int, map[string]interface{}, error)
Detect detects vulnerabilities in an LLM response
func (*DefaultDetectionEngine) RegisterCustomDetector ¶
func (e *DefaultDetectionEngine) RegisterCustomDetector(detectionType string, detector CustomDetector)
RegisterCustomDetector registers a custom detector for a specific detection type
type DetectionEngine ¶
type DetectionEngine interface {
Detect(ctx context.Context, template interfaces.Template, response string) (bool, int, map[string]interface{}, error)
}
DetectionEngine is the interface for detection engines
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is a simplified template execution engine for benchmarking
func (*Engine) ExecuteTemplate ¶
func (e *Engine) ExecuteTemplate(ctx context.Context, template *format.Template, data interface{}) (string, error)
ExecuteTemplate executes a template
func (*Engine) ExecuteTemplates ¶
func (e *Engine) ExecuteTemplates(ctx context.Context, templates []*format.Template, data interface{}) ([]string, error)
ExecuteTemplates executes multiple templates
func (*Engine) GetExecutionDelay ¶
GetExecutionDelay returns the simulated execution delay
func (*Engine) GetMaxConcurrent ¶
GetMaxConcurrent returns the maximum number of concurrent executions
func (*Engine) SetExecutionDelay ¶
SetExecutionDelay sets the simulated execution delay
func (*Engine) SetMaxConcurrent ¶
SetMaxConcurrent sets the maximum number of concurrent executions
type ExecutionOptions ¶
type ExecutionOptions struct {
// Provider is the LLM provider to use
Provider LLMProvider
// DetectionEngine is the detection engine to use
DetectionEngine DetectionEngine
// RateLimiter is the rate limiter to use
RateLimiter RateLimiter
// InputValidator is the input validator to use
InputValidator interfaces.InputValidator
// Timeout is the timeout for template execution
Timeout time.Duration
// RetryCount is the number of retries for failed requests
RetryCount int
// RetryDelay is the delay between retries
RetryDelay time.Duration
// MaxConcurrent is the maximum number of concurrent executions
MaxConcurrent int
// Variables is a map of variables to substitute in templates
Variables map[string]interface{}
// ProviderOptions is a map of provider-specific options
ProviderOptions map[string]interface{}
// StrictValidation determines if validation errors should fail execution
StrictValidation bool
// SanitizePrompts determines if prompts should be sanitized before execution
SanitizePrompts bool
// UserID is the ID of the user making the request
UserID string
// EnableUserRateLimiting determines if user-specific rate limiting is enabled
EnableUserRateLimiting bool
}
ExecutionOptions contains options for template execution
type ExecutionStats ¶
type ExecutionStats struct {
// TotalExecutions is the total number of template executions
TotalExecutions int64
// SuccessfulExecutions is the number of successful executions
SuccessfulExecutions int64
// FailedExecutions is the number of failed executions
FailedExecutions int64
// CachedResponses is the number of cached responses used
CachedResponses int64
// TotalExecutionTime is the total time spent executing templates
TotalExecutionTime time.Duration
// RetryCount is the number of retries performed
RetryCount int64
}
ExecutionStats tracks execution statistics
type LLMProvider ¶
type LLMProvider interface {
// SendPrompt sends a prompt to the LLM and returns the response
SendPrompt(ctx context.Context, prompt string, options map[string]interface{}) (string, error)
// GetSupportedModels returns the list of supported models
GetSupportedModels() []string
// GetName returns the name of the provider
GetName() string
// GetID returns a unique identifier for the provider
GetID() string
}
LLMProvider is the interface for interacting with LLM systems
type OptimizedTemplateExecutor ¶
type OptimizedTemplateExecutor struct {
// contains filtered or unexported fields
}
OptimizedTemplateExecutor is an enhanced template executor with improved performance
func NewOptimizedTemplateExecutor ¶
func NewOptimizedTemplateExecutor(defaultOptions *ExecutionOptions, cacheSize int, cacheTTL time.Duration, workerPoolSize int) *OptimizedTemplateExecutor
NewOptimizedTemplateExecutor creates a new optimized template executor
func (*OptimizedTemplateExecutor) ClearCache ¶
func (e *OptimizedTemplateExecutor) ClearCache()
ClearCache clears the response cache
func (*OptimizedTemplateExecutor) Execute ¶
func (e *OptimizedTemplateExecutor) Execute(ctx context.Context, template *format.Template, options map[string]interface{}) (*interfaces.TemplateResult, error)
Execute executes a template
func (*OptimizedTemplateExecutor) ExecuteBatch ¶
func (e *OptimizedTemplateExecutor) ExecuteBatch(ctx context.Context, templates []*format.Template, options map[string]interface{}) ([]*interfaces.TemplateResult, error)
ExecuteBatch executes multiple templates concurrently
func (*OptimizedTemplateExecutor) GetCacheStats ¶
func (e *OptimizedTemplateExecutor) GetCacheStats() map[string]interface{}
GetCacheStats returns statistics about the cache
func (*OptimizedTemplateExecutor) GetDetectionEngines ¶
func (e *OptimizedTemplateExecutor) GetDetectionEngines() []string
GetDetectionEngines returns the list of registered detection engines
func (*OptimizedTemplateExecutor) GetExecutionStats ¶
func (e *OptimizedTemplateExecutor) GetExecutionStats() map[string]interface{}
GetExecutionStats returns statistics about the executor
func (*OptimizedTemplateExecutor) GetProviders ¶
func (e *OptimizedTemplateExecutor) GetProviders() []string
GetProviders returns the list of registered providers
func (*OptimizedTemplateExecutor) RegisterDetectionEngine ¶
func (e *OptimizedTemplateExecutor) RegisterDetectionEngine(engine interfaces.DetectionEngine)
RegisterDetectionEngine registers a detection engine
func (*OptimizedTemplateExecutor) RegisterProvider ¶
func (e *OptimizedTemplateExecutor) RegisterProvider(provider interfaces.LLMProvider)
RegisterProvider registers an LLM provider
func (*OptimizedTemplateExecutor) SetCacheSize ¶
func (e *OptimizedTemplateExecutor) SetCacheSize(size int)
SetCacheSize sets the maximum size of the cache
func (*OptimizedTemplateExecutor) SetCacheTTL ¶
func (e *OptimizedTemplateExecutor) SetCacheTTL(ttl time.Duration)
SetCacheTTL sets the time-to-live for cache entries
func (*OptimizedTemplateExecutor) SetMaxConcurrent ¶
func (e *OptimizedTemplateExecutor) SetMaxConcurrent(max int)
SetMaxConcurrent sets the maximum number of concurrent executions
func (*OptimizedTemplateExecutor) SetWorkerPoolSize ¶
func (e *OptimizedTemplateExecutor) SetWorkerPoolSize(size int)
SetWorkerPoolSize sets the size of the worker pool
type PipelineExecutor ¶
type PipelineExecutor struct {
// contains filtered or unexported fields
}
PipelineExecutor is a template executor that uses a parallel pipeline
func NewPipelineExecutor ¶
func NewPipelineExecutor(baseExecutor interfaces.TemplateExecutor, bufferSize int) *PipelineExecutor
NewPipelineExecutor creates a new pipeline executor
func (*PipelineExecutor) AddPostprocessor ¶
func (p *PipelineExecutor) AddPostprocessor(postprocessor ResultPostprocessor)
AddPostprocessor adds a postprocessor to the pipeline
func (*PipelineExecutor) AddPreprocessor ¶
func (p *PipelineExecutor) AddPreprocessor(preprocessor TemplatePreprocessor)
AddPreprocessor adds a preprocessor to the pipeline
func (*PipelineExecutor) Execute ¶
func (p *PipelineExecutor) Execute(ctx context.Context, template interfaces.Template, options map[string]interface{}) (*interfaces.TemplateResult, error)
Execute executes a template through the pipeline
func (*PipelineExecutor) ExecuteBatch ¶
func (p *PipelineExecutor) ExecuteBatch(ctx context.Context, templates []interfaces.Template, options map[string]interface{}) ([]*interfaces.TemplateResult, error)
ExecuteBatch executes multiple templates through the pipeline
func (*PipelineExecutor) GetPipelineStats ¶
func (p *PipelineExecutor) GetPipelineStats() map[string]interface{}
GetPipelineStats returns statistics about the pipeline
func (*PipelineExecutor) SetDetectionEngine ¶
func (p *PipelineExecutor) SetDetectionEngine(detectionEngine DetectionEngine)
SetDetectionEngine sets the detection engine for the pipeline
func (*PipelineExecutor) Shutdown ¶
func (p *PipelineExecutor) Shutdown()
Shutdown shuts down the pipeline
type PipelineStage ¶
type PipelineStage int
PipelineStage represents a stage in the execution pipeline
const ( // StagePreprocessing is the preprocessing stage StagePreprocessing PipelineStage = iota // StageExecution is the execution stage StageExecution // StageDetection is the detection stage StageDetection // StagePostprocessing is the postprocessing stage StagePostprocessing )
type RateLimiter ¶
type RateLimiter = interfaces.RateLimiter
RateLimiter is an alias for interfaces.RateLimiter
type ResponseCache ¶
type ResponseCache struct {
// contains filtered or unexported fields
}
ResponseCache is a cache for LLM responses
type ResponseCacheEntry ¶
type ResponseCacheEntry struct {
// Response is the cached response
Response string
// CreatedAt is the time the entry was created
CreatedAt time.Time
// ExpiresAt is the time the entry expires
ExpiresAt time.Time
// Size is an estimate of the response size in bytes
Size int
}
ResponseCacheEntry represents a cached LLM response
type ResultPostprocessor ¶
type ResultPostprocessor interface {
// Postprocess postprocesses a result
Postprocess(ctx context.Context, result *interfaces.TemplateResult) (*interfaces.TemplateResult, error)
}
ResultPostprocessor is a postprocessor for results
type TemplateExecutor ¶
type TemplateExecutor struct {
// contains filtered or unexported fields
}
TemplateExecutor is responsible for executing templates against LLM systems
func NewTemplateExecutor ¶
func NewTemplateExecutor(defaultOptions *ExecutionOptions) *TemplateExecutor
NewTemplateExecutor creates a new template executor
func (*TemplateExecutor) EnableUserRateLimiting ¶
func (e *TemplateExecutor) EnableUserRateLimiting(enabled bool)
EnableUserRateLimiting enables or disables user-specific rate limiting
func (*TemplateExecutor) Execute ¶
func (e *TemplateExecutor) Execute(ctx context.Context, template *format.Template, options map[string]interface{}) (*interfaces.TemplateResult, error)
Execute executes a template
func (*TemplateExecutor) ExecuteBatch ¶
func (e *TemplateExecutor) ExecuteBatch(ctx context.Context, templates []*format.Template, options map[string]interface{}) ([]*interfaces.TemplateResult, error)
ExecuteBatch executes multiple templates
func (*TemplateExecutor) ExecuteBatchForUser ¶
func (e *TemplateExecutor) ExecuteBatchForUser(ctx context.Context, templates []*format.Template, userID string, options map[string]interface{}) ([]*interfaces.TemplateResult, error)
ExecuteBatchForUser executes multiple templates for a specific user
func (*TemplateExecutor) ExecuteForUser ¶
func (e *TemplateExecutor) ExecuteForUser(ctx context.Context, template *format.Template, userID string, options map[string]interface{}) (*interfaces.TemplateResult, error)
ExecuteForUser executes a template for a specific user
func (*TemplateExecutor) GetDetectionEngines ¶
func (e *TemplateExecutor) GetDetectionEngines() []string
GetDetectionEngines returns the list of registered detection engines
func (*TemplateExecutor) GetInputValidator ¶
func (e *TemplateExecutor) GetInputValidator() interfaces.InputValidator
GetInputValidator gets the input validator
func (*TemplateExecutor) GetProviders ¶
func (e *TemplateExecutor) GetProviders() []string
GetProviders returns the list of registered providers
func (*TemplateExecutor) RegisterDetectionEngine ¶
func (e *TemplateExecutor) RegisterDetectionEngine(name string, engine DetectionEngine)
RegisterDetectionEngine registers a detection engine
func (*TemplateExecutor) RegisterProvider ¶
func (e *TemplateExecutor) RegisterProvider(provider LLMProvider)
RegisterProvider registers an LLM provider
func (*TemplateExecutor) SetInputValidator ¶
func (e *TemplateExecutor) SetInputValidator(validator interfaces.InputValidator)
SetInputValidator sets the input validator
func (*TemplateExecutor) SetMaxConcurrent ¶
func (e *TemplateExecutor) SetMaxConcurrent(max int)
SetMaxConcurrent sets the maximum number of concurrent executions
func (*TemplateExecutor) SetSanitizePrompts ¶
func (e *TemplateExecutor) SetSanitizePrompts(sanitize bool)
SetSanitizePrompts sets whether prompts should be sanitized
func (*TemplateExecutor) SetStrictValidation ¶
func (e *TemplateExecutor) SetStrictValidation(strict bool)
SetStrictValidation sets the strict validation mode
func (*TemplateExecutor) SetUserID ¶
func (e *TemplateExecutor) SetUserID(userID string)
SetUserID sets the user ID for rate limiting
type TemplateExecutorAdapter ¶ added in v0.8.0
type TemplateExecutorAdapter struct {
// contains filtered or unexported fields
}
TemplateExecutorAdapter adapts TemplateExecutor to implement interfaces.TemplateExecutor
func NewTemplateExecutorAdapter ¶ added in v0.8.0
func NewTemplateExecutorAdapter(executor *TemplateExecutor) *TemplateExecutorAdapter
NewTemplateExecutorAdapter creates a new template executor adapter
func (*TemplateExecutorAdapter) Execute ¶ added in v0.8.0
func (a *TemplateExecutorAdapter) Execute(ctx context.Context, template interfaces.Template, data interface{}) ([]byte, error)
Execute executes a template (interface compatibility)
func (*TemplateExecutorAdapter) ExecuteWithOptions ¶ added in v0.8.0
func (a *TemplateExecutorAdapter) ExecuteWithOptions(ctx context.Context, template interfaces.Template, data interface{}, options map[string]interface{}) ([]byte, error)
ExecuteWithOptions executes with options (interface compatibility)
func (*TemplateExecutorAdapter) RegisterProvider ¶ added in v0.8.0
func (a *TemplateExecutorAdapter) RegisterProvider(provider interface{})
RegisterProvider registers a provider (interface compatibility)
type TemplatePreprocessor ¶
type TemplatePreprocessor interface {
// Preprocess preprocesses a template
Preprocess(ctx context.Context, template interfaces.Template, options map[string]interface{}) (interfaces.Template, error)
}
TemplatePreprocessor is a preprocessor for templates