Documentation
¶
Overview ¶
Package control implements the scripted fake upstreams used by the e2e tests and the control API that scripts them and reads back what they received.
Index ¶
Constants ¶
const ( DefaultChatID = "chatcmpl-fake" DefaultResponseID = "resp_fake" DefaultCreated = 1700000000 DefaultNoul = 0.75 )
Fixed values of the default answers, so tests can assert on them.
const ( RouteOpenAIChat = "openai.chat" // POST /v1/chat/completions RouteOpenAIEmbeddings = "openai.embeddings" // POST /v1/embeddings RouteOpenAITranscriptions = "openai.transcriptions" // POST /v1/audio/transcriptions RouteOpenAIDecisions = "openai.decisions" // POST /v1/decisions RouteOpenAIResponses = "openai.responses" // POST /v1/responses RouteModels = "models" // GET /v1/models RouteOpenRouterAuthKey = "openrouter.auth_key" // GET /v1/auth/key RouteSonioxFileCreate = "soniox.files.create" // POST /v1/files RouteSonioxFileList = "soniox.files.list" // GET /v1/files RouteSonioxFileDelete = "soniox.files.delete" // DELETE /v1/files/{id} RouteSonioxTxCreate = "soniox.transcriptions.create" // POST /v1/transcriptions RouteSonioxTxList = "soniox.transcriptions.list" // GET /v1/transcriptions RouteSonioxTxGet = "soniox.transcriptions.get" // GET /v1/transcriptions/{id} RouteSonioxTxDelete = "soniox.transcriptions.delete" // DELETE /v1/transcriptions/{id} RouteSonioxTranscript = "soniox.transcript.get" // GET /v1/transcriptions/{id}/transcript RouteTypeSafeSystemOne = "typesafe.systemone" // POST /v1/systemone )
Route names, matched under /u/{upstream}.
const DefaultChatContent = "می\u200cشود و نمی\u200cخواهم"
DefaultChatContent is the assistant text of the default chat answer, streamed or not. It holds two zero-width non-joiners (U+200C) so byte-for-byte fidelity is tested even without a script.
const DefaultChatJSONContent = `{"answer":"` + DefaultChatContent + `"}`
DefaultChatJSONContent is the default chat answer when the request asks for a JSON response_format.
const DefaultEmbeddingDimensions = 8
DefaultEmbeddingDimensions is the vector length when a request sets no dimensions.
Variables ¶
This section is empty.
Functions ¶
func Defaults ¶
func Defaults() map[string]http.HandlerFunc
Defaults returns the default answer of every route this plan serves: OpenAI chat (plain and streamed), Responses, embeddings and decisions, TypeSafe System One and the model listing. Each echoes the requested model.
Types ¶
type RecordedRequest ¶
type RecordedRequest struct {
Route string `json:"route"`
Method string `json:"method"`
Path string `json:"path"`
Header http.Header `json:"header"`
Body []byte `json:"body"` // base64 in JSON
At time.Time `json:"at"`
}
RecordedRequest is one request a fake upstream received.
type Script ¶
type Script struct {
Steps []Step `json:"steps"`
Repeat bool `json:"repeat"` // after the last step: true = repeat it, false = fall back to the route default
}
Script is the ordered replies for one (upstream, route).
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server holds the scripts and recordings of every fake upstream.
type Step ¶
type Step struct {
Status int `json:"status"` // default 200
Headers map[string]string `json:"headers,omitempty"` // Content-Type defaults to application/json
Body string `json:"body,omitempty"` // written verbatim
DelayMS int `json:"delay_ms,omitempty"` // before the first byte; honours request cancellation
SSE []string `json:"sse,omitempty"` // when set: text/event-stream, one flushed `data:` event each, then [DONE]
// IntervalMS, with SSE, waits this long before every event after the first, [DONE] included; it honours request
// cancellation. It makes a stream last as long as a test needs.
IntervalMS int `json:"interval_ms,omitempty"`
}
Step is one scripted reply.