Documentation
¶
Overview ¶
Package llm_response_parser implements the SlotOnResponse middleware that decodes OpenAI- and Anthropic-shaped LLM responses (buffered or streaming) and emits token usage and completion metadata. Provider and model are read from the request-side metadata bag emitted by llm_request_parser; without that context the middleware is a no-op.
Index ¶
- Constants
- type Factory
- type Middleware
- func (m *Middleware) AcceptedContentTypes() []string
- func (m *Middleware) Close() error
- func (m *Middleware) ID() string
- func (m *Middleware) Invoke(_ context.Context, in *middleware.Input) (*middleware.Output, error)
- func (m *Middleware) MetadataKeys() []string
- func (m *Middleware) MutationsSupported() bool
- func (m *Middleware) Slot() middleware.Slot
- func (m *Middleware) Version() string
Constants ¶
const ID = "llm_response_parser"
ID is the registry identifier for this middleware.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Factory ¶
type Factory struct{}
Factory constructs configured Middleware instances for the registry.
func (Factory) New ¶
func (Factory) New(rawConfig []byte) (middleware.Middleware, error)
New decodes RawConfig (empty / null / "{}" all accepted) and returns a configured Middleware. Construction never fails on a well-formed empty config; only structurally invalid JSON is rejected.
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware implements middleware.Middleware.
func (*Middleware) AcceptedContentTypes ¶
func (m *Middleware) AcceptedContentTypes() []string
AcceptedContentTypes lists the response content types the middleware inspects.
func (*Middleware) Close ¶
func (m *Middleware) Close() error
Close releases any resources held by the middleware. The parser-set is stateless so this is a no-op.
func (*Middleware) Invoke ¶
func (m *Middleware) Invoke(_ context.Context, in *middleware.Input) (*middleware.Output, error)
Invoke decodes the response body and emits token-usage and completion metadata. The decision is always DecisionAllow; parse errors degrade silently to omitted metadata rather than chain failures.
func (*Middleware) MetadataKeys ¶
func (m *Middleware) MetadataKeys() []string
MetadataKeys returns the closed allowlist of keys this middleware may emit.
func (*Middleware) MutationsSupported ¶
func (m *Middleware) MutationsSupported() bool
MutationsSupported reports that this middleware never mutates the response.
func (*Middleware) Slot ¶
func (m *Middleware) Slot() middleware.Slot
Slot reports that the middleware runs after the upstream call.
func (*Middleware) Version ¶
func (m *Middleware) Version() string
Version returns the implementation version.