Class DashScopeChatFormatter
java.lang.Object
io.agentscope.core.formatter.AbstractBaseFormatter<DashScopeMessage,DashScopeResponse,DashScopeRequest>
io.agentscope.extensions.model.dashscope.formatter.DashScopeChatFormatter
- All Implemented Interfaces:
io.agentscope.core.formatter.Formatter<DashScopeMessage,DashScopeResponse, DashScopeRequest>
public class DashScopeChatFormatter
extends io.agentscope.core.formatter.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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyOptions(DashScopeRequest request, io.agentscope.core.model.GenerateOptions options, io.agentscope.core.model.GenerateOptions defaultOptions) voidapplyToolChoice(DashScopeRequest request, io.agentscope.core.model.ToolChoice toolChoice) Apply tool choice configuration to DashScopeRequest.voidapplyTools(DashScopeRequest request, List<io.agentscope.core.model.ToolSchema> tools) buildRequest(String model, List<DashScopeMessage> messages, boolean stream) Build a complete DashScopeRequest for the API call.buildRequest(String model, List<DashScopeMessage> messages, boolean stream, io.agentscope.core.model.GenerateOptions options, io.agentscope.core.model.GenerateOptions defaultOptions, List<io.agentscope.core.model.ToolSchema> tools, io.agentscope.core.model.ToolChoice toolChoice) Build a complete DashScopeRequest with full configuration.protected List<DashScopeMessage>protected List<DashScopeMessage>doFormat(List<io.agentscope.core.message.Msg> msgs, io.agentscope.core.model.GenerateOptions options) formatMultiModal(List<io.agentscope.core.message.Msg> messages) Format AgentScope Msg objects to DashScope MultiModal message format.formatMultiModal(List<io.agentscope.core.message.Msg> messages, io.agentscope.core.model.GenerateOptions options) Format AgentScope Msg objects to DashScope MultiModal message format using request-scoped generation options.io.agentscope.core.model.ChatResponseparseResponse(DashScopeResponse result, Instant startTime) Methods inherited from class io.agentscope.core.formatter.AbstractBaseFormatter
convertToolResultToString, extractTextContent, extractTextContent, format, format, formatRoleLabel, getOptionOrDefault, hasMediaContent, saveBase64DataToTempFile, shouldBypassHistoryMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.agentscope.core.formatter.Formatter
applyToolChoice, applyTools
-
Constructor Details
-
DashScopeChatFormatter
public DashScopeChatFormatter()
-
-
Method Details
-
doFormat
- Specified by:
doFormatin classio.agentscope.core.formatter.AbstractBaseFormatter<DashScopeMessage,DashScopeResponse, DashScopeRequest>
-
doFormat
protected List<DashScopeMessage> doFormat(List<io.agentscope.core.message.Msg> msgs, io.agentscope.core.model.GenerateOptions options) - Overrides:
doFormatin classio.agentscope.core.formatter.AbstractBaseFormatter<DashScopeMessage,DashScopeResponse, DashScopeRequest>
-
parseResponse
public io.agentscope.core.model.ChatResponse parseResponse(DashScopeResponse result, Instant startTime) -
applyOptions
public void applyOptions(DashScopeRequest request, io.agentscope.core.model.GenerateOptions options, io.agentscope.core.model.GenerateOptions defaultOptions) -
applyTools
-
applyToolChoice
public void applyToolChoice(DashScopeRequest request, io.agentscope.core.model.ToolChoice toolChoice) Apply tool choice configuration to DashScopeRequest.- Parameters:
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.- Parameters:
messages- The AgentScope messages to convert- Returns:
- List of DashScopeMessage objects with multimodal content
-
formatMultiModal
public List<DashScopeMessage> formatMultiModal(List<io.agentscope.core.message.Msg> messages, io.agentscope.core.model.GenerateOptions options) Format AgentScope Msg objects to DashScope MultiModal message format using request-scoped generation options.- Parameters:
messages- The AgentScope messages to convertoptions- request-scoped generation options; may benull- Returns:
- List of DashScopeMessage objects with multimodal content
-
buildRequest
Build a complete DashScopeRequest for the API call.- Parameters:
model- Model namemessages- Formatted DashScope messagesstream- Whether to enable streaming- Returns:
- Complete DashScopeRequest ready for API call
-
buildRequest
public DashScopeRequest buildRequest(String model, List<DashScopeMessage> messages, boolean stream, io.agentscope.core.model.GenerateOptions options, io.agentscope.core.model.GenerateOptions defaultOptions, List<io.agentscope.core.model.ToolSchema> tools, io.agentscope.core.model.ToolChoice toolChoice) Build a complete DashScopeRequest with full configuration.- Parameters:
model- Model namemessages- Formatted DashScope messagesstream- Whether to enable streamingoptions- Generation optionsdefaultOptions- Default generation optionstools- Tool schemastoolChoice- Tool choice configuration- Returns:
- Complete DashScopeRequest ready for API call
-