Documentation
¶
Index ¶
- Constants
- func NormalizeArguments(args map[string]any, types map[string]string) map[string]any
- type ContentSafetyMatcher
- type ContentSafetyPattern
- type ContinueAction
- type Extractable
- type FilterAction
- type KillAction
- type MatchResult
- type Matcher
- type StreamFilter
- type ToolCall
- type ToolCallAction
- type ToolCallMatcher
Constants ¶
const (
DefaultMaxBuffer = 200
)
Variables ¶
This section is empty.
Functions ¶
func NormalizeArguments ¶ added in v0.4.3
NormalizeArguments coerces tool call argument values to match the JSON Schema types declared in the tool's parameter schema. LLMs sometimes return numbers as strings, bools as strings, etc. Unknown or missing properties are left unchanged.
types maps property names to their JSON Schema type strings (e.g. "number", "boolean", "string", "array", "object").
Types ¶
type ContentSafetyMatcher ¶
type ContentSafetyMatcher struct {
// contains filtered or unexported fields
}
ContentSafetyMatcher scans for blocked patterns in the stream.
func NewContentSafetyMatcher ¶
func NewContentSafetyMatcher(patterns []ContentSafetyPattern) *ContentSafetyMatcher
NewContentSafetyMatcher creates a matcher from compiled patterns.
func (*ContentSafetyMatcher) Name ¶
func (m *ContentSafetyMatcher) Name() string
func (*ContentSafetyMatcher) Scan ¶
func (m *ContentSafetyMatcher) Scan(buf []byte, prevTail string) MatchResult
type ContentSafetyPattern ¶
type ContentSafetyPattern struct {
Name string `json:"name"`
Regex string `json:"regex"`
// contains filtered or unexported fields
}
ContentSafetyPattern is a named regex pattern for content filtering.
type ContinueAction ¶
type ContinueAction struct{}
type Extractable ¶
type Extractable interface {
Extract(buf []byte) FilterAction
}
Extractable is implemented by matchers that produce data on FullMatch.
type FilterAction ¶
type FilterAction interface {
// contains filtered or unexported methods
}
FilterAction is returned by StreamFilter.Write and Flush to signal what happened.
type KillAction ¶
type KillAction struct{ Reason string }
type MatchResult ¶
type MatchResult int
const ( NoMatch MatchResult = iota PartialMatch // keep buffering, pattern might be forming FullMatch // pattern confirmed, act on it )
type Matcher ¶
type Matcher interface {
Scan(buf []byte, prevTail string) MatchResult
Name() string
}
Matcher scans a buffer and reports whether a pattern is present. prevTail contains the last N chars of previously emitted text for cross-boundary matching.
type StreamFilter ¶
type StreamFilter struct {
// contains filtered or unexported fields
}
StreamFilter sits between the model output stream and the SSE sender. It maintains a small lookahead buffer, runs matchers against it, and emits tokens from the trailing edge with a fixed delay.
func NewStreamFilter ¶
func NewStreamFilter(emitFunc func(string), matchers []Matcher, maxBuffer int) *StreamFilter
NewStreamFilter creates a filter with the given emit function, matchers, and buffer size.
func (*StreamFilter) Flush ¶
func (f *StreamFilter) Flush() FilterAction
Flush drains the remaining buffer. Call after the model stream completes.
func (*StreamFilter) PrevTail ¶
func (f *StreamFilter) PrevTail() string
PrevTail returns the overlap text for external inspection.
func (*StreamFilter) Write ¶
func (f *StreamFilter) Write(token string) FilterAction
Write feeds a token into the filter. Returns an action if a matcher triggers.
type ToolCallAction ¶
type ToolCallAction struct{ Calls []ToolCall }
type ToolCallMatcher ¶
type ToolCallMatcher struct{}
ToolCallMatcher detects tool call JSON emitted as text content.
func NewToolCallMatcher ¶
func NewToolCallMatcher() *ToolCallMatcher
func (*ToolCallMatcher) Extract ¶
func (m *ToolCallMatcher) Extract(buf []byte) FilterAction
func (*ToolCallMatcher) Name ¶
func (m *ToolCallMatcher) Name() string
func (*ToolCallMatcher) Scan ¶
func (m *ToolCallMatcher) Scan(buf []byte, _ string) MatchResult