wirefake

package
v0.9.9 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 11 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 wirefake has fakes of the model APIs Blitz speaks (Anthropic's Messages API, the Gemini API and OpenAI's Responses API) that are as strict as the real ones (spec_056_conversation_adapters CA-150): each refuses, with the real API's status and words, what its documentation says it refuses. They answer from a script, sign their own reasoning as the real APIs do, and refuse a signature they didn't give, so a test that switches a conversation between them shows what a real switch would break.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ModelOf

func ModelOf(req map[string]any) string

ModelOf is the model a recorded request asked for: in its body (Anthropic, OpenAI) or its path (Gemini).

Types

type Call

type Call struct {
	Name string
	Args map[string]any
}

Call is one scripted tool call.

type Fake

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

Fake is one API's fake: a server, its script, and what it was sent.

func Anthropic

func Anthropic(t testing.TB) *Fake

Anthropic fakes the Messages API (POST /v1/messages), streamed when asked ("stream": true) as the API streams: each block started, its deltas, stopped, then the message's stop reason and usage.

func Gemini

func Gemini(t testing.TB) *Fake

Gemini fakes the Gemini API's generateContent and streamGenerateContent (POST /v1beta/models/<model>:…; the stream as server-sent events, the whole answer in one chunk). Point the genai client at it with GOOGLE_GEMINI_BASE_URL.

func OpenAI

func OpenAI(t testing.TB) *Fake

OpenAI fakes the Responses API (POST <base>/responses), streamed when asked ("stream": true) as the API streams: the response created, each output item added and done, then the response completed.

func (*Fake) Refusals

func (f *Fake) Refusals() []string

Refusals are why the fake refused requests, in order, in the API's words.

func (*Fake) Remaining

func (f *Fake) Remaining() int

Remaining is how many scripted answers haven't been given yet.

func (*Fake) Requests

func (f *Fake) Requests() []map[string]any

Requests are the bodies the fake was sent, accepted or not.

func (*Fake) Script

func (f *Fake) Script(rs ...Reply)

Script queues answers, given in order to the requests the fake accepts.

func (*Fake) Streamed

func (f *Fake) Streamed() int

Streamed is how many answers the fake gave as streams.

func (*Fake) URL

func (f *Fake) URL() string

URL is the fake's address.

type File

type File struct {
	MIME string
	Data []byte
}

File is a file a model makes.

type Reply

type Reply struct {
	// Thought is the model's reasoning, returned (and signed) only when
	// the request asks for reasoning, as the real APIs do.
	Thought string
	// Text is the answer's text.
	Text string
	// Calls are the tool calls the answer makes.
	Calls []Call
	// Files are files the answer makes (an image model's pictures), which
	// only the Gemini fake returns, as Gemini does: inline data in the
	// model's turn.
	Files []File
	// Usage is what the answer reports; zero gives a small default.
	Usage Usage
	// Status, when set, refuses the request with this HTTP status (a 503:
	// the model is overloaded) instead of answering.
	Status int
	// Search is a web search the model runs with its provider's own tool,
	// before its Text, which cites the results; only when the request
	// offers that tool, as a real model can search only then.
	Search *Search
	// Finish, when set, is why the answer ended, in the API's own words:
	// Anthropic's stop_reason ("refusal"), Gemini's finishReason ("SAFETY",
	// "RECITATION", "MALFORMED_FUNCTION_CALL"), OpenAI's incomplete reason
	// ("content_filter").
	Finish string
	// Extra are parts of the answer Blitz has no form for, as the API
	// sends them: an Anthropic content block (a server_tool_use), an
	// OpenAI output item (a web_search_call).
	Extra []map[string]any
	// TooLong refuses the request as longer than the model's context
	// window, in the API's words.
	TooLong bool
	// Refusal is the refusal's message, in the API's error shape (its
	// status's text when empty): a model refusing what it can't do, in
	// the words its server uses ("… does not support tools").
	Refusal string
}

Reply is one scripted answer, given in each API's own form.

type Search struct {
	Query   string
	Results []Source
}

Search is a provider web search: its query and what it found.

type Source

type Source struct {
	Title, URL string
}

Source is one search result.

type Usage

type Usage struct {
	Input, Cached, Output, Reasoning int
}

Usage is a reply's token counts, in the neutral sense: Output includes Reasoning (each fake reports them as its API does).

Jump to

Keyboard shortcuts

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