Skip to content

feat: add AioTextReRank to support async rerank#119

Open
Trenza1ore wants to merge 1 commit intodashscope:mainfrom
Trenza1ore:main
Open

feat: add AioTextReRank to support async rerank#119
Trenza1ore wants to merge 1 commit intodashscope:mainfrom
Trenza1ore:main

Conversation

@Trenza1ore
Copy link
Copy Markdown

@Trenza1ore Trenza1ore commented Mar 25, 2026

Description

dashscope currently has no async rerank API and requests.post is thread-level blocking, meaning there is no way to have any concurrency within one thread. This PR just introduce AioTextReRank as an async copy of TextReRank, and I'll leave the dashscope members to refactor later, gemini's comments are outside the scope of this PR.

Related Issue: Fixes #118

Security Considerations: [Check if API keys or sensitive credentials are exposed in code/logs]

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactoring

Component(s) Affected

  • Model
  • Application
  • Common
  • Documentation
  • Tests
  • CI/CD

Checklist

  • Pre-commit hooks pass
  • Tests pass locally
  • Documentation updated (if needed)
  • Ready for review

Testing

Added to test_text_rerank.py sample test.

Additional Notes

[Optional: any other context]

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 enhances the dashscope library by introducing asynchronous text re-ranking functionality. This new feature allows users to perform re-ranking operations without blocking the main thread, significantly improving concurrency and overall application responsiveness, especially in I/O-bound scenarios. The change provides a more efficient way to interact with re-ranking models.

Highlights

  • Asynchronous Text Re-ranking: Introduced a new AioTextReRank class to provide asynchronous text re-ranking capabilities, addressing the current limitation of no async rerank API in dashscope.
  • API Exposure: The new AioTextReRank class has been exposed through the main dashscope package, making it readily available for use.
  • Asynchronous Base API Integration: Integrated BaseAioApi to support the asynchronous operations required for the new re-ranking functionality.
  • Test Coverage: Added a new asynchronous test case to test_text_rerank.py to validate the functionality of the AioTextReRank class.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

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.

@Trenza1ore
Copy link
Copy Markdown
Author

/gemini review

Copy link
Copy Markdown

@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

This pull request introduces an asynchronous text reranking API (AioTextReRank) by adding a new class in dashscope/rerank/text_rerank.py and updating dashscope/__init__.py to expose it. Corresponding asynchronous test cases have been added in samples/test_text_rerank.py. Feedback includes suggestions to improve code maintainability by reusing the Models inner class from TextReRank, extracting common input validation logic into a helper function to avoid duplication, and removing a redundant try...except block in the new asynchronous test.

Copy link
Copy Markdown

@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

This pull request introduces an asynchronous text reranking API, AioTextReRank, by adding a new class in dashscope/rerank/text_rerank.py and exposing it through dashscope/__init__.py. It also includes a new asynchronous test case in samples/test_text_rerank.py to demonstrate its usage. The review feedback points out several areas for improvement, including addressing a docstring line length violation, renaming a variable to avoid redefining a built-in name, resolving or explaining a type ignore comment, documenting the instruct parameter in the new API's docstring, and enhancing error handling in the new test case by logging exceptions before re-raising.

@Trenza1ore Trenza1ore changed the title add AioTextReRank to support async rerank feat: add AioTextReRank to support async rerank Mar 25, 2026
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.

文本重排功能没有异步接口

1 participant