Class OllamaClient
java.lang.Object
com.developer.nefarious.zjoule.plugin.chat.ollama.OllamaClient
- All Implemented Interfaces:
IAIClient
A client implementation for interacting with the Ollama AI chat system.
The OllamaClient
facilitates chat interactions by sending requests
to an Ollama chat API endpoint and processing responses. It also manages
message history using an in-memory storage system.
-
Constructor Summary
ConstructorsConstructorDescriptionOllamaClient
(IMemoryMessageHistory memoryMessageHistory, IMemoryObject<String> memoryOllamaEndpoint, IOllamaClientHelper ollamaClientHelper) Constructs anOllamaClient
with the specified dependencies. -
Method Summary
Modifier and TypeMethodDescriptionchatCompletion
(List<IChatMessage> messages) Sends a chat completion request to the Ollama API.createMessage
(Role role, String userPrompt) Creates a new chat message with the specified role and user input.Retrieves the chat message history stored in memory.void
setMessageHistory
(List<IChatMessage> chatMessages) Stores the given chat message history in memory.
-
Constructor Details
-
OllamaClient
public OllamaClient(IMemoryMessageHistory memoryMessageHistory, IMemoryObject<String> memoryOllamaEndpoint, IOllamaClientHelper ollamaClientHelper) Constructs anOllamaClient
with the specified dependencies.- Parameters:
memoryMessageHistory
- the in-memory storage for chat message history.memoryOllamaEndpoint
- the in-memory storage containing the Ollama chat API endpoint.ollamaClientHelper
- the helper class for handling request and response transformations.
-
-
Method Details
-
chatCompletion
public IChatMessage chatCompletion(List<IChatMessage> messages) throws IOException, InterruptedException Sends a chat completion request to the Ollama API.This method constructs a request using the provided chat messages and sends it to the configured API endpoint. It then processes the response and returns the generated AI message.
- Specified by:
chatCompletion
in interfaceIAIClient
- Parameters:
messages
- the list of chat messages forming the conversation history.- Returns:
- the AI-generated response as an
IChatMessage
. - Throws:
IOException
- if an I/O error occurs when sending the request.InterruptedException
- if the request is interrupted while waiting for a response.
-
createMessage
Creates a new chat message with the specified role and user input.- Specified by:
createMessage
in interfaceIAIClient
- Parameters:
role
- the role of the message (e.g., user or assistant).userPrompt
- the message content.- Returns:
- an instance of
IChatMessage
representing the user input.
-
getMessageHistory
Retrieves the chat message history stored in memory.- Specified by:
getMessageHistory
in interfaceIAIClient
- Returns:
- a list of
IChatMessage
representing the chat history, or an empty list if no history is available.
-
setMessageHistory
Stores the given chat message history in memory.- Specified by:
setMessageHistory
in interfaceIAIClient
- Parameters:
chatMessages
- the list of chat messages to save.
-