Package org.mockserver.llm.codec
Class OllamaCodec
java.lang.Object
org.mockserver.llm.codec.OllamaCodec
- All Implemented Interfaces:
ProviderCodec
Codec for Ollama
/api/chat endpoint (version ollama-2025).
Ollama uses a distinct JSON shape with a top-level message object
(not an array of choices). Token counts are exposed as prompt_eval_count
and eval_count.
Streaming format: Ollama's native wire format is NDJSON
(newline-delimited JSON, application/x-ndjson), not SSE. Each
streaming chunk is a single JSON object followed by a newline character
(<json>\n). This codec internally represents chunks as
SseEvent objects (reusing the existing data/delay model), but
declares StreamingFormat.NDJSON via streamingFormat() so
that the downstream write handler emits raw NDJSON framing instead of SSE
data: prefixes.
Tool calls use Ollama 0.3+ format where arguments is a JSON object
(not a JSON-as-string like OpenAI).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondecode(HttpRequest request) encode(Completion completion, String model) encodeEmbedding(EmbeddingResponse embedding, String input) encodeStreaming(Completion completion, String model, StreamingPhysics physics) provider()The wire format this provider uses for streaming responses.
-
Constructor Details
-
OllamaCodec
public OllamaCodec()
-
-
Method Details
-
provider
- Specified by:
providerin interfaceProviderCodec
-
apiVersion
- Specified by:
apiVersionin interfaceProviderCodec
-
streamingFormat
Description copied from interface:ProviderCodecThe wire format this provider uses for streaming responses. Defaults toStreamingFormat.SSE; override for providers that use a different format (e.g. Ollama uses NDJSON).- Specified by:
streamingFormatin interfaceProviderCodec
-
encode
- Specified by:
encodein interfaceProviderCodec
-
encodeStreaming
public List<SseEvent> encodeStreaming(Completion completion, String model, StreamingPhysics physics) - Specified by:
encodeStreamingin interfaceProviderCodec
-
decode
- Specified by:
decodein interfaceProviderCodec
-
encodeEmbedding
- Specified by:
encodeEmbeddingin interfaceProviderCodec
-