Class AnthropicMediaConverter

java.lang.Object
io.agentscope.extensions.model.anthropic.formatter.AnthropicMediaConverter

public class AnthropicMediaConverter extends Object
Handles media content conversion for Anthropic API.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    com.anthropic.models.messages.ImageBlockParam
    convertDataBlock(io.agentscope.core.message.DataBlock dataBlock)
    Convert DataBlock to Anthropic ImageBlockParam by resolving MIME type and routing to image.
    com.anthropic.models.messages.ImageBlockParam
    convertImageBlock(io.agentscope.core.message.ImageBlock imageBlock)
    Convert ImageBlock to Anthropic ImageBlockParam.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AnthropicMediaConverter

      public AnthropicMediaConverter()
  • Method Details

    • convertImageBlock

      public com.anthropic.models.messages.ImageBlockParam convertImageBlock(io.agentscope.core.message.ImageBlock imageBlock) throws Exception
      Convert ImageBlock to Anthropic ImageBlockParam. For local files, converts to base64. For remote URLs, uses URL source directly.
      Throws:
      Exception
    • convertDataBlock

      public com.anthropic.models.messages.ImageBlockParam convertDataBlock(io.agentscope.core.message.DataBlock dataBlock) throws Exception
      Convert DataBlock to Anthropic ImageBlockParam by resolving MIME type and routing to image.

      Anthropic currently supports image modality only via this SDK type. Audio and video DataBlocks will throw IllegalArgumentException since the Anthropic API does not expose a generic binary content block param yet.

      MIME type resolution order:

      1. Base64Source.mediaType — always explicit
      2. URLSource.mimeType — caller-supplied hint for extension-less URLs
      3. MediaUtils.determineMediaType(url) — extension-based inference
      Parameters:
      dataBlock - The data block to convert
      Returns:
      ImageBlockParam for Anthropic API
      Throws:
      Exception - If conversion fails or MIME type resolves to a non-image category