类 DashScopeMediaConverter

java.lang.Object
io.agentscope.core.formatter.dashscope.DashScopeMediaConverter

public class DashScopeMediaConverter extends Object
Handles media content conversion for DashScope API. Converts ImageBlock/VideoBlock/AudioBlock to DashScope-compatible formats.

DashScope uses file:// protocol for local files, which differs from OpenAI's base64 approach.

  • 构造器详细资料

    • DashScopeMediaConverter

      public DashScopeMediaConverter()
  • 方法详细资料

    • convertImageBlockToUrl

      public String convertImageBlockToUrl(ImageBlock imageBlock) throws Exception
      Convert ImageBlock to URL string for DashScope API.

      Uses file:// protocol for local files for consistent behavior.

      Handles:

      • Local files → file:// protocol URL (e.g., file:///absolute/path/image.png)
      • Remote URLs → Direct URL (e.g., https://example.com/image.png)
      • Base64 sources → Data URL (e.g., data:image/png;base64,...)
      参数:
      imageBlock - The image block to convert
      返回:
      URL string for DashScope API
      抛出:
      Exception - If conversion fails
    • convertImageBlockToContentPart

      public DashScopeContentPart convertImageBlockToContentPart(ImageBlock imageBlock) throws Exception
      Convert ImageBlock to DashScopeContentPart.
      参数:
      imageBlock - The image block to convert
      返回:
      DashScopeContentPart for the image
      抛出:
      Exception - If conversion fails
    • convertVideoBlockToUrl

      public String convertVideoBlockToUrl(VideoBlock videoBlock) throws Exception
      Convert VideoBlock to URL string for DashScope API.

      Uses file:// protocol for local files for consistent behavior (same as ImageBlock handling).

      Handles:

      • Local files → file:// protocol URL (e.g., file:///absolute/path/video.mp4)
      • Remote URLs → Direct URL (e.g., https://example.com/video.mp4)
      • Base64 sources → Data URL (e.g., data:video/mp4;base64,...)
      参数:
      videoBlock - The video block to convert
      返回:
      URL string for DashScope API
      抛出:
      Exception - If conversion fails
    • convertVideoBlockToContentPart

      public DashScopeContentPart convertVideoBlockToContentPart(VideoBlock videoBlock) throws Exception
      Convert VideoBlock to DashScopeContentPart.
      参数:
      videoBlock - The video block to convert
      返回:
      DashScopeContentPart for the video
      抛出:
      Exception - If conversion fails
    • convertAudioBlockToUrl

      public String convertAudioBlockToUrl(AudioBlock audioBlock) throws Exception
      Convert AudioBlock to URL string for DashScope API.

      Uses file:// protocol for local files for consistent behavior (same as ImageBlock handling).

      Handles:

      • Local files → file:// protocol URL (e.g., file:///absolute/path/audio.mp3)
      • Remote URLs → Direct URL (e.g., https://example.com/audio.mp3)
      • Base64 sources → Data URL (e.g., data:audio/wav;base64,...)
      参数:
      audioBlock - The audio block to convert
      返回:
      URL string for DashScope API
      抛出:
      Exception - If conversion fails
    • convertAudioBlockToContentPart

      public DashScopeContentPart convertAudioBlockToContentPart(AudioBlock audioBlock) throws Exception
      Convert AudioBlock to DashScopeContentPart.
      参数:
      audioBlock - The audio block to convert
      返回:
      DashScopeContentPart for the audio
      抛出:
      Exception - If conversion fails