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
GenerateOptionsand Ollama-specificOllamaOptions - 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 -
Constructor Summary
ConstructorsConstructorDescriptionOllamaChatModel(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 TypeMethodDescriptionstatic OllamaChatModel.Builderbuilder()Creates a new builder for OllamaChatModel.io.agentscope.core.model.ChatResponsechat(List<io.agentscope.core.message.Msg> messages, io.agentscope.core.model.GenerateOptions options) Chat with the model using default options.io.agentscope.core.model.ChatResponsechat(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) booleanMethods inherited from class io.agentscope.core.model.ChatModelBase
getContextWindowSize, setContextWindowSize, setNativeStructuredOutput, setNativeStructuredOutputWithTools, stream, supportsNativeStructuredOutput, supportsNativeStructuredOutputWithTools
-
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
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
Creates a new builder for OllamaChatModel.- Returns:
- A new Builder instance.
-
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:
doStreamin classio.agentscope.core.model.ChatModelBase
-