Documentation
¶
Overview ¶
Package openai provides a deterministic, stateless mock upstream for several LLM providers. Responses preserve the provider-specific shapes and usage fields consumed by gateway policies.
Index ¶
Constants ¶
const ChatEchoPath = "/openai/v1/chat-echo"
ChatEchoPath answers with the request's last user message as the assistant's reply, so a scenario controls the response text a gateway policy sees. With "stream": true the reply is sent as OpenAI chat-completion chunks over server-sent events, one word per chunk.
const ChatEchoProviderPath = "/openai-echo/v1/chat/completions"
ChatEchoProviderPath answers like ChatEchoPath at the chat-completions path an OpenAI-template LLM provider calls, so a provider whose upstream is http://testbench:3008/openai-echo/v1 gets echoed, optionally streamed replies.
const KeyedPathPrefix = "/openai-keyed/v1"
KeyedPathPrefix is an OpenAI-dialect upstream that, like the real service, refuses any credential but ValidAPIKey, sent in either the api-key header (Azure OpenAI) or as an Authorization bearer token (OpenAI). Its refusal never repeats the presented key.
const Port = 3008
Port is the container port used by the testbench.
const ReadinessPath = "/__readiness"
ReadinessPath is used by provider readiness probes.
const ScriptedHeader = "X-Testbench-Scripted"
ScriptedHeader is set on every scripted reply, so a scenario can show that the gateway passed the upstream's headers through unchanged.
const ScriptedPathPrefix = "/scripted/"
ScriptedPathPrefix starts every path whose reply the request itself scripts. A request on any path below it gets exactly the reply its body names in ScriptedReplyField, so a scenario controls the model, usage and stream shape a gateway policy sees. Paths outside the prefix are unaffected.
const ScriptedReplyField = "x_testbench_reply"
ScriptedReplyField is the request body field that scripts the reply. Its value is an object with exactly one of:
"body": any JSON value except null, written as an application/json body (script a
literal null with "raw": "null")
"raw": a string written verbatim, for malformed or empty bodies
"events": a server-sent event stream, one element per event: a JSON object or array is
sent as "data: <compact JSON>", and a string is sent as the event's raw lines,
such as "data: [DONE]" or "event: message_start\ndata: {...}"
"contentType" optionally replaces the default content type of the chosen form. The service flushes after every event, so the gateway receives the stream as it is written.
const StreamErrorTrigger = "STREAM_ERROR"
StreamErrorTrigger, anywhere in a streaming request, ends the stream with the provider's error event instead of a clean finish.
const StreamedReply = "This is a streamed reply from the mock model."
StreamedReply is the assistant text every streamed reply carries, one word per delta.
const ValidAPIKey = "sk-testbench-valid-key"
ValidAPIKey is the only credential the keyed upstream accepts.
Variables ¶
This section is empty.
Functions ¶
This section is empty.