KEMBAR78
feat(alibaba): Added alibaba vision model and omni model support by Little-LittleProgrammer · Pull Request #6292 · ChatGPTNextWeb/NextChat · GitHub
Skip to content

Conversation

@Little-LittleProgrammer
Copy link
Contributor

@Little-LittleProgrammer Little-LittleProgrammer commented Feb 24, 2025

💻 变更类型 | Change Type

  • feat
  • fix
  • refactor
  • perf
  • style
  • test
  • docs
  • ci
  • chore
  • build

🔀 变更说明 | Description of Change

[b709ee3] -- 增加对阿里巴巴图片理解(vl)和全模态(omni)模型的支持

[b709ee3] -- Added alibaba graph understanding and omni model support

📝 补充信息 | Additional Information

Summary by CodeRabbit

  • New Features
    • Enhanced chat interactions now support multimodal content, seamlessly handling both text and image data.
    • Improved message processing differentiates between vision and traditional models for more dynamic responses.
    • Service endpoints dynamically adjust based on the selected mode, offering additional options.
    • Introduced flexible image processing improvements that allow different transformations for image URLs based on context.
    • New interface for multimodal content specifically for Alibaba added.

@vercel
Copy link

vercel bot commented Feb 24, 2025

@Little-LittleProgrammer is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 24, 2025

Walkthrough

The pull request introduces support for multimodal content handling for Alibaba. A new interface, MultimodalContentForAlibaba, is added, and the chat method in the Alibaba platform is refactored to process messages differently based on whether the model is vision-enabled. The response handling now supports an array of multimodal content objects. Furthermore, the static Alibaba chat path is replaced with a dynamic function that determines the endpoint based on the model name. Lastly, a helper function is introduced to preprocess image content by converting image URLs to Base64.

Changes

File(s) Change Summary
app/client/api.ts Added new export interface MultimodalContentForAlibaba with optional properties text?: string and image?: string.
app/client/platforms/alibaba.ts, app/constant.ts Updated QwenApi's chat method to handle content as an array of MultimodalContentForAlibaba objects based on a vision model check. Modified response parsing to join text items and updated the Alibaba ChatPath from a static string to a dynamic function. New Alibaba mode entries were also added.
app/utils/chat.ts Renamed preProcessImageContent to preProcessImageContentBase and updated its signature to include a transformImageUrl parameter. Added new functions preProcessImageContent and preProcessImageContentForAlibabaDashScope for flexible image URL processing.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant QwenApi
    participant Utils
    participant AlibabaService

    Client->>QwenApi: chat(options)
    alt Vision Model Check
        QwenApi->>Utils: preProcessImageContentForAlibabaDashScope(content)
        Utils-->>QwenApi: processed content (array of multimodal items)
    else Non-Vision Model
        QwenApi-->>QwenApi: Process messages using standard mapping
    end
    QwenApi->>AlibabaService: Request via dynamic ChatPath (based on model)
    AlibabaService-->>QwenApi: Response with content array
    QwenApi-->>Client: Return joined text from content array
Loading

Poem

I'm a rabbit with code so bright,
Hopping through changes day and night,
New interfaces and pathways in sight,
Vision and text now dance just right,
Image URLs to Base64 shine,
In Alibaba lands, all is divine!
Happy hops and code carrots in flight!

Tip

CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0a25a1a and a2c4e46.

📒 Files selected for processing (1)
  • app/utils/chat.ts (4 hunks)
🔇 Additional comments (4)
app/utils/chat.ts (4)

6-6: Good addition of MultimodalContent import

Adding the MultimodalContent import is necessary for the new type annotations in the updated functions. This supports the Alibaba vision model integration.


73-86: Good refactoring to support different image transformations

The function has been effectively renamed and refactored to accept a transformation function parameter, which enhances flexibility for different platforms. This change properly supports the Alibaba vision model requirements by allowing customized image processing.


96-103: Well-implemented backward compatibility

This new implementation maintains backward compatibility by providing the same functionality as the original function but now leveraging the base function with a specific transformation. The explicit type annotation ensures type safety when used throughout the application.


105-111: Good implementation for Alibaba-specific image handling

This specialized function for Alibaba DashScope correctly transforms image content into the required format for the Alibaba vision model API. The implementation aligns with the PR objective to support Alibaba's vision model capabilities.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
app/utils/chat.ts (1)

95-115: LGTM! Well-implemented image content preprocessing for Alibaba.

The function correctly handles image content conversion and error cases.

Consider refactoring to reduce code duplication with preProcessImageContent. Here's a suggested approach:

+async function preProcessImageContentBase(
+  content: RequestMessage["content"],
+  transformImageUrl: (url: string) => Promise<{[key: string]: string}>,
+) {
+  if (typeof content === "string") {
+    return content;
+  }
+  const result = [];
+  for (const part of content) {
+    if (part?.type == "image_url" && part?.image_url?.url) {
+      try {
+        const url = await cacheImageToBase64Image(part?.image_url?.url);
+        result.push(await transformImageUrl(url));
+      } catch (error) {
+        console.error("Error processing image URL:", error);
+      }
+    } else {
+      result.push({ ...part });
+    }
+  }
+  return result;
+}

-export async function preProcessImageContent(content: RequestMessage["content"]) {
+export async function preProcessImageContent(content: RequestMessage["content"]) {
+  return preProcessImageContentBase(content, async (url) => ({
+    type: "image_url",
+    image_url: { url },
+  }));
+}

-export async function preProcessImageContentForAlibabaDashScope(content: RequestMessage["content"]) {
+export async function preProcessImageContentForAlibabaDashScope(content: RequestMessage["content"]) {
+  return preProcessImageContentBase(content, async (url) => ({
+    image: url,
+  }));
+}
app/client/platforms/alibaba.ts (2)

107-119: Consider refactoring nested ternaries and type safety.
The nested ternary, plus the as any cast, can reduce readability and forfeit type guarantees. A clearer flow or explicit type could improve maintainability.


227-229: Review the comma delimiter usage.
Joining multiple text items with commas may be confusing if any item contains commas. Also confirm each array item has a text field.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f5f3ce9 and b709ee3.

📒 Files selected for processing (4)
  • app/client/api.ts (1 hunks)
  • app/client/platforms/alibaba.ts (5 hunks)
  • app/constant.ts (2 hunks)
  • app/utils/chat.ts (1 hunks)
🔇 Additional comments (8)
app/client/api.ts (1)

43-46: LGTM! Well-structured interface for Alibaba's multimodal content.

The interface is properly designed with optional properties and follows TypeScript best practices.

app/constant.ts (2)

224-229: LGTM! Well-implemented dynamic path selection based on model type.

The function correctly determines the appropriate endpoint based on whether the model is vision-enabled ("vl") or omni-enabled.


576-578: LGTM! Added new model entries for vision and omni capabilities.

The new entries qwen-omni-turbo, qwen-vl-plus, and qwen-vl-max align with the multimodal support being added.

app/client/platforms/alibaba.ts (5)

10-13: All good on the new imports.
No issues found; the import statements align well with the introduced functionalities.


28-28: Import looks fine.
Ensure there are no conflicts or duplicates with similar utility functions named isVisionModel.


105-106: Validate the model selection logic.
The approach is straightforward, but confirm that isVisionModel(options.config.model) covers all possible model variants.


144-144: Double-check dynamic path resolution.
Confirm that Alibaba.ChatPath(modelConfig.model) yields valid endpoints for both vision and non-vision models.


177-177: Handle empty or invalid multimodal content arrays.
Ensure the new union type (string | null | MultimodalContentForAlibaba[]) is safely processed when array elements are missing or invalid.

@Leizhenpeng Leizhenpeng merged commit f7cde17 into ChatGPTNextWeb:main Mar 1, 2025
1 check failed
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.

2 participants