DashScopeChatFormatter
public class DashScopeChatFormatter extends AbstractBaseFormatter<DashScopeMessage, DashScopeResponse, DashScopeRequest>
io/agentscope/extensions/model/dashscope/formatter/DashScopeChatFormatter.java:46–312DashScope 聊天格式化器,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.dashscope.formatter 包,继承自 AbstractBaseFormatter<DashScopeMessage, DashScopeResponse, DashScopeRequest>。核心成员包括 doFormat、parseResponse、applyOptions、applyTools、applyToolChoice、formatMultiModal。
Formatter for DashScope Conversation/Generation APIs. Converts between AgentScope Msg objects and DashScope DTO types.
This formatter handles both text and multimodal messages, supporting the DashScope Generation API and MultiModalConversation API.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public DashScopeChatFormatter() | 初始化 `DashScopeChatFormatter` 实例。 Creates a new instance. |
方法摘要Method Summary
构造器详情Constructor Detail
DashScopeChatFormatter
public DashScopeChatFormatter()
初始化 DashScopeChatFormatter 实例。
Creates a new instance.
io/agentscope/extensions/model/dashscope/formatter/DashScopeChatFormatter.java:58–62方法详情Method Detail
doFormat
protected List<DashScopeMessage> doFormat(List<Msg> msgs)
执行格式操作。
Performs the do format operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。The msgs. |
List<DashScopeMessage>io/agentscope/extensions/model/dashscope/formatter/DashScopeChatFormatter.java:64–75doFormat
protected List<DashScopeMessage> doFormat(List<Msg> msgs, GenerateOptions options)
执行格式操作。
Performs the do format operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。The msgs. |
options | GenerateOptions | 选项(类型 `GenerateOptions`)。The options. |
List<DashScopeMessage>io/agentscope/extensions/model/dashscope/formatter/DashScopeChatFormatter.java:77–90parseResponse
public ChatResponse parseResponse(DashScopeResponse result, Instant startTime)
解析响应。
Parses the response.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
result | DashScopeResponse | 结果(类型 `DashScopeResponse`)。The result. |
startTime | Instant | 启动时间(类型 `Instant`)。The start time. |
ChatResponseio/agentscope/extensions/model/dashscope/formatter/DashScopeChatFormatter.java:92–95applyOptions
public void applyOptions(DashScopeRequest request, GenerateOptions options, GenerateOptions defaultOptions)
应用选项。
Performs the apply options operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | DashScopeRequest | 请求(类型 `DashScopeRequest`)。The request. |
options | GenerateOptions | 选项(类型 `GenerateOptions`)。The options. |
defaultOptions | GenerateOptions | 默认选项(类型 `GenerateOptions`)。The default options. |
io/agentscope/extensions/model/dashscope/formatter/DashScopeChatFormatter.java:97–106applyTools
public void applyTools(DashScopeRequest request, List<ToolSchema> tools)
应用工具。
Performs the apply tools operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | DashScopeRequest | 请求(类型 `DashScopeRequest`)。The request. |
tools | List<ToolSchema> | 工具列表(类型 `List`)。The tools. |
io/agentscope/extensions/model/dashscope/formatter/DashScopeChatFormatter.java:108–116applyToolChoice
public void applyToolChoice(DashScopeRequest request, ToolChoice toolChoice)
应用工具选项。
Apply tool choice configuration to DashScopeRequest.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | DashScopeRequest | 请求(类型 `DashScopeRequest`)。DashScope request |
toolChoice | ToolChoice | 工具选项(类型 `ToolChoice`)。Tool choice configuration |
io/agentscope/extensions/model/dashscope/formatter/DashScopeChatFormatter.java:124–132formatMultiModal
public List<DashScopeMessage> formatMultiModal(List<Msg> messages)
格式化 formatMultiModal。
Format AgentScope Msg objects to DashScope MultiModal message format.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
messages | List<Msg> | AgentScope 消息到转换。The AgentScope messages to convert |
List<DashScopeMessage>io/agentscope/extensions/model/dashscope/formatter/DashScopeChatFormatter.java:141–143formatMultiModal
public List<DashScopeMessage> formatMultiModal(List<Msg> messages, GenerateOptions options)
格式化 formatMultiModal。
Format AgentScope Msg objects to DashScope MultiModal message format using request-scoped generation options.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
messages | List<Msg> | AgentScope 消息到转换。The AgentScope messages to convert |
options | GenerateOptions | 选项(类型 `GenerateOptions`)。request-scoped generation options; may be `null` |
List<DashScopeMessage>io/agentscope/extensions/model/dashscope/formatter/DashScopeChatFormatter.java:153–163buildRequest
public DashScopeRequest buildRequest(String model, List<DashScopeMessage> messages, boolean stream)
构建请求。
Build a complete DashScopeRequest for the API call.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
model | String | 模型实例(类型 `String`)。Model name |
messages | List<DashScopeMessage> | 消息列表(类型 `List`)。Formatted DashScope messages |
stream | boolean | 判断是否到启用流式。Whether to enable streaming |
DashScopeRequestio/agentscope/extensions/model/dashscope/formatter/DashScopeChatFormatter.java:173–183buildRequest
public DashScopeRequest buildRequest(String model, List<DashScopeMessage> messages, boolean stream, GenerateOptions options, GenerateOptions defaultOptions, List<ToolSchema> tools, ToolChoice toolChoice)
构建请求。
Build a complete DashScopeRequest with full configuration.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
model | String | 模型实例(类型 `String`)。Model name |
messages | List<DashScopeMessage> | 消息列表(类型 `List`)。Formatted DashScope messages |
stream | boolean | 判断是否到启用流式。Whether to enable streaming |
options | GenerateOptions | 选项(类型 `GenerateOptions`)。Generation options |
defaultOptions | GenerateOptions | 默认选项(类型 `GenerateOptions`)。Default generation options |
tools | List<ToolSchema> | 工具列表(类型 `List`)。Tool schemas |
toolChoice | ToolChoice | 工具选项(类型 `ToolChoice`)。Tool choice configuration |
DashScopeRequestio/agentscope/extensions/model/dashscope/formatter/DashScopeChatFormatter.java:197–213