类 OllamaChatModel

java.lang.Object
io.agentscope.core.model.ChatModelBase
io.agentscope.core.model.OllamaChatModel
所有已实现的接口:
Model

public class OllamaChatModel extends 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
  • 构造器详细资料

    • OllamaChatModel

      public OllamaChatModel(String modelName, String baseUrl, OllamaOptions defaultOptions, Formatter<OllamaMessage,OllamaResponse,OllamaRequest> formatter, HttpTransport httpTransport)
      Creates a new OllamaChatModel.
      参数:
      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)
      Creates a new OllamaChatModel with default settings.
      参数:
      modelName - The name of the model to use.
      baseUrl - The base URL of the Ollama server.
      defaultOptions - Default configuration options.
  • 方法详细资料

    • builder

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

      public String getModelName()
      从接口复制的说明: Model
      Get model name for logging and identification.
      返回:
      model name
    • chat

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

      This method uses Ollama-specific options directly without conversion.

      参数:
      messages - The messages to send.
      options - The Ollama-specific options.
      返回:
      The chat response.
    • chat

      public ChatResponse chat(List<Msg> messages, GenerateOptions options)
      Chat with the model using default options.
      参数:
      messages - The messages to send.
      options - The generation options.
      返回:
      The chat response.
    • doStream

      protected reactor.core.publisher.Flux<ChatResponse> doStream(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options)
      从类复制的说明: ChatModelBase
      Internal implementation for streaming chat completion responses. Subclasses must implement their specific logic here.
      指定者:
      doStream 在类中 ChatModelBase
      参数:
      messages - AgentScope messages to send to the model
      tools - Optional list of tool schemas (null or empty if no tools)
      options - Optional generation options (null to use defaults)
      返回:
      Flux stream of chat responses