Documentation
¶
Overview ¶
Package rewrite performs keyword substitution on request payloads.
It is used to replace sensitive or brand-specific keywords in the inbound request body before forwarding to the upstream, helping avoid content security detection that keys off specific terms. Rules are provided as a JSON object mapping a source keyword to its replacement, e.g. `{"foo":"bar"}`. Matching is case-sensitive and multiple rules are applied in a single pass (longest source first) so overlapping keywords do not double-replace.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppliedRule ¶
AppliedRule describes a rule that changed at least one textual field in a request. Count is the number of substitutions made by that rule.
type Replacer ¶
type Replacer struct {
// contains filtered or unexported fields
}
Replacer holds compiled keyword rules. A nil *Replacer is a no-op for every method, so callers can invoke ApplyToRequest without nil checks.
func Parse ¶
Parse decodes a JSON object of keyword mappings into a Replacer. An empty input returns a nil Replacer (no-op). Keys and values must be non-empty strings; duplicate source keywords keep the first occurrence.
Matching is case-sensitive, so "Foo" and "foo" are distinct keywords. Configure both explicitly if both forms should be rewritten.
func (*Replacer) ApplyToRequest ¶
func (r *Replacer) ApplyToRequest(req *ir.Request) []AppliedRule
ApplyToRequest rewrites the textual content of an IR request in place: the system prompt, message text/thinking parts and tool result payloads. Structural fields such as model names, tool names and tool call arguments are intentionally left untouched so routing and function calls stay intact. It returns the rules that made an actual change, in match order.
Source Files
¶
- rewrite.go