litellmtest

package
v1.9.6 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package litellmtest provides a scripted Provider for testing code that calls models, without a network or a vendor.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider answers each call with the next of its replies, and records the requests it was called with. It is safe for concurrent use. A call beyond the script fails.

func New

func New(replies ...Reply) *Provider

New returns a Provider that replies in order.

func (*Provider) Chat

func (p *Provider) Chat(ctx context.Context, req *litellm.Request) (*litellm.Response, error)

func (*Provider) Name

func (p *Provider) Name() string

Name returns "test".

func (*Provider) Requests

func (p *Provider) Requests() []litellm.Request

Requests returns the requests made so far, in order.

func (*Provider) Stream

func (p *Provider) Stream(ctx context.Context, req *litellm.Request) (litellm.Stream, error)

type Reply

type Reply struct {
	Blocks []litellm.Block
	Usage  litellm.Usage
	// FinishReason defaults to tool_calls when Blocks hold a tool use, and to
	// stop otherwise.
	FinishReason litellm.FinishReason
	Err          error
	// StreamErr, if set, fails the stream with it once Blocks streamed,
	// instead of finishing it.
	StreamErr error
	// Stall, if set, holds the stream open once Blocks streamed, until the
	// call is cancelled.
	Stall bool
}

Reply is one scripted call: the response it streams, or the error it fails with before streaming.

func Fail

func Fail(err error) Reply

Fail fails the call with err.

func Respond

func Respond(blocks ...litellm.Block) Reply

Respond replies with blocks.

func Text

func Text(text string) Reply

Text replies with text.

Jump to

Keyboard shortcuts

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