java.lang.Object
com.developer.nefarious.zjoule.plugin.chat.ollama.OllamaClient
All Implemented Interfaces:
IAIClient

public class OllamaClient extends Object implements 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 Details

    • OllamaClient

      public OllamaClient(IMemoryMessageHistory memoryMessageHistory, IMemoryObject<String> memoryOllamaEndpoint, IOllamaClientHelper ollamaClientHelper)
      Constructs an OllamaClient 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 interface IAIClient
      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

      public IChatMessage createMessage(Role role, String userPrompt)
      Creates a new chat message with the specified role and user input.
      Specified by:
      createMessage in interface IAIClient
      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

      public List<IChatMessage> getMessageHistory()
      Retrieves the chat message history stored in memory.
      Specified by:
      getMessageHistory in interface IAIClient
      Returns:
      a list of IChatMessage representing the chat history, or an empty list if no history is available.
    • setMessageHistory

      public void setMessageHistory(List<IChatMessage> chatMessages)
      Stores the given chat message history in memory.
      Specified by:
      setMessageHistory in interface IAIClient
      Parameters:
      chatMessages - the list of chat messages to save.