llm_response_parser

package
v0.83.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: BSD-3-Clause, AGPL-3.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func (m *Middleware) Invoke(ctx 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.

Jump to

Keyboard shortcuts

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