Documentation
¶
Overview ¶
Package llmaltering is the built-in llm_based_altering plugin: it rewrites the text of selected message roles through an auxiliary model, both in the prompt phase (before the provider call) and in the response phase.
Index ¶
- Constants
- func EffectiveMaxTokens(maxTokens int) int
- func New() pluginapi.Plugin
- func NormalizeRoles(roles []string) ([]string, error)
- func QualifiedModel(model, provider string) (string, error)
- func ResolvePrompt(prompt string) string
- type Config
- type Plugin
- func (p *Plugin) Close(context.Context) error
- func (p *Plugin) Init(_ context.Context, raw json.RawMessage, host pluginapi.Host) error
- func (p *Plugin) Manifest() pluginapi.Manifest
- func (p *Plugin) Normalize(raw json.RawMessage) (json.RawMessage, error)
- func (p *Plugin) OnPrompt(ctx context.Context, x *pluginapi.Exchange) (pluginapi.Decision, error)
- func (p *Plugin) OnResponse(ctx context.Context, x *pluginapi.Exchange) (pluginapi.Decision, error)
- func (p *Plugin) Summarize(raw json.RawMessage) string
Constants ¶
const DefaultMaxTokens = 4096
DefaultMaxTokens caps the auxiliary rewrite completion when unset.
const DefaultPrompt = `` /* 8087-byte string literal not displayed */
DefaultPrompt is the built-in prompt used when no custom prompt is configured. It is derived from LiteLLM's data anonymization guardrail prompt and instructs the model to rewrite text conservatively.
const Name = "llm_based_altering"
Name is the plugin's manifest name.
Variables ¶
This section is empty.
Functions ¶
func EffectiveMaxTokens ¶
EffectiveMaxTokens returns the effective max_tokens value.
func NormalizeRoles ¶
NormalizeRoles validates, lowercases, and deduplicates the target roles.
func QualifiedModel ¶
QualifiedModel folds an optional provider hint into the model selector.
func ResolvePrompt ¶
ResolvePrompt returns the effective system prompt.
Types ¶
type Config ¶
type Config struct {
Model string `json:"model"`
Provider string `json:"provider,omitempty"`
Prompt string `json:"prompt,omitempty"`
Roles []string `json:"roles,omitempty"`
SkipContentPrefix string `json:"skip_content_prefix,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
}
Config is the instance configuration.
func ParseConfig ¶
func ParseConfig(raw json.RawMessage) (Config, error)
ParseConfig decodes and normalizes a config: the provider hint is folded into the model ("provider/model"), roles are lowercased and deduplicated (default ["user"]), and an empty prompt selects DefaultPrompt.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements the prompt and response hooks.
func (*Plugin) Normalize ¶
func (p *Plugin) Normalize(raw json.RawMessage) (json.RawMessage, error)
Normalize folds the provider hint into the stored model selector so the persisted config reads "provider/model" with provider cleared.
func (*Plugin) OnPrompt ¶
OnPrompt rewrites the text parts of every message whose role is selected, tool-result text included.
func (*Plugin) OnResponse ¶
OnResponse rewrites the assistant text of every choice when the assistant role is selected.