Class OllamaChatModel

java.lang.Object
io.agentscope.core.model.ChatModelBase
io.agentscope.extensions.model.ollama.OllamaChatModel
All Implemented Interfaces:
io.agentscope.core.model.Model

public class OllamaChatModel extends io.agentscope.core.model.ChatModelBase
AgentScope ChatModel implementation for Ollama. Provides integration with local Ollama instances via HTTP API.

This class implements the AgentScope ChatModelBase interface for Ollama models, supporting both synchronous and streaming chat operations, tool usage, and custom Ollama options.

Key features:

  • Support for both GenerateOptions and Ollama-specific OllamaOptions
  • Integration with AgentScope's message formatting system
  • Streaming response support via Project Reactor's Flux
  • Tool usage and function calling capabilities
  • Configurable message formatters (OllamaChatFormatter, OllamaMultiAgentFormatter)
  • Automatic timeout and retry mechanisms
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    OllamaChatModel(String modelName, String baseUrl, OllamaOptions defaultOptions)
    Creates a new OllamaChatModel with default settings.
    OllamaChatModel(String modelName, String baseUrl, OllamaOptions defaultOptions, io.agentscope.core.formatter.Formatter<OllamaMessage,OllamaResponse,OllamaRequest> formatter, io.agentscope.core.model.transport.HttpTransport httpTransport)
    Creates a new OllamaChatModel.
    OllamaChatModel(String modelName, String baseUrl, OllamaOptions defaultOptions, io.agentscope.core.formatter.Formatter<OllamaMessage,OllamaResponse,OllamaRequest> formatter, io.agentscope.core.model.transport.HttpTransport httpTransport, boolean stream)
    Creates a new OllamaChatModel with an explicit streaming mode.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new builder for OllamaChatModel.
    io.agentscope.core.model.ChatResponse
    chat(List<io.agentscope.core.message.Msg> messages, io.agentscope.core.model.GenerateOptions options)
    Chat with the model using default options.
    io.agentscope.core.model.ChatResponse
    chat(List<io.agentscope.core.message.Msg> messages, OllamaOptions options)
    Chat with the model using Ollama-specific options.
    protected reactor.core.publisher.Flux<io.agentscope.core.model.ChatResponse>
    doStream(List<io.agentscope.core.message.Msg> messages, List<io.agentscope.core.model.ToolSchema> tools, io.agentscope.core.model.GenerateOptions options)
     
     
    boolean
     

    Methods inherited from class io.agentscope.core.model.ChatModelBase

    getContextWindowSize, setContextWindowSize, setNativeStructuredOutput, setNativeStructuredOutputWithTools, stream, supportsNativeStructuredOutput, supportsNativeStructuredOutputWithTools

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • OllamaChatModel

      public OllamaChatModel(String modelName, String baseUrl, OllamaOptions defaultOptions, io.agentscope.core.formatter.Formatter<OllamaMessage,OllamaResponse,OllamaRequest> formatter, io.agentscope.core.model.transport.HttpTransport httpTransport)
      Creates a new OllamaChatModel.
      Parameters:
      modelName - The name of the model to use (e.g., "llama2", "mistral").
      baseUrl - The base URL of the Ollama server (e.g. "http://localhost:11434").
      defaultOptions - Default configuration options.
      formatter - The message formatter to use.
      httpTransport - The HTTP transport to use.
    • OllamaChatModel

      public OllamaChatModel(String modelName, String baseUrl, OllamaOptions defaultOptions, io.agentscope.core.formatter.Formatter<OllamaMessage,OllamaResponse,OllamaRequest> formatter, io.agentscope.core.model.transport.HttpTransport httpTransport, boolean stream)
      Creates a new OllamaChatModel with an explicit streaming mode.
    • OllamaChatModel

      public OllamaChatModel(String modelName, String baseUrl, OllamaOptions defaultOptions)
      Creates a new OllamaChatModel with default settings.
      Parameters:
      modelName - The name of the model to use.
      baseUrl - The base URL of the Ollama server.
      defaultOptions - Default configuration options.
  • Method Details

    • builder

      public static OllamaChatModel.Builder builder()
      Creates a new builder for OllamaChatModel.
      Returns:
      A new Builder instance.
    • getModelName

      public String getModelName()
    • isStreaming

      public boolean isStreaming()
    • chat

      public io.agentscope.core.model.ChatResponse chat(List<io.agentscope.core.message.Msg> messages, OllamaOptions options)
      Chat with the model using Ollama-specific options.

      This method uses Ollama-specific options directly without conversion.

      Parameters:
      messages - The messages to send.
      options - The Ollama-specific options.
      Returns:
      The chat response.
    • chat

      public io.agentscope.core.model.ChatResponse chat(List<io.agentscope.core.message.Msg> messages, io.agentscope.core.model.GenerateOptions options)
      Chat with the model using default options.
      Parameters:
      messages - The messages to send.
      options - The generation options.
      Returns:
      The chat response.
    • doStream

      protected reactor.core.publisher.Flux<io.agentscope.core.model.ChatResponse> doStream(List<io.agentscope.core.message.Msg> messages, List<io.agentscope.core.model.ToolSchema> tools, io.agentscope.core.model.GenerateOptions options)
      Specified by:
      doStream in class io.agentscope.core.model.ChatModelBase