Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContentFilter ¶
type ContentFilter struct {
// contains filtered or unexported fields
}
ContentFilter implements a guardrail that filters inappropriate content
func NewContentFilter ¶
func NewContentFilter(blockedWords []string, action Action) *ContentFilter
NewContentFilter creates a new content filter guardrail
func (*ContentFilter) Action ¶
func (c *ContentFilter) Action() Action
Action returns the action to take when the guardrail is triggered
func (*ContentFilter) CheckRequest ¶
CheckRequest checks if a request violates the guardrail
func (*ContentFilter) CheckResponse ¶
CheckResponse checks if a response violates the guardrail
func (*ContentFilter) Type ¶
func (c *ContentFilter) Type() GuardrailType
Type returns the type of guardrail
type Guardrail ¶
type Guardrail interface {
// Type returns the type of guardrail
Type() GuardrailType
// CheckRequest checks if a request violates the guardrail
CheckRequest(ctx context.Context, request string) (bool, string, error)
// CheckResponse checks if a response violates the guardrail
CheckResponse(ctx context.Context, response string) (bool, string, error)
// Action returns the action to take when the guardrail is triggered
Action() Action
}
Guardrail represents a guardrail that can be applied to requests and responses
type GuardrailType ¶
type GuardrailType string
GuardrailType represents the type of guardrail
const ( // ContentFilterGuardrail filters content for inappropriate material ContentFilterGuardrail GuardrailType = "content_filter" // TokenLimitGuardrail limits the number of tokens in a request or response TokenLimitGuardrail GuardrailType = "token_limit" // PiiFilterGuardrail filters personally identifiable information PiiFilterGuardrail GuardrailType = "pii_filter" // ToolRestrictionGuardrail restricts which tools can be used ToolRestrictionGuardrail GuardrailType = "tool_restriction" // RateLimitGuardrail limits the rate of requests RateLimitGuardrail GuardrailType = "rate_limit" )
type LLMMiddleware ¶
type LLMMiddleware struct {
// contains filtered or unexported fields
}
LLMMiddleware implements middleware for LLM calls
func NewLLMMiddleware ¶
func NewLLMMiddleware(llm interfaces.LLM, pipeline *Pipeline) *LLMMiddleware
NewLLMMiddleware creates a new LLM middleware
type PiiFilter ¶
type PiiFilter struct {
// contains filtered or unexported fields
}
PiiFilter implements a guardrail that filters personally identifiable information
func NewPiiFilter ¶
NewPiiFilter creates a new PII filter guardrail
func (*PiiFilter) CheckRequest ¶
CheckRequest checks if a request violates the guardrail
func (*PiiFilter) CheckResponse ¶
CheckResponse checks if a response violates the guardrail
func (*PiiFilter) Type ¶
func (p *PiiFilter) Type() GuardrailType
Type returns the type of guardrail
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline represents a pipeline of guardrails
func NewPipeline ¶
NewPipeline creates a new guardrails pipeline
func (*Pipeline) AddGuardrail ¶
AddGuardrail adds a guardrail to the pipeline
func (*Pipeline) ProcessRequest ¶
ProcessRequest processes a request through the guardrails pipeline
type RateLimit ¶
type RateLimit struct {
// contains filtered or unexported fields
}
RateLimit implements a guardrail that limits the rate of requests
func NewRateLimit ¶
NewRateLimit creates a new rate limit guardrail
func (*RateLimit) CheckRequest ¶
CheckRequest checks if a request violates the guardrail
func (*RateLimit) CheckResponse ¶
CheckResponse checks if a response violates the guardrail
func (*RateLimit) Type ¶
func (r *RateLimit) Type() GuardrailType
Type returns the type of guardrail
type SimpleTokenCounter ¶
type SimpleTokenCounter struct{}
SimpleTokenCounter implements a simple token counter
func (*SimpleTokenCounter) CountTokens ¶
func (s *SimpleTokenCounter) CountTokens(text string) (int, error)
CountTokens counts tokens in text (simple approximation)
type TokenCounter ¶
TokenCounter is an interface for counting tokens in text
type TokenLimit ¶
type TokenLimit struct {
// contains filtered or unexported fields
}
TokenLimit implements a guardrail that limits the number of tokens
func NewTokenLimit ¶
func NewTokenLimit(maxTokens int, counter TokenCounter, action Action, truncateMode string) *TokenLimit
NewTokenLimit creates a new token limit guardrail
func (*TokenLimit) Action ¶
func (t *TokenLimit) Action() Action
Action returns the action to take when the guardrail is triggered
func (*TokenLimit) CheckRequest ¶
CheckRequest checks if a request violates the guardrail
func (*TokenLimit) CheckResponse ¶
CheckResponse checks if a response violates the guardrail
func (*TokenLimit) Type ¶
func (t *TokenLimit) Type() GuardrailType
Type returns the type of guardrail
type ToolMiddleware ¶
type ToolMiddleware struct {
// contains filtered or unexported fields
}
ToolMiddleware implements middleware for tool calls
func NewToolMiddleware ¶
func NewToolMiddleware(tool interfaces.Tool, pipeline *Pipeline) *ToolMiddleware
NewToolMiddleware creates a new tool middleware
func (*ToolMiddleware) Description ¶
func (m *ToolMiddleware) Description() string
Description returns a description of what the tool does
func (*ToolMiddleware) Name ¶
func (m *ToolMiddleware) Name() string
Name returns the name of the tool
func (*ToolMiddleware) Parameters ¶
func (m *ToolMiddleware) Parameters() map[string]interfaces.ParameterSpec
Parameters returns the parameters that the tool accepts
type ToolRestriction ¶
type ToolRestriction struct {
// contains filtered or unexported fields
}
ToolRestriction implements a guardrail that restricts which tools can be used
func NewToolRestriction ¶
func NewToolRestriction(allowedTools []string, action Action) *ToolRestriction
NewToolRestriction creates a new tool restriction guardrail
func (*ToolRestriction) Action ¶
func (t *ToolRestriction) Action() Action
Action returns the action to take when the guardrail is triggered
func (*ToolRestriction) CheckRequest ¶
CheckRequest checks if a request violates the guardrail
func (*ToolRestriction) CheckResponse ¶
CheckResponse checks if a response violates the guardrail
func (*ToolRestriction) Type ¶
func (t *ToolRestriction) Type() GuardrailType
Type returns the type of guardrail