AS AgentScopeAPI 手册 / API Reference

OllamaChatModel

public class OllamaChatModel extends ChatModelBase
源码Source io/agentscope/extensions/model/ollama/OllamaChatModel.java:63–425

Ollama 聊天模型,与模型服务通信并返回生成或向量化结果。位于 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 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

类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

构造器Constructor说明Description
public OllamaChatModel(String modelName, String baseUrl, OllamaOptions defaultOptions, Formatter<OllamaMessage, OllamaResponse, OllamaRequest> formatter, HttpTransport httpTransport)
创建新的OllamaChatModel。
Creates a new OllamaChatModel.
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.
public OllamaChatModel(String modelName, String baseUrl, OllamaOptions defaultOptions)
创建新的OllamaChatModel 使用默认设置。
Creates a new OllamaChatModel with default settings.

方法摘要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.

参数Parameters
名称Name类型Type说明Description
modelNameString模型名称(类型 `String`)。The name of the model to use (e.g., "llama2", "mistral").
baseUrlString基类 URL(类型 `String`)。The base URL of the Ollama server (e.g. "http://localhost:11434").
defaultOptionsOllamaOptions默认选项(类型 `OllamaOptions`)。Default configuration options.
formatterFormatter<OllamaMessage, OllamaResponse, OllamaRequest>消息格式化器到使用。The message formatter to use.
httpTransportHttpTransportHTTP 传输层到使用。The HTTP transport to use.
源码Source io/agentscope/extensions/model/ollama/OllamaChatModel.java:81–88

OllamaChatModel

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.

参数Parameters
名称Name类型Type说明Description
modelNameString模型名称(类型 `String`)。The model name.
baseUrlString基类 URL(类型 `String`)。The base url.
defaultOptionsOllamaOptions默认选项(类型 `OllamaOptions`)。The default options.
formatterFormatter<OllamaMessage, OllamaResponse, OllamaRequest>格式化器(类型 `Formatter`)。The formatter.
httpTransportHttpTransportHTTP 传输层(类型 `HttpTransport`)。The http transport.
streamboolean流(类型 `boolean`)。The stream.
源码Source io/agentscope/extensions/model/ollama/OllamaChatModel.java:93–109

OllamaChatModel

public OllamaChatModel(String modelName, String baseUrl, OllamaOptions defaultOptions)

创建新的OllamaChatModel 使用默认设置。

Creates a new OllamaChatModel with default settings.

参数Parameters
名称Name类型Type说明Description
modelNameString模型到使用的名称。The name of the model to use.
baseUrlString基类 URL(类型 `String`)。The base URL of the Ollama server.
defaultOptionsOllamaOptions默认选项(类型 `OllamaOptions`)。Default configuration options.
源码Source io/agentscope/extensions/model/ollama/OllamaChatModel.java:118–120

方法详情Method Detail

builder

public static Builder builder()
static

创建新的构建器用于 OllamaChatModel。

Creates a new builder for OllamaChatModel.

返回Returns Builder
一种新的构建器实例。A new Builder instance.
源码Source io/agentscope/extensions/model/ollama/OllamaChatModel.java:127–129

getModelName

public String getModelName()

获取模型名称。

Returns the model name.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/model/ollama/OllamaChatModel.java:131–134

isStreaming

public boolean isStreaming()

判断是否流式。

Returns whether the streaming.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/extensions/model/ollama/OllamaChatModel.java:136–138

chat

public ChatResponse chat(List<Msg> messages, OllamaOptions options)

执行聊天相关操作。

Chat with the model using Ollama-specific options.

参数Parameters
名称Name类型Type说明Description
messagesList<Msg>消息到发送。The messages to send.
optionsOllamaOptions选项(类型 `OllamaOptions`)。The Ollama-specific options.
返回Returns ChatResponse
聊天响应。The chat response.
源码Source io/agentscope/extensions/model/ollama/OllamaChatModel.java:149–151

chat

public ChatResponse chat(List<Msg> messages, GenerateOptions options)

执行聊天相关操作。

Chat with the model using default options.

参数Parameters
名称Name类型Type说明Description
messagesList<Msg>消息到发送。The messages to send.
optionsGenerateOptions选项(类型 `GenerateOptions`)。The generation options.
返回Returns ChatResponse
聊天响应。The chat response.
源码Source io/agentscope/extensions/model/ollama/OllamaChatModel.java:160–162

doStream

protected Flux<ChatResponse> doStream(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options)

以流式方式执行并返回结果。

Performs the do stream operation.

参数Parameters
名称Name类型Type说明Description
messagesList<Msg>消息列表(类型 `List`)。The messages.
toolsList<ToolSchema>工具列表(类型 `List`)。The tools.
optionsGenerateOptions选项(类型 `GenerateOptions`)。The options.
返回Returns Flux<ChatResponse>
返回Flux。Returns flux.
源码Source 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.

继承成员Inherited Members

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.