类 DashScopeChatFormatter
java.lang.Object
io.agentscope.core.formatter.AbstractBaseFormatter<DashScopeMessage,DashScopeResponse,DashScopeRequest>
io.agentscope.core.formatter.dashscope.DashScopeChatFormatter
public class DashScopeChatFormatter
extends AbstractBaseFormatter<DashScopeMessage,DashScopeResponse,DashScopeRequest>
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.
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidapplyCacheControl(List<DashScopeMessage> messages) Apply cache control to DashScope messages.voidapplyOptions(DashScopeRequest request, GenerateOptions options, GenerateOptions defaultOptions) Apply generation options to provider-specific request parameters.voidapplyToolChoice(DashScopeRequest request, ToolChoice toolChoice) Apply tool choice configuration to DashScopeRequest.voidapplyTools(DashScopeRequest request, List<ToolSchema> tools) Apply tool schemas to provider-specific request parameters.buildRequest(String model, List<DashScopeMessage> messages, boolean stream) Build a complete DashScopeRequest for the API call.buildRequest(String model, List<DashScopeMessage> messages, boolean stream, GenerateOptions options, GenerateOptions defaultOptions, List<ToolSchema> tools, ToolChoice toolChoice) Build a complete DashScopeRequest with full configuration.protected List<DashScopeMessage> formatMultiModal(List<Msg> messages) Format AgentScope Msg objects to DashScope MultiModal message format.parseResponse(DashScopeResponse result, Instant startTime) Parse provider-specific response to AgentScope ChatResponse.从类继承的方法 io.agentscope.core.formatter.AbstractBaseFormatter
convertToolResultToString, extractTextContent, extractTextContent, format, formatRoleLabel, getOptionOrDefault, hasMediaContent, saveBase64DataToTempFile, shouldBypassHistory从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 io.agentscope.core.formatter.Formatter
applyToolChoice, applyTools
-
构造器详细资料
-
DashScopeChatFormatter
public DashScopeChatFormatter()
-
-
方法详细资料
-
doFormat
-
parseResponse
从接口复制的说明:FormatterParse provider-specific response to AgentScope ChatResponse.- 参数:
result- Provider-specific response objectstartTime- Request start time for calculating duration- 返回:
- AgentScope ChatResponse
-
applyOptions
public void applyOptions(DashScopeRequest request, GenerateOptions options, GenerateOptions defaultOptions) 从接口复制的说明:FormatterApply generation options to provider-specific request parameters.- 参数:
request- Provider-specific request parameters builderoptions- Generation options to applydefaultOptions- Default options to use if options parameter is null
-
applyTools
从接口复制的说明:FormatterApply tool schemas to provider-specific request parameters.- 参数:
request- Provider-specific request parameters buildertools- List of tool schemas to apply (may be null or empty)
-
applyToolChoice
Apply tool choice configuration to DashScopeRequest.- 参数:
request- DashScope requesttoolChoice- Tool choice configuration
-
formatMultiModal
Format AgentScope Msg objects to DashScope MultiModal message format. This method is used for vision models that require the MultiModalConversation API.- 参数:
messages- The AgentScope messages to convert- 返回:
- List of DashScopeMessage objects with multimodal content
-
buildRequest
Build a complete DashScopeRequest for the API call.- 参数:
model- Model namemessages- Formatted DashScope messagesstream- Whether to enable streaming- 返回:
- Complete DashScopeRequest ready for API call
-
buildRequest
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.- 参数:
model- Model namemessages- Formatted DashScope messagesstream- Whether to enable streamingoptions- Generation optionsdefaultOptions- Default generation optionstools- Tool schemastoolChoice- Tool choice configuration- 返回:
- Complete DashScopeRequest ready for API call
-
applyCacheControl
Apply cache control to DashScope messages.Adds
cache_control: {"type": "ephemeral"}to all system messages and the last message in the list. Messages that already have cache_control set (e.g., via manual metadata marking) will not be overwritten.- 参数:
messages- the list of formatted DashScope messages
-