Package org.mockserver.llm.client
Class AbstractLlmClient
java.lang.Object
org.mockserver.llm.client.AbstractLlmClient
- All Implemented Interfaces:
LlmClient
- Direct Known Subclasses:
AnthropicLlmClient,GeminiLlmClient,OllamaLlmClient,OpenAiLlmClient,OpenAiResponsesLlmClient
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 Summary
FieldsModifier and TypeFieldDescriptionprotected static final com.fasterxml.jackson.databind.ObjectMapper -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendRoleContentMessages(com.fasterxml.jackson.databind.node.ArrayNode messagesArray, ParsedConversation prompt, String systemRole, String userRole, String assistantRole, String toolRole) Append the conversation's messages tomessagesArrayas{role, content}objects using the given role names.protected HttpRequestpostJson(LlmBackend backend, String baseUrl, String path, String jsonBody) Build a POST request tobaseUrl + path, parsing the URL into host, port, and scheme so the transport can route it.protected com.fasterxml.jackson.databind.JsonNodereadBody(HttpResponse response) Parse a response body into a JSON tree.protected StringresolveBaseUrl(LlmBackend backend, String defaultBaseUrl) Resolve the effective base URL: the backend's value if set, else the provider default.protected StringresolveModel(LlmBackend backend, String defaultModel) Resolve the effective model: the backend's value if set, else the provider default.protected StringwriteJson(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).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.mockserver.llm.client.LlmClient
buildCompletionRequest, parseCompletionResponse, provider
-
Field Details
-
OBJECT_MAPPER
protected static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPER
-
-
Constructor Details
-
AbstractLlmClient
public AbstractLlmClient()
-
-
Method Details
-
resolveBaseUrl
Resolve the effective base URL: the backend's value if set, else the provider default. -
resolveModel
Resolve the effective model: the backend's value if set, else the provider default. -
postJson
Build a POST request tobaseUrl + path, parsing the URL into host, port, and scheme so the transport can route it. Applies a JSON content-type and any caller-suppliedheadersescape hatch. -
readBody
Parse a response body into a JSON tree. Throws on a malformed body; the caller (LlmCompletionService) treats that fail-closed. -
writeJson
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 tomessagesArrayas{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).
-