OllamaChatModel
public class OllamaChatModel extends ChatModelBase
io/agentscope/extensions/model/ollama/OllamaChatModel.java:63–425Ollama 聊天模型,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.ollama 包,继承自 ChatModelBase。核心成员包括 builder、getModelName、isStreaming、chat、doStream、OllamaChatModel。
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
| 类Class | 类型Kind | 说明Description |
|---|---|---|
Builder | 类class | 构建器,用于构建并配置目标实例。 A class in io.agentscope.extensions.model.ollama that talks to model services and returns generated or embedded output. |
构造器摘要Constructor Summary
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public static Builder builder()static | 创建新的构建器用于 OllamaChatModel。 Creates a new builder for OllamaChatModel. |
public String getModelName() | 获取模型名称。 Returns the model name. |
public boolean isStreaming() | 判断是否流式。 Returns whether the streaming. |
public ChatResponse chat(List<Msg> messages, OllamaOptions options) | 执行聊天相关操作。 Chat with the model using Ollama-specific options. |
public ChatResponse chat(List<Msg> messages, GenerateOptions options) | 执行聊天相关操作。 Chat with the model using default options. |
protected Flux<ChatResponse> doStream(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options) | 以流式方式执行并返回结果。 Performs the do stream operation. |
构造器详情Constructor Detail
OllamaChatModel
public OllamaChatModel(String modelName, String baseUrl, OllamaOptions defaultOptions, Formatter<OllamaMessage, OllamaResponse, OllamaRequest> formatter, HttpTransport httpTransport)
创建新的OllamaChatModel。
Creates a new OllamaChatModel.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelName | String | 模型名称(类型 `String`)。The name of the model to use (e.g., "llama2", "mistral"). |
baseUrl | String | 基类 URL(类型 `String`)。The base URL of the Ollama server (e.g. "http://localhost:11434"). |
defaultOptions | OllamaOptions | 默认选项(类型 `OllamaOptions`)。Default configuration options. |
formatter | Formatter<OllamaMessage, OllamaResponse, OllamaRequest> | 消息格式化器到使用。The message formatter to use. |
httpTransport | HttpTransport | HTTP 传输层到使用。The HTTP transport to use. |
io/agentscope/extensions/model/ollama/OllamaChatModel.java:81–88OllamaChatModel
public OllamaChatModel(String modelName, String baseUrl, OllamaOptions defaultOptions, Formatter<OllamaMessage, OllamaResponse, OllamaRequest> formatter, HttpTransport httpTransport, boolean stream)
初始化 OllamaChatModel 实例。
Creates a new OllamaChatModel with an explicit streaming mode.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelName | String | 模型名称(类型 `String`)。The model name. |
baseUrl | String | 基类 URL(类型 `String`)。The base url. |
defaultOptions | OllamaOptions | 默认选项(类型 `OllamaOptions`)。The default options. |
formatter | Formatter<OllamaMessage, OllamaResponse, OllamaRequest> | 格式化器(类型 `Formatter`)。The formatter. |
httpTransport | HttpTransport | HTTP 传输层(类型 `HttpTransport`)。The http transport. |
stream | boolean | 流(类型 `boolean`)。The stream. |
io/agentscope/extensions/model/ollama/OllamaChatModel.java:93–109OllamaChatModel
public OllamaChatModel(String modelName, String baseUrl, OllamaOptions defaultOptions)
创建新的OllamaChatModel 使用默认设置。
Creates a new OllamaChatModel with default settings.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelName | String | 模型到使用的名称。The name of the model to use. |
baseUrl | String | 基类 URL(类型 `String`)。The base URL of the Ollama server. |
defaultOptions | OllamaOptions | 默认选项(类型 `OllamaOptions`)。Default configuration options. |
io/agentscope/extensions/model/ollama/OllamaChatModel.java:118–120方法详情Method Detail
builder
public static Builder builder()
创建新的构建器用于 OllamaChatModel。
Creates a new builder for OllamaChatModel.
Builderio/agentscope/extensions/model/ollama/OllamaChatModel.java:127–129getModelName
public String getModelName()
获取模型名称。
Returns the model name.
Stringio/agentscope/extensions/model/ollama/OllamaChatModel.java:131–134isStreaming
public boolean isStreaming()
判断是否流式。
Returns whether the streaming.
booleanio/agentscope/extensions/model/ollama/OllamaChatModel.java:136–138chat
public ChatResponse chat(List<Msg> messages, OllamaOptions options)
执行聊天相关操作。
Chat with the model using Ollama-specific options.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
messages | List<Msg> | 消息到发送。The messages to send. |
options | OllamaOptions | 选项(类型 `OllamaOptions`)。The Ollama-specific options. |
ChatResponseio/agentscope/extensions/model/ollama/OllamaChatModel.java:149–151chat
public ChatResponse chat(List<Msg> messages, GenerateOptions options)
执行聊天相关操作。
Chat with the model using default options.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
messages | List<Msg> | 消息到发送。The messages to send. |
options | GenerateOptions | 选项(类型 `GenerateOptions`)。The generation options. |
ChatResponseio/agentscope/extensions/model/ollama/OllamaChatModel.java:160–162doStream
protected Flux<ChatResponse> doStream(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options)
以流式方式执行并返回结果。
Performs the do stream operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
messages | List<Msg> | 消息列表(类型 `List`)。The messages. |
tools | List<ToolSchema> | 工具列表(类型 `List`)。The tools. |
options | GenerateOptions | 选项(类型 `GenerateOptions`)。The options. |
Flux<ChatResponse>io/agentscope/extensions/model/ollama/OllamaChatModel.java:164–175嵌套类详情Nested Class Detail
Builder
public static class Builder构建器,用于构建并配置目标实例。位于 io.agentscope.extensions.model.ollama 包。核心成员包括 modelName、baseUrl、stream、defaultOptions、formatter、httpTransport。
A class in io.agentscope.extensions.model.ollama that talks to model services and returns generated or embedded output. Declared in io.agentscope.extensions.model.ollama.