OllamaChatFormatter
public class OllamaChatFormatter extends AbstractBaseFormatter<OllamaMessage, OllamaResponse, OllamaRequest>
源码Source
io/agentscope/extensions/model/ollama/formatter/OllamaChatFormatter.java:52–491Ollama 聊天格式化器,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.ollama.formatter 包,继承自 AbstractBaseFormatter<OllamaMessage, OllamaResponse, OllamaRequest>。核心成员包括 doFormat、parseResponse、applyOptions、applyTools、applyToolChoice、buildRequest。
Formatter for Ollama Chat API. Converts between AgentScope Msg objects and Ollama DTO types.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public OllamaChatFormatter() | 初始化 `OllamaChatFormatter` 实例。 Creates a new instance. |
public OllamaChatFormatter(boolean promoteToolResultImages) | 初始化 `OllamaChatFormatter` 实例。 Creates a new instance. |
方法摘要Method Summary
构造器详情Constructor Detail
OllamaChatFormatter
public OllamaChatFormatter()
初始化 OllamaChatFormatter 实例。
Creates a new instance.
源码Source
io/agentscope/extensions/model/ollama/formatter/OllamaChatFormatter.java:61–63OllamaChatFormatter
public OllamaChatFormatter(boolean promoteToolResultImages)
初始化 OllamaChatFormatter 实例。
Creates a new instance.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
promoteToolResultImages | boolean | promote 工具结果 Images(类型 `boolean`)。The promote tool result images. |
源码Source
io/agentscope/extensions/model/ollama/formatter/OllamaChatFormatter.java:65–70方法详情Method Detail
doFormat
protected List<OllamaMessage> doFormat(List<Msg> msgs)
执行格式操作。
Performs the do format operation.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。The msgs. |
List<OllamaMessage>返回列出。Returns list.
源码Source
io/agentscope/extensions/model/ollama/formatter/OllamaChatFormatter.java:72–82parseResponse
public ChatResponse parseResponse(OllamaResponse result, Instant startTime)
解析响应。
Parses the response.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
result | OllamaResponse | 结果(类型 `OllamaResponse`)。The result. |
startTime | Instant | 启动时间(类型 `Instant`)。The start time. |
ChatResponse返回ChatResponse。Returns chat response.
源码Source
io/agentscope/extensions/model/ollama/formatter/OllamaChatFormatter.java:413–416applyOptions
public void applyOptions(OllamaRequest request, GenerateOptions options, GenerateOptions defaultOptions)
应用选项。
Performs the apply options operation.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | OllamaRequest | 请求(类型 `OllamaRequest`)。The request. |
options | GenerateOptions | 选项(类型 `GenerateOptions`)。The options. |
defaultOptions | GenerateOptions | 默认选项(类型 `GenerateOptions`)。The default options. |
源码Source
io/agentscope/extensions/model/ollama/formatter/OllamaChatFormatter.java:418–422applyOptions
public void applyOptions(OllamaRequest request, OllamaOptions options, OllamaOptions defaultOptions)
应用选项。
Apply OllamaOptions to the request.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | OllamaRequest | 请求(类型 `OllamaRequest`)。The request to apply options to |
options | OllamaOptions | 运行时选项。The runtime options |
defaultOptions | OllamaOptions | 默认选项。The default options |
源码Source
io/agentscope/extensions/model/ollama/formatter/OllamaChatFormatter.java:431–434applyTools
public void applyTools(OllamaRequest request, List<ToolSchema> tools)
应用工具。
Performs the apply tools operation.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | OllamaRequest | 请求(类型 `OllamaRequest`)。The request. |
tools | List<ToolSchema> | 工具列表(类型 `List`)。The tools. |
源码Source
io/agentscope/extensions/model/ollama/formatter/OllamaChatFormatter.java:436–439applyToolChoice
public void applyToolChoice(OllamaRequest request, ToolChoice toolChoice)
应用工具选项。
Performs the apply tool choice operation.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | OllamaRequest | 请求(类型 `OllamaRequest`)。The request. |
toolChoice | ToolChoice | 工具选项(类型 `ToolChoice`)。The tool choice. |
源码Source
io/agentscope/extensions/model/ollama/formatter/OllamaChatFormatter.java:441–444buildRequest
public OllamaRequest buildRequest(String model, List<OllamaMessage> messages, boolean stream, OllamaOptions options, OllamaOptions defaultOptions, List<ToolSchema> tools, ToolChoice toolChoice)
构建请求。
Build a complete OllamaRequest for the API call.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
model | String | 模型实例(类型 `String`)。Model name |
messages | List<OllamaMessage> | 消息列表(类型 `List`)。Formatted Ollama messages |
stream | boolean | 判断是否到启用流式。Whether to enable streaming |
options | OllamaOptions | 选项(类型 `OllamaOptions`)。Generation options |
defaultOptions | OllamaOptions | 默认选项(类型 `OllamaOptions`)。Default generation options |
tools | List<ToolSchema> | 工具列表(类型 `List`)。Tool schemas |
toolChoice | ToolChoice | 工具选项(类型 `ToolChoice`)。Tool choice configuration |
OllamaRequest返回OllamaRequest。Complete OllamaRequest ready for API call
源码Source
io/agentscope/extensions/model/ollama/formatter/OllamaChatFormatter.java:458–479