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
- func ModelOf(req map[string]any) string
- type Call
- type Fake
- type File
- type Live
- func (f *Live) Call(id, name string, args map[string]any, d time.Duration) map[string]any
- func (f *Live) Close()
- func (f *Live) Drop()
- func (f *Live) GoAway()
- func (f *Live) Heard(text string)
- func (f *Live) Next(key string, d time.Duration) map[string]any
- func (f *Live) Opened(d time.Duration) map[string]any
- func (f *Live) Resume(handle string)
- func (f *Live) Say(text string, pcm []byte)
- func (f *Live) Send(msg map[string]any)
- func (f *Live) Setups() []map[string]any
- type Reply
- type Search
- type Source
- type Usage
Constants ¶
const LivePath = "/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent"
LivePath is the Gemini API's Live socket, as genai dials it.
Variables ¶
This section is empty.
Functions ¶
Types ¶
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 ¶
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 ¶
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 ¶
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.
type Live ¶ added in v1.0.0
type Live struct {
// URL is the client's base URL (ws://host), for genai's HTTPOptions.
URL string
// contains filtered or unexported fields
}
Live fakes the Gemini API's Live socket (BidiGenerateContent) as strictly as the API (spec_063_voice VOX-60): the API key in x-goog-api-key, setup first (a model, audio answers, a prebuilt voice) and answered with setupComplete; then only realtime input (16 kHz PCM, activity start and end), client content and tool responses, each tool response answering a call the fake made. Anything else fails the test and closes the socket with 1007, as the API does. The test plays the server: Send pushes a message to the open connection, Next waits for the client's next message; GoAway and Drop end a connection, and a client resuming must name the last handle given (Resume).
func (*Live) Call ¶ added in v1.0.0
Call is the model calling a tool, and the response the client sends back, within d.
func (*Live) Close ¶ added in v1.0.0
func (f *Live) Close()
Close ends the connection and the server.
func (*Live) Drop ¶ added in v1.0.0
func (f *Live) Drop()
Drop ends the connection with no warning (a network that went away).
func (*Live) GoAway ¶ added in v1.0.0
func (f *Live) GoAway()
GoAway warns the client the connection ends soon, then ends it, as the API does at its session limit.
func (*Live) Next ¶ added in v1.0.0
Next waits for the client's next message that has key (others are skipped: audio streams constantly), within d.
func (*Live) Opened ¶ added in v1.0.0
Opened waits for a connection's setup (VOX-07's resumption opens another) and returns it.
func (*Live) Say ¶ added in v1.0.0
Say is the server speaking: the transcript of what it says and its audio (24 kHz PCM), then the turn's end.
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.