Package org.mockserver.llm.codec
Class OllamaCodec
- java.lang.Object
-
- org.mockserver.llm.codec.OllamaCodec
-
- All Implemented Interfaces:
ProviderCodec
public class OllamaCodec extends Object implements ProviderCodec
Codec for Ollama/api/chatendpoint (version ollama-2025).Ollama uses a distinct JSON shape with a top-level
messageobject (not an array of choices). Token counts are exposed asprompt_eval_countandeval_count.Streaming limitation: Ollama's native wire format is NDJSON (newline-delimited JSON), not SSE. This codec represents each chunk as an
SseEventwith the JSON line as thedatafield. When MockServer sends them, the SSE handler emitsdata: <json>\n\nwhich is close enough for most SDK clients to parse. Strict NDJSON support is out of scope.Tool calls use Ollama 0.3+ format where
argumentsis a JSON object (not a JSON-as-string like OpenAI).
-
-
Constructor Summary
Constructors Constructor Description OllamaCodec()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringapiVersion()ParsedConversationdecode(HttpRequest request)HttpResponseencode(Completion completion, String model)HttpResponseencodeEmbedding(EmbeddingResponse embedding, String input)List<SseEvent>encodeStreaming(Completion completion, String model, StreamingPhysics physics)Providerprovider()
-
-
-
Method Detail
-
provider
public Provider provider()
- Specified by:
providerin interfaceProviderCodec
-
apiVersion
public String apiVersion()
- Specified by:
apiVersionin interfaceProviderCodec
-
encode
public HttpResponse encode(Completion completion, String model)
- Specified by:
encodein interfaceProviderCodec
-
encodeStreaming
public List<SseEvent> encodeStreaming(Completion completion, String model, StreamingPhysics physics)
- Specified by:
encodeStreamingin interfaceProviderCodec
-
decode
public ParsedConversation decode(HttpRequest request)
- Specified by:
decodein interfaceProviderCodec
-
encodeEmbedding
public HttpResponse encodeEmbedding(EmbeddingResponse embedding, String input)
- Specified by:
encodeEmbeddingin interfaceProviderCodec
-
-