Expand description
Fluent LLM-mocking builders for the MockServer Rust client.
This module is an idiomatic Rust port of the Java/Node/Python client LLM
builders (org.mockserver.client.Llm / LlmMockBuilder /
LlmConversationBuilder / LlmFailoverBuilder / TurnBuilder) and the
underlying model classes (Completion, ToolUse, Usage,
StreamingPhysics, EmbeddingResponse). The builders produce exactly the
same expectation wire JSON the other clients emit, so a mock scripted from
Rust is byte-for-byte equivalent (modulo JSON key order, which the server
ignores) to one scripted from Java.
The expectation action is carried in the httpLlmResponse field of an
expectation (a sibling of httpRequest, scenarioName, scenarioState,
newScenarioState, times, timeToLive, httpResponse). Null/unset
fields are omitted from the JSON, matching the server’s NON_NULL
serialization.
§Example
use mockserver_client::llm::{llm_mock, completion, Provider};
let expectation = llm_mock("/v1/chat/completions")
.with_provider(Provider::OPENAI)
.with_model("gpt-4o")
.responding_with(completion().with_text("Hello!"))
.build();
assert_eq!(expectation["httpLlmResponse"]["provider"], "OPENAI");Structs§
- Completion
- A mocked LLM chat/completion response, provider-agnostic
(mirrors
org.mockserver.model.Completion). - Embedding
Response - A mocked embedding response — vector shape and determinism
(mirrors
org.mockserver.model.EmbeddingResponse). - Isolation
Source - Where to read the per-session isolation key from an inbound request
(mirrors
org.mockserver.llm.IsolationSource). Encodes as"<kind>:<name>". - LlmConversation
Builder - Builder for multi-turn LLM conversation mocks with scenario advancement
(mirrors
org.mockserver.client.LlmConversationBuilder). - LlmFailover
Builder - Builder for provider failover/retry scenarios
(mirrors
org.mockserver.client.LlmFailoverBuilder). - LlmMock
Builder - Fluent builder for a single LLM mock expectation
(mirrors
org.mockserver.client.LlmMockBuilder). - Provider
- LLM provider names. Serialized on the wire as the upper-case enum name
(mirrors
org.mockserver.model.Provider). - Role
- Parsed-message roles (mirrors
org.mockserver.llm.ParsedMessage.Role). - Streaming
Physics - Controls the timing physics of a streamed (SSE) completion
(mirrors
org.mockserver.model.StreamingPhysics). - ToolUse
- A single tool/function call emitted by the assistant
(mirrors
org.mockserver.model.ToolUse). - Turn
Builder - Sub-builder configuring one turn of a conversation mock
(mirrors
org.mockserver.client.TurnBuilder). - Usage
- Token usage counts for a completion (mirrors
org.mockserver.model.Usage).
Enums§
- LlmResponse
Body - Either a
Completionor anEmbeddingResponse, accepted byresponding_withbuilder methods.
Functions§
- completion
- Factory mirroring
Completion.completion(). - conversation
- Entry point mirroring
LlmConversationBuilder.conversation(). - cookie
- Isolate conversations by a cookie.
- default_
error_ body - The default error body for the given status code (mirrors the Java/Node/Python
defaultErrorBody). Exposed for parity/testing. - embedding
- Factory mirroring
EmbeddingResponse.embedding(). - header
- Isolate conversations by a request header.
- input_
tokens - Factory mirroring
Usage.inputTokens(n). - jitter
- Factory mirroring
StreamingPhysics.jitter(j). - llm_
failover - Entry point mirroring
LlmFailoverBuilder.llmFailover(). - llm_
mock - Entry point mirroring
LlmMockBuilder.llmMock(path). - output_
tokens - Factory mirroring
Usage.outputTokens(n). - query_
parameter - Isolate conversations by a query parameter.
- streaming_
physics - Factory mirroring
StreamingPhysics.streamingPhysics(). - tokens_
per_ second - Factory mirroring
StreamingPhysics.tokensPerSecond(n). - tool_
use - Factory mirroring
ToolUse.toolUse(name). - turn
- Entry point mirroring
TurnBuilderconstruction (used withLlmConversationBuilder::turn). - usage
- Factory mirroring
Usage.usage().