Class OllamaApi
java.lang.Object
org.springframework.ai.ollama.api.OllamaApi
Java Client for the Ollama API. https://ollama.ai
- Since:
- 0.8.0
- Author:
- Christian Tzolov, Thomas Vitale
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
Chat request object.static final record
Ollama chat response object.static final record
Deprecated, for removal: This API element is subject to removal in a future version.static final record
Deprecated, for removal: This API element is subject to removal in a future version.UseOllamaApi.EmbeddingsResponse
instead.static final record
Generate embeddings from a model.static final record
The response object returned from the /embedding endpoint.static final record
Deprecated, for removal: This API element is subject to removal in a future version.static final record
Deprecated, for removal: This API element is subject to removal in a future version.static final record
Chat message object. -
Field Summary
-
Constructor Summary
ConstructorDescriptionDefault constructor that uses the default localhost url.Crate a new OllamaApi instance with the given base url.OllamaApi
(String baseUrl, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.reactive.function.client.WebClient.Builder webClientBuilder) Crate a new OllamaApi instance with the given base url andRestClient.Builder
. -
Method Summary
Modifier and TypeMethodDescriptionchat
(OllamaApi.ChatRequest chatRequest) Generate the next message in a chat with a provided model.embed
(OllamaApi.EmbeddingsRequest embeddingsRequest) Generate embeddings from a model.embeddings
(OllamaApi.EmbeddingRequest embeddingRequest) Deprecated, for removal: This API element is subject to removal in a future version.Useembed(EmbeddingsRequest)
instead.generate
(OllamaApi.GenerateRequest completionRequest) Deprecated, for removal: This API element is subject to removal in a future version.Usechat(ChatRequest)
instead.reactor.core.publisher.Flux<OllamaApi.GenerateResponse>
generateStreaming
(OllamaApi.GenerateRequest completionRequest) Deprecated, for removal: This API element is subject to removal in a future version.UsestreamingChat(ChatRequest)
instead.reactor.core.publisher.Flux<OllamaApi.ChatResponse>
streamingChat
(OllamaApi.ChatRequest chatRequest) Streaming response for the chat completion request.
-
Field Details
-
PROVIDER_NAME
-
REQUEST_BODY_NULL_ERROR
- See Also:
-
-
Constructor Details
-
OllamaApi
public OllamaApi()Default constructor that uses the default localhost url. -
OllamaApi
Crate a new OllamaApi instance with the given base url.- Parameters:
baseUrl
- The base url of the Ollama server.
-
OllamaApi
public OllamaApi(String baseUrl, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.reactive.function.client.WebClient.Builder webClientBuilder) Crate a new OllamaApi instance with the given base url andRestClient.Builder
.- Parameters:
baseUrl
- The base url of the Ollama server.restClientBuilder
- TheRestClient.Builder
to use.
-
-
Method Details
-
generate
@Deprecated(since="1.0.0-M2", forRemoval=true) public OllamaApi.GenerateResponse generate(OllamaApi.GenerateRequest completionRequest) Deprecated, for removal: This API element is subject to removal in a future version.Usechat(ChatRequest)
instead.Generate a completion for the given prompt.- Parameters:
completionRequest
- Completion request.- Returns:
- Completion response.
-
generateStreaming
@Deprecated(since="1.0.0-M2", forRemoval=true) public reactor.core.publisher.Flux<OllamaApi.GenerateResponse> generateStreaming(OllamaApi.GenerateRequest completionRequest) Deprecated, for removal: This API element is subject to removal in a future version.UsestreamingChat(ChatRequest)
instead.Generate a streaming completion for the given prompt.- Parameters:
completionRequest
- Completion request. The request must set the stream property to true.- Returns:
- Completion response as a
Flux
stream.
-
chat
Generate the next message in a chat with a provided model. This is a streaming endpoint (controlled by the 'stream' request property), so there will be a series of responses. The final response object will include statistics and additional data from the request.- Parameters:
chatRequest
- Chat request.- Returns:
- Chat response.
-
streamingChat
public reactor.core.publisher.Flux<OllamaApi.ChatResponse> streamingChat(OllamaApi.ChatRequest chatRequest) Streaming response for the chat completion request.- Parameters:
chatRequest
- Chat request. The request must set the stream property to true.- Returns:
- Chat response as a
Flux
stream.
-
embed
Generate embeddings from a model.- Parameters:
embeddingsRequest
- Embedding request.- Returns:
- Embeddings response.
-
embeddings
@Deprecated(since="1.0.0-M2", forRemoval=true) public OllamaApi.EmbeddingResponse embeddings(OllamaApi.EmbeddingRequest embeddingRequest) Deprecated, for removal: This API element is subject to removal in a future version.Useembed(EmbeddingsRequest)
instead.Generate embeddings from a model.- Parameters:
embeddingRequest
- Embedding request.- Returns:
- Embedding response.
-
OllamaApi.EmbeddingsRequest
instead.