Documentation
¶
Overview ¶
Package stringreplace is the built-in string_replace plugin: it rewrites, flags, or blocks prompt and completion text that matches a list of literal or regular-expression rules, in place for non-streaming responses and in flight for streams. It doubles as a reference implementation of a mutating pluginapi plugin with prompt, response, and stream hooks.
Index ¶
- Constants
- func New() pluginapi.Plugin
- type Plugin
- func (p *Plugin) Close(context.Context) error
- func (p *Plugin) Init(_ context.Context, raw json.RawMessage, _ pluginapi.Host) error
- func (p *Plugin) Manifest() pluginapi.Manifest
- func (p *Plugin) OnPrompt(_ context.Context, x *pluginapi.Exchange) (pluginapi.Decision, error)
- func (p *Plugin) OnResponse(_ context.Context, x *pluginapi.Exchange) (pluginapi.Decision, error)
- func (p *Plugin) OnStreamEnd(_ context.Context, x *pluginapi.Exchange) (pluginapi.Decision, error)
- func (p *Plugin) OnStreamEvent(_ context.Context, x *pluginapi.Exchange, ev *pluginapi.StreamEvent) (pluginapi.StreamDecision, error)
- func (p *Plugin) StreamPolicy() pluginapi.StreamPolicy
- func (p *Plugin) Summarize(raw json.RawMessage) string
Constants ¶
const ( ModeLiteral = "literal" ModeRegex = "regex" )
Mode values for the "mode" config key.
const ( OnMatchReplace = "replace" OnMatchBlock = "block" OnMatchRespond = "respond" OnMatchWarn = "warn" )
OnMatch values for the "on_match" config key.
const ( DefaultMessage = "Request blocked by policy" DefaultStreamLookbehind = 64 )
Defaults for optional config keys.
const Code = "string_replace_match"
Code is the Decision.Code recorded when a rule matches and on_match is block, respond, or warn.
const Name = "string_replace"
Name is the manifest name of the plugin.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin is one configured string_replace instance.
func (*Plugin) OnResponse ¶
OnResponse edits or inspects the text of every completion choice.
func (*Plugin) OnStreamEnd ¶
OnStreamEnd reports a warning when on_match is warn and a rule matched during the stream; otherwise it allows.
func (*Plugin) OnStreamEvent ¶
func (p *Plugin) OnStreamEvent(_ context.Context, x *pluginapi.Exchange, ev *pluginapi.StreamEvent) (pluginapi.StreamDecision, error)
OnStreamEvent rewrites text deltas for replace, remembers matches for warn, and passes everything else through.
func (*Plugin) StreamPolicy ¶
func (p *Plugin) StreamPolicy() pluginapi.StreamPolicy
StreamPolicy transforms text deltas in flight for replace and warn, and buffers the whole stream for block and respond so the decision is taken on the assembled completion before anything reaches the client.