Class OllamaProvider

java.lang.Object
dev.agenor.adapters.llm.ollama.OllamaProvider
All Implemented Interfaces:
LLMProvider

public class OllamaProvider extends Object implements LLMProvider
  • Method Details

    • chat

      public CompletableFuture<LLMResponse> chat(LLMRequest request)
      Description copied from interface: LLMProvider
      Send a chat completion request to the LLM.

      This is the primary method for interacting with the LLM. It sends a request containing messages and configuration, and returns a response asynchronously.

      Specified by:
      chat in interface LLMProvider
      Returns:
      CompletableFuture containing the LLM response
    • chatStream

      public CompletableFuture<Void> chatStream(LLMRequest request, Consumer<StreamingChunk> chunkHandler)
      Description copied from interface: LLMProvider
      Stream a chat completion request to the LLM.

      Similar to LLMProvider.chat(LLMRequest), but provides streaming updates as the response is generated. This is useful for long responses where you want to show incremental progress to users.

      Example usage:

      
       provider.chatStream(request, chunk -> {
           System.out.print(chunk.content());
       }).thenRun(() -> {
           System.out.println("\nStreaming complete");
       });
       
      Specified by:
      chatStream in interface LLMProvider
      Returns:
      CompletableFuture that completes when streaming is finished
    • getAvailableModels

      public CompletableFuture<List<String>> getAvailableModels()
      Description copied from interface: LLMProvider
      Get the list of available models from this provider.

      Returns a list of model identifiers that can be used with this provider. Model names are provider-specific (e.g., "gpt-4", "claude-3-opus", "llama2").

      Specified by:
      getAvailableModels in interface LLMProvider
      Returns:
      CompletableFuture containing list of available model names
    • getProviderName

      public String getProviderName()
      Description copied from interface: LLMProvider
      Get the name of this provider.

      Returns a human-readable identifier for this provider, such as "OpenAI", "Anthropic", or "Ollama".

      Specified by:
      getProviderName in interface LLMProvider
      Returns:
      the provider name
    • supportsFunctionCalling

      public boolean supportsFunctionCalling()
      Description copied from interface: LLMProvider
      Check if this provider supports function calling.

      Function calling (also known as tool use) allows the LLM to call external functions to gather information or perform actions. Not all providers or models support this feature.

      Specified by:
      supportsFunctionCalling in interface LLMProvider
      Returns:
      true if function calling is supported, false otherwise
    • supportsStreaming

      public boolean supportsStreaming()
      Description copied from interface: LLMProvider
      Check if this provider supports streaming responses.

      Streaming allows incremental delivery of responses as they are generated. Most modern LLM providers support this feature.

      Specified by:
      supportsStreaming in interface LLMProvider
      Returns:
      true if streaming is supported, false otherwise
    • getDefaultModel

      public String getDefaultModel()
      Description copied from interface: LLMProvider
      Get the default model for this provider.

      Returns a reasonable default model that can be used if the user doesn't specify one. This should be a balanced model that works well for general purposes.

      Specified by:
      getDefaultModel in interface LLMProvider
      Returns:
      the default model name, or null if no default is available
    • builder

      public static OllamaProvider.Builder builder()