Class Completion


public class Completion extends ObjectWithJsonToString
  • Constructor Details

    • Completion

      public Completion()
  • Method Details

    • completion

      public static Completion completion()
    • withText

      public Completion withText(String text)
    • getText

      public String getText()
    • withToolCalls

      public Completion withToolCalls(List<ToolUse> toolCalls)
    • withToolCalls

      public Completion withToolCalls(ToolUse... toolCalls)
    • withToolCall

      public Completion withToolCall(ToolUse toolCall)
    • getToolCalls

      public List<ToolUse> getToolCalls()
    • withStopReason

      public Completion withStopReason(String stopReason)
    • getStopReason

      public String getStopReason()
    • withUsage

      public Completion withUsage(Usage usage)
    • getUsage

      public Usage getUsage()
    • withStreaming

      public Completion withStreaming(Boolean streaming)
    • streaming

      public Completion streaming()
    • getStreaming

      public Boolean getStreaming()
    • withStreamingPhysics

      public Completion withStreamingPhysics(StreamingPhysics streamingPhysics)
    • withStreamingPhysics

      public Completion withStreamingPhysics(Object... parts)
      Compose streaming physics from independent values. Accepts any combination of Delay (interpreted as time-to-first-token) and StreamingPhysics fragments (each typically carrying a single field — e.g. tokensPerSecond(50) or jitter(0.2)). Non-null fields from the fragments are merged left-to-right onto a single StreamingPhysics instance which is then assigned to this completion. Calling implicitly enables streaming.
    • getStreamingPhysics

      public StreamingPhysics getStreamingPhysics()
    • withOutputSchema

      public Completion withOutputSchema(String outputSchema)
      Optional JSON Schema (as a JSON string) that this completion's text is expected to conform to. When set, the LLM response handler validates the configured text against the schema as the response is encoded. Validation is fail-soft: a mismatch does not alter the response body — it adds an x-mockserver-structured-output-invalid diagnostic header and logs a warning, so a deliberately non-conforming fixture still returns exactly as configured while malformed structured-output fixtures are surfaced.
    • getOutputSchema

      public String getOutputSchema()
    • withEnforceOutputSchema

      public Completion withEnforceOutputSchema(Boolean enforceOutputSchema)
      Opt-in strict structured-output enforcement. When true and an outputSchema is declared, the LLM response handler enforces conformance instead of merely flagging it: if the configured text does not conform to the schema, the handler fails loudly with a provider-correct error response rather than returning the non-conforming body.

      This models real providers' strict response_format: json_schema mode, where the provider guarantees schema-valid output — so a non-conforming fixture is a configuration error that should surface rather than pass silently.

      When unset or false (the default), behaviour is unchanged: a mismatch is fail-soft — the body is returned as configured and only the x-mockserver-structured-output-invalid diagnostic header + a warning log are added. Has no effect without an outputSchema.

    • enforceOutputSchema

      public Completion enforceOutputSchema()
    • getEnforceOutputSchema

      public Boolean getEnforceOutputSchema()
    • withModel

      public Completion withModel(String model)
      Optional model identifier extracted from the provider response. Set by parseCompletionResponse implementations so the caller can read the model without re-parsing the response body.
    • getModel

      public String getModel()
    • withToolChoice

      public Completion withToolChoice(String toolChoice)
      Optional tool-choice directive modelling the request's tool_choice for this mocked exchange. Recognised values: auto (model decides), none (never call a tool), required (must call a tool), or a named tool. When set to required and at least one tool call is configured, the encoded response's finish_reason is forced to tool_calls. Absent toolChoice leaves the existing finish-reason behaviour unchanged.
    • getToolChoice

      public String getToolChoice()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class ObjectWithReflectiveEqualsHashCodeToString
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class ObjectWithReflectiveEqualsHashCodeToString