Skip to content

fix(DashScope formatter): convert local files to base64 data in dashscope formatter#1253

Open
qbc2016 wants to merge 3 commits intoagentscope-ai:mainfrom
qbc2016:bc/hotfix_formatter
Open

fix(DashScope formatter): convert local files to base64 data in dashscope formatter#1253
qbc2016 wants to merge 3 commits intoagentscope-ai:mainfrom
qbc2016:bc/hotfix_formatter

Conversation

@qbc2016
Copy link
Copy Markdown
Member

@qbc2016 qbc2016 commented Feb 22, 2026

AgentScope Version

1.0.16

Description

  • Fix the FileAlreadyExists error from DashScope SDK when the same local image appears in memory across multiple agent calls
  • Local media files are now converted to base64 data URIs in _format_dashscope_media_block instead of file:// URLs, avoiding repeated OSS uploads
  • Refactor DashScopeMultiAgentFormatter to reuse _format_dashscope_media_block for consistent media handling

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with pre-commit run --all-files command
  • All tests are passing
  • Docstrings are in Google style
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @qbc2016, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses issues with how local media files are handled within the DashScope formatter. It prevents 'FileAlreadyExists' errors and optimizes media processing by converting local file paths into base64 data URIs. This change ensures that media content is directly embedded, avoiding redundant uploads and standardizing the formatting logic.

Highlights

  • Error Fix: Fixed the 'FileAlreadyExists' error from DashScope SDK that occurred when the same local image appeared in memory across multiple agent calls.
  • Media Handling Improvement: Converted local media files to base64 data URIs in '_format_dashscope_media_block' instead of 'file:// URLs', which avoids repeated OSS uploads and ensures media content is embedded directly.
  • Code Refactoring: Refactored 'DashScopeMultiAgentFormatter' to reuse '_format_dashscope_media_block' for consistent and centralized media handling across different message types.
Changelog
  • examples/functionality/rag/multimodal_rag.py
    • Adjusted the index used to retrieve content from the agent's memory in an example.
  • src/agentscope/formatter/_dashscope_formatter.py
    • Imported 'base64' and 'mimetypes' modules for encoding and type detection.
    • Modified '_format_dashscope_media_block' to read local files, determine their MIME type, and encode them as base64 data URIs.
    • Refactored '_format_agent_message' to utilize '_format_dashscope_media_block' for all media block processing, removing redundant logic.
  • tests/formatter_dashscope_test.py
    • Updated the test setup to generate base64 data URIs for a dummy image.
    • Modified existing test cases to assert against base64 data URIs instead of local file paths, reflecting the new media handling.
Activity
  • The author has provided a checklist indicating that the code has been formatted, tests are passing, docstrings are in Google style, related documentation has been updated, and the code is ready for review.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request successfully addresses the FileAlreadyExists error in the DashScope SDK by converting local media files to base64 data URIs instead of using file:// URLs. This is a robust fix that avoids repeated uploads to OSS. The refactoring of DashScopeMultiAgentFormatter to reuse _format_dashscope_media_block is a positive change for maintainability and consistency. My feedback focuses on ensuring that type hints and docstrings accurately reflect the support for video blocks, which are now being processed by this centralized logic.

Style Guide Adherence:

  • [MUST] Comment Standards: I've suggested updates to the docstrings in _format_dashscope_media_block to ensure they are complete and include the newly supported VideoBlock (Repository Style Guide, line 46).
  • [MUST] Encapsulation Standards: The internal helper function _format_dashscope_media_block correctly uses the _ prefix (Repository Style Guide, line 27).
  • [MUST] Lazy Loading: Standard library imports (base64, mimetypes) are placed at the top, which is acceptable as they are not third-party dependencies. Third-party libraries like dashscope are correctly imported at the point of use elsewhere in the file (Repository Style Guide, line 10).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: https://github.com/agentscope-ai/agentscope/edit/main/examples/functionality/rag/multimodal_rag.py

1 participant