llm_response_parser

package
v0.74.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2026 License: BSD-3-Clause, AGPL-3.0 Imports: 17 Imported by: 0

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

View Source
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) ID

func (Factory) ID() string

ID returns the registry identifier.

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 New

func New(cfg config) *Middleware

New constructs a configured Middleware instance.

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) ID

func (m *Middleware) ID() string

ID returns the registry identifier.

func (*Middleware) Invoke

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL