openai

package
v0.4.3 Latest Latest
Warning

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

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

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

View Source
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.

View Source
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.

View Source
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.

View Source
const Port = 3008

Port is the container port used by the testbench.

View Source
const ReadinessPath = "/__readiness"

ReadinessPath is used by provider readiness probes.

View Source
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.

View Source
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.

View Source
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.

View Source
const StreamErrorTrigger = "STREAM_ERROR"

StreamErrorTrigger, anywhere in a streaming request, ends the stream with the provider's error event instead of a clean finish.

View Source
const StreamedReply = "This is a streamed reply from the mock model."

StreamedReply is the assistant text every streamed reply carries, one word per delta.

View Source
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.

Types

type Service

type Service struct{}

Service implements the stateless LLM mock used by the testbench.

func New

func New() *Service

New returns a new Service.

func (*Service) Handler

func (s *Service) Handler() http.Handler

Handler returns the HTTP handler for the service.

func (*Service) Name

func (s *Service) Name() string

Name returns the service registration name.

func (*Service) Port

func (s *Service) Port() int

Port returns the service's listening port.

func (*Service) Stateful

func (s *Service) Stateful() bool

Stateful reports whether the service keeps request-specific state.

Jump to

Keyboard shortcuts

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