Class AbstractLlmClient

java.lang.Object
org.mockserver.llm.client.AbstractLlmClient
All Implemented Interfaces:
LlmClient
Direct Known Subclasses:
AnthropicLlmClient, GeminiLlmClient, OllamaLlmClient, OpenAiLlmClient, OpenAiResponsesLlmClient

public abstract class AbstractLlmClient extends Object implements LlmClient
Shared scaffolding for LlmClient implementations: URL parsing, base-request construction (method, path, host, scheme, custom headers) and a shared ObjectMapper. Subclasses add provider-specific auth, request body, and response parsing.
  • Field Details

    • OBJECT_MAPPER

      protected static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPER
  • Constructor Details

    • AbstractLlmClient

      public AbstractLlmClient()
  • Method Details

    • resolveBaseUrl

      protected String resolveBaseUrl(LlmBackend backend, String defaultBaseUrl)
      Resolve the effective base URL: the backend's value if set, else the provider default.
    • resolveModel

      protected String resolveModel(LlmBackend backend, String defaultModel)
      Resolve the effective model: the backend's value if set, else the provider default.
    • postJson

      protected HttpRequest postJson(LlmBackend backend, String baseUrl, String path, String jsonBody)
      Build a POST request to baseUrl + path, parsing the URL into host, port, and scheme so the transport can route it. Applies a JSON content-type and any caller-supplied headers escape hatch.
    • readBody

      protected com.fasterxml.jackson.databind.JsonNode readBody(HttpResponse response)
      Parse a response body into a JSON tree. Throws on a malformed body; the caller (LlmCompletionService) treats that fail-closed.
    • writeJson

      protected String writeJson(com.fasterxml.jackson.databind.JsonNode node)
      Serialize a JSON node to a string, wrapping the checked exception as unchecked (the node is always well-formed here).
    • appendRoleContentMessages

      protected void appendRoleContentMessages(com.fasterxml.jackson.databind.node.ArrayNode messagesArray, ParsedConversation prompt, String systemRole, String userRole, String assistantRole, String toolRole)
      Append the conversation's messages to messagesArray as {role, content} objects using the given role names. Messages with no text content are skipped (the runtime client carries prompt text; outbound tool-call round-tripping is out of scope for this SPI).