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 Details

    • DashScopeChatFormatter

      public DashScopeChatFormatter()
  • Method Details

    • doFormat

      protected List<DashScopeMessage> doFormat(List<io.agentscope.core.message.Msg> msgs)
      Specified by:
      doFormat in class io.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:
      doFormat in class io.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

      public void applyTools(DashScopeRequest request, List<io.agentscope.core.model.ToolSchema> tools)
    • applyToolChoice

      public void applyToolChoice(DashScopeRequest request, io.agentscope.core.model.ToolChoice toolChoice)
      Apply tool choice configuration to DashScopeRequest.
      Parameters:
      request - DashScope request
      toolChoice - Tool choice configuration
    • formatMultiModal

      public List<DashScopeMessage> formatMultiModal(List<io.agentscope.core.message.Msg> messages)
      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 convert
      options - request-scoped generation options; may be null
      Returns:
      List of DashScopeMessage objects with multimodal content
    • buildRequest

      public DashScopeRequest buildRequest(String model, List<DashScopeMessage> messages, boolean stream)
      Build a complete DashScopeRequest for the API call.
      Parameters:
      model - Model name
      messages - Formatted DashScope messages
      stream - 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 name
      messages - Formatted DashScope messages
      stream - Whether to enable streaming
      options - Generation options
      defaultOptions - Default generation options
      tools - Tool schemas
      toolChoice - Tool choice configuration
      Returns:
      Complete DashScopeRequest ready for API call