Class OllamaClientHelper
java.lang.Object
com.developer.nefarious.zjoule.plugin.chat.ollama.OllamaClientHelper
- All Implemented Interfaces:
IOllamaClientHelper
A helper class for constructing requests and processing responses for the Ollama AI chat system.
The OllamaClientHelper
is responsible for serializing chat request bodies,
deserializing chat responses, and retrieving the currently selected Ollama model.
-
Constructor Summary
ConstructorsConstructorDescriptionOllamaClientHelper
(IMemoryObject<OllamaModel> memoryOllamaModel) Constructs anOllamaClientHelper
with the specified memory storage. -
Method Summary
Modifier and TypeMethodDescriptionconvertResponseToObject
(String serializedResponseBody) Converts a serialized JSON response body from the Ollama service into anIChatMessage
.createRequestBody
(List<IChatMessage> messages) Creates an HTTP request body for a chat completion request to the Ollama service.
-
Constructor Details
-
OllamaClientHelper
Constructs anOllamaClientHelper
with the specified memory storage.- Parameters:
memoryOllamaModel
- the in-memory storage containing the selected Ollama model.
-
-
Method Details
-
convertResponseToObject
Converts a serialized JSON response body from the Ollama service into anIChatMessage
. The method deserializes the response and extracts the first message returned by the AI.- Specified by:
convertResponseToObject
in interfaceIOllamaClientHelper
- Parameters:
serializedResponseBody
- the JSON response body as aString
.- Returns:
- the first
IChatMessage
extracted from the response.
-
createRequestBody
Creates an HTTP request body for a chat completion request to the Ollama service. The request body includes parameters such as:- Chat messages providing the context for the conversation.
- Maximum number of tokens allowed for the response.
- Temperature, frequency penalty, and presence penalty settings.
- Stop sequences for terminating the response.
- Specified by:
createRequestBody
in interfaceIOllamaClientHelper
- Parameters:
messages
- a list ofIChatMessage
objects representing the chat context.- Returns:
- a
HttpRequest.BodyPublisher
object containing the serialized request body.
-