Class OllamaHttpClient
java.lang.Object
io.agentscope.extensions.model.ollama.OllamaHttpClient
HTTP client for Ollama API.
This client handles communication with Ollama's chat and embedding APIs. It provides both synchronous and asynchronous (streaming) request capabilities with proper JSON serialization/deserialization and error handling.
Features:
- Synchronous and streaming request support
- NDJSON stream parsing for streaming responses
- Automatic JSON serialization/deserialization with snake_case naming
- Proper error handling with detailed exception information
- Configurable base URL and HTTP transport
Default base URL is http://localhost:11434, which is the standard Ollama server address.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for OllamaHttpClient.static classException thrown when Ollama HTTP operations fail. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionOllamaHttpClient(io.agentscope.core.model.transport.HttpTransport transport, String baseUrl) Create a new OllamaHttpClient. -
Method Summary
Modifier and TypeMethodDescriptionstatic OllamaHttpClient.Builderbuilder()Create a new builder for OllamaHttpClient.Make a synchronous API call to specific endpoint.<T> TMake a synchronous API call to specific endpoint with custom response type.chat(OllamaRequest request) Make a synchronous Chat API call.voidclose()Close the transport.embed(OllamaEmbeddingRequest request) Make a synchronous Embed API call.Get the base URL.reactor.core.publisher.Flux<OllamaResponse>stream(OllamaRequest request) Make a streaming Chat API call.
-
Field Details
-
DEFAULT_BASE_URL
Default base URL for Ollama API.- See Also:
-
CHAT_ENDPOINT
Chat API endpoint.- See Also:
-
EMBED_ENDPOINT
Embed API endpoint.- See Also:
-
-
Constructor Details
-
OllamaHttpClient
Create a new OllamaHttpClient.- Parameters:
transport- the HTTP transport to usebaseUrl- the base URL (null for default)
-
-
Method Details
-
chat
Make a synchronous Chat API call.- Parameters:
request- the Ollama request- Returns:
- the Ollama response
-
embed
Make a synchronous Embed API call.- Parameters:
request- the Embed request- Returns:
- the Embed response
-
call
Make a synchronous API call to specific endpoint.- Parameters:
endpoint- the API endpointrequest- the request object- Returns:
- the Ollama response
-
call
Make a synchronous API call to specific endpoint with custom response type.- Type Parameters:
T- the response type- Parameters:
endpoint- the API endpointrequest- the request objectresponseType- the response class- Returns:
- the response object
-
stream
Make a streaming Chat API call.- Parameters:
request- the Ollama request- Returns:
- a Flux of Ollama responses
-
getBaseUrl
Get the base URL.- Returns:
- the base URL
-
close
public void close()Close the transport. -
builder
Create a new builder for OllamaHttpClient.- Returns:
- a new Builder instance
-