Skip to content
English

MockGPT · 模拟模型与调试 ​

Kit · 可选业务库 · 返回本层目录

符号类别用途
CallRecordinterfaceDetached snapshot of one accepted call, exposed through MockGPT.records.
createMockHandlerfunctionCreate a bare Node request listener backed by the mock.
createMockServerfunctionCreate a self-contained mock HTTP server with explicit listen/close control. No UI or static assets are served: only the model routes answer, everything else is a 404.
encodeModelResponsefunctionOptional app-owned codec; validation and encoding consume the same snapshots. Thin public wrapper over encodeModel: re-validates identity arguments and re-snapshots both the request and the model output, so callers that build replies themselves get identical validation and cannot mutate the mock's state afterwards.
GeneratedtypeWhat a rule may produce: plain data, or a descriptor that changes transport behaviour.
GenerationContextinterfaceEverything a rule or generator may read for one accepted call. The context is frozen; the only mutable side channel is report, and only while the call is still pending.
GenerationInputinterfaceInput of MockGPT.generate. Normalized exactly like an HTTP request body, so a rule matches identically through both entry points; only model and messages are required.
GenerationOptionsinterfacePer-call options of MockGPT.generate.
GeneratortypeA rule's output: either a fixed value (deep-copied and frozen when the instance is built) or a function evaluated per call. A function may be async and is awaited under cancellation.
generatorNamesconstant
generatorsconstant
HandlerOptionsinterfaceOptions shared by the standalone server and the bare request handler.
HttpFaultinterfaceA simulated HTTP-level failure returned instead of a model reply.
isPublicAddressfunctionDecide whether an address is an acceptable public destination.
JsonValuetypeAny value accepted by the package's JSON snapshot rules: strings, finite numbers, booleans, null, arrays and plain objects.
LoadedPageinterfaceA fetched page body plus the metadata needed for decoding and diagnostics.
MessagetypeOne entry of an OpenAI chat conversation. The runtime validates role against the OpenAI role set and validates the outer shape of content; every other field is retained verbatim so vendor extensions flow through.
MockGPTclassConfigurable mock model instance. Create one per test or per mock server.
MockGPTErrorclassError type carrying a stable machine-readable code plus optional HTTP status and details. The HTTP adapter maps status onto the response and serializes code/details into the OpenAI-style error body, so codes are part of the public contract.
MockGPTOptionsinterfaceConstruction options of a MockGPT instance.
ModelOutputinterfaceThe model-authored part of a reply, before it becomes JSON or SSE frames.
ModelRequestinterfaceA normalized /chat/completions request, produced by snapshotRequest. Optional undefined fields have already been dropped and stream is already defaulted, so rules always observe the same shape regardless of whether the caller used generate or the injected fetch.
OutputOptionsinterfaceTransport-level knobs of a generated response. All values are simulated: they affect framing and timing of the mock reply, not real model behaviour.
ResponseDescriptionclassWrapper that distinguishes a transport instruction from ordinary generator data. kind: 'model' carries a ModelOutput, 'http' an HttpFault response, and 'reject' a message used to simulate a network failure. Instances are recognized by brand rather than by instanceof alone, so descriptors survive crossing the ESM/CJS boundary.
responsesconstant
routesconstant
RuleinterfaceOne ordered matching rule of a MockGPT instance.
ServerOptionsinterfaceOptions of createMockServer, adding shutdown behaviour.
sourcesconstant
TextOptionsinterfaceCommon options of the text generators.
TextSourcetypeText supplied to a text generator. A function may be async; it receives the per-call context so a source can depend on the prompt or on the call index.
ToolCallinterfaceA tool call the mocked assistant emits instead of executing.
UsageinterfaceToken accounting reported by the OpenAI API; validated for internal consistency.
WebOptionsinterfaceConfiguration of sources.web.
WebProfiletypeName of an entry in webHeaderProfiles.

接口参考、使用示例与开发指南。