modeltest

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package modeltest provides a scripted model for tests.

Index

Constants

This section is empty.

Variables

View Source
var ErrExhausted = errors.New("modeltest: script exhausted")

ErrExhausted is returned when the script has no more steps.

Functions

This section is empty.

Types

type Call

type Call struct {
	ID   string
	Name string
	Args any
}

Call describes a tool call made by CallTools.

type Model

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

Model replays a fixed script of steps and records every request.

func New

func New(steps ...Step) *Model

New returns a model that answers calls with steps, in order.

func (*Model) Append

func (m *Model) Append(steps ...Step)

Append adds steps to the script.

func (*Model) Generate

func (m *Model) Generate(ctx context.Context, req *model.Request) (*model.Response, error)

Generate returns the next scripted response.

func (*Model) Requests

func (m *Model) Requests() []*model.Request

Requests returns copies of the requests received so far.

func (*Model) Stream

func (m *Model) Stream(ctx context.Context, req *model.Request) iter.Seq2[*model.StreamEvent, error]

Stream streams the next scripted response. Text parts are split into several deltas so callers see incremental output. A step that returns no response and no error makes the stream fail.

type Step

type Step func(req *model.Request) (*model.Response, error)

Step produces the response for one model call.

func CallTools

func CallTools(calls ...Call) Step

CallTools returns a step that requests the given tool calls.

func Fail

func Fail(err error) Step

Fail returns a step that fails with err.

func Reply

func Reply(text string) Step

Reply returns a step that answers with text.

func Respond

func Respond(resp *model.Response) Step

Respond returns a step that answers with resp.

Jump to

Keyboard shortcuts

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