Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: qwen #4942

Merged
merged 7 commits into from
Jul 9, 2024
Merged

feat: qwen #4942

merged 7 commits into from
Jul 9, 2024

Conversation

Dogtiti
Copy link
Member

@Dogtiti Dogtiti commented Jul 7, 2024

Summary by CodeRabbit

  • New Features

    • Added support for Alibaba and ByteDance API integrations.
    • Introduced new settings for API keys and endpoints for Alibaba and ByteDance.
  • Localization

    • Added localization keys for Alibaba and ByteDance settings in both English and Chinese.
  • Documentation

    • Updated README.md and README_CN.md with configuration options for Alibaba and ByteDance APIs.

@Dogtiti Dogtiti requested a review from lloydzhou July 7, 2024 14:00
Copy link

vercel bot commented Jul 7, 2024

@Dogtiti is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Jul 7, 2024

Walkthrough

The changes introduce new authentication and request proxying functions for Alibaba and ByteDance services, integrating them into existing APIs. This includes new class implementations for QwenApi and DoubaoApi, extended localization and configuration options, and UI updates. Logging, URL handling, and HTTP request functions have been improved to support these new services.

Changes

Files Summary
app/api/alibaba/[...path]/route.ts Added handler functions for requests, authentication, OPTIONS handling, request proxying to Alibaba.
app/api/auth.ts Added authentication case for ModelProvider.Qwen, handling Alibaba API Keys.
app/api/bytedance/[...path]/route.ts Added handler functions for ByteDance requests, authentication, and HTTP request processing.
app/client/api.ts Updated to handle ByteDance and Alibaba APIs, added DoubaoApi and QwenApi integrations.
app/client/platforms/alibaba.ts Introduced QwenApi class with methods for chat interactions, path construction, and model handling.
app/client/platforms/bytedance.ts Introduced DoubaoApi class with methods for chat interactions, path construction, and model handling.
README.md Added configuration options for Alibaba Cloud and ByteDance APIs, including model name customization.
README_CN.md Similar updates to README.md, but in Chinese.
app/components/settings.tsx Enhanced Settings component to include fields for Alibaba and ByteDance API configurations.
app/locales/cn.ts Added localization keys for Alibaba and ByteDance settings.
app/locales/en.ts Added localization keys for Alibaba and ByteDance settings.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Settings
    participant Auth
    participant AlibabaService
    participant ByteDanceService
    participant QwenApi as QwenApi
    participant DoubaoApi as DoubaoApi
    
    User->>Settings: Access Settings
    Settings->>User: Display new provider options
    User->>Settings: Select Alibaba/ByteDance provider
    Settings->>Auth: Authenticate user request
    Auth->>Settings: Return API key
    Settings->>User: Save API key
    
    User->>QwenApi: Make chat request
    QwenApi->>AlibabaService: Forward request
    AlibabaService-->>QwenApi: Return result
    QwenApi->>User: Display result
    
    User->>DoubaoApi: Make chat request
    DoubaoApi->>ByteDanceService: Forward request
    ByteDanceService-->>DoubaoApi: Return result
    DoubaoApi->>User: Display result
Loading

Poem

Amidst the code, in lines so bright,
Alibaba and ByteDance take their flight.
APIs dancing, with keys held tight,
Proxies pave paths in the data night.
Settings, updated with care so slight,
Making integrations just feel right.
A journey through bytes, pure delight!


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

@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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7218f13 and 9bdd37b.

Files selected for processing (8)
  • app/api/alibaba/[...path]/route.ts (1 hunks)
  • app/api/auth.ts (1 hunks)
  • app/client/api.ts (3 hunks)
  • app/client/platforms/alibaba.ts (1 hunks)
  • app/client/platforms/openai.ts (1 hunks)
  • app/config/server.ts (3 hunks)
  • app/constant.ts (6 hunks)
  • app/store/access.ts (3 hunks)
Additional context used
Biome
app/api/auth.ts

[error] 79-79: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

Additional comments not posted (21)
app/api/auth.ts (1)

Line range hint 1-78:
LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to auth handle the ModelProvider.Qwen case correctly.

Verification successful

Function usage verified!

The auth function is correctly handling the ModelProvider.Qwen case in the app/api/alibaba/[...path]/route.ts file.

  • app/api/alibaba/[...path]/route.ts:
    • The auth function is called with ModelProvider.Qwen, and the result is appropriately handled.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `auth` handle the `ModelProvider.Qwen` case correctly.

# Test: Search for the function usage. Expect: Function calls handle the `ModelProvider.Qwen` case.
rg --type js --type ts $'auth'

Length of output: 8722


Script:

#!/bin/bash
# Description: Verify the usage of the `auth` function in app/api/alibaba/[...path]/route.ts for handling ModelProvider.Qwen case

# Extract lines where `auth` function is called in the relevant file
rg 'auth\(.*ModelProvider\.Qwen' app/api/alibaba/[...path]/route.ts -C 5

Length of output: 331

Tools
Biome

[error] 79-79: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

app/store/access.ts (2)

50-53: LGTM!

The new Alibaba-related configurations are consistent with the existing pattern.


90-92: LGTM!

The new method isValidAlibaba is consistent with the existing pattern.

app/config/server.ts (2)

38-41: LGTM!

The new environment variables for Alibaba integration are consistent with the existing pattern.


Line range hint 99-135:
LGTM!

The new logic for Alibaba-specific checks and configurations is consistent with the existing pattern.

app/client/api.ts (2)

109-111: LGTM! Support for ModelProvider.Qwen added.

The new case for ModelProvider.Qwen is correctly implemented.


228-229: LGTM! Support for ServiceProvider.Alibaba added.

The new case for ServiceProvider.Alibaba is correctly implemented.

app/constant.ts (6)

17-18: LGTM! New constant ALIBABA_BASE_URL added.

The new constant ALIBABA_BASE_URL is correctly defined.


34-34: LGTM! New enum value Alibaba added to ApiPath.

The new enum value Alibaba is correctly defined.


78-78: LGTM! New enum value Alibaba added to ServiceProvider.

The new enum value Alibaba is correctly defined.


85-85: LGTM! New enum value Qwen added to ModelProvider.

The new enum value Qwen is correctly defined.


186-194: LGTM! New array alibabaModes added.

The new array alibabaModes is correctly defined.


233-241: LGTM! Updates to DEFAULT_MODELS array for Alibaba models added.

The updates to the DEFAULT_MODELS array are correctly implemented.

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

26-33: LGTM! New interface OpenAIListModelResponse added.

The new interface OpenAIListModelResponse is correctly defined.


35-47: LGTM! New interface RequestPayload added.

The new interface RequestPayload is correctly defined.


49-76: LGTM! New path method in QwenApi class added.

The new path method is correctly implemented.


78-80: LGTM! New extractMessage method in QwenApi class added.

The new extractMessage method is correctly implemented.


82-248: LGTM! New chat method in QwenApi class added.

The new chat method is correctly implemented.


249-253: LGTM! New usage method in QwenApi class added.

The new usage method is correctly implemented.


256-258: LGTM! New models method in QwenApi class added.

The new models method is correctly implemented.

app/client/platforms/openai.ts (1)

45-45: LGTM! RequestPayload interface is now exported.

The RequestPayload interface is correctly exported.

app/api/auth.ts Show resolved Hide resolved
app/api/alibaba/[...path]/route.ts Show resolved Hide resolved
app/api/alibaba/[...path]/route.ts Outdated Show resolved Hide resolved
}

extractMessage(res: any) {
return res.choices?.at(0)?.message?.content ?? "";
Copy link
Collaborator

Choose a reason for hiding this comment

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

结构应该有一些区别,这里需要再检查一下

}

async chat(options: ChatOptions) {
const visionModel = isVisionModel(options.config.model);
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里不用检查

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9bdd37b and 3628d68.

Files selected for processing (13)
  • README.md (2 hunks)
  • README_CN.md (2 hunks)
  • app/api/alibaba/[...path]/route.ts (1 hunks)
  • app/api/auth.ts (1 hunks)
  • app/api/bytedance/[...path]/route.ts (1 hunks)
  • app/client/api.ts (5 hunks)
  • app/client/platforms/alibaba.ts (1 hunks)
  • app/client/platforms/bytedance.ts (1 hunks)
  • app/components/chat.tsx (4 hunks)
  • app/config/server.ts (3 hunks)
  • app/constant.ts (6 hunks)
  • app/store/access.ts (3 hunks)
  • app/utils/model.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • README.md
Files skipped from review as they are similar to previous changes (6)
  • app/api/alibaba/[...path]/route.ts
  • app/client/api.ts
  • app/client/platforms/alibaba.ts
  • app/config/server.ts
  • app/constant.ts
  • app/store/access.ts
Additional context used
Biome
app/api/auth.ts

[error] 85-85: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

Additional comments not posted (16)
app/api/auth.ts (1)

82-84: Remove the redundant case clause.

The case for ModelProvider.Qwen is redundant due to the default clause.

-      case ModelProvider.Qwen:
-        systemApiKey = serverConfig.alibabaApiKey;
-        break;

Likely invalid or redundant comment.

app/utils/model.ts (1)

Line range hint 42-66:
LGTM! Verify the logic for the provider "bytedance".

The changes to initialize displayName as a let and the logic to swap name and displayName for the provider "bytedance" look good.

However, ensure that the logic for the provider "bytedance" is correct and consistent with the rest of the codebase.

app/api/bytedance/[...path]/route.ts (2)

15-39: LGTM! Verify the handling of ByteDance requests.

The changes to add the params parameter and handle ByteDance requests look good.

However, ensure that the handling of ByteDance requests is correct and consistent with the rest of the codebase.


65-153: LGTM! Verify the handling of HTTP requests and custom models.

The changes to add the request function to handle HTTP requests and custom models look good.

However, ensure that the handling of HTTP requests and custom models is correct and consistent with the rest of the codebase.

README_CN.md (2)

142-148: LGTM! Verify the new configuration parameters for ByteDance APIs.

The changes to add new configuration parameters BYTEDANCE_API_KEY and BYTEDANCE_URL for ByteDance APIs look good.

However, ensure that the new configuration parameters are correct and consistent with the rest of the documentation.


183-185: LGTM! Verify the new configuration parameters for ByteDance models.

The changes to add new configuration parameters for ByteDance models in the CUSTOM_MODELS section look good.

However, ensure that the new configuration parameters are correct and consistent with the rest of the documentation.

app/client/platforms/bytedance.ts (7)

26-33: LGTM!

The OpenAIListModelResponse interface is well-defined and correctly structured.


35-47: LGTM!

The RequestPayload interface is well-defined and correctly structured.


50-74: LGTM!

The path method is well-structured and correctly constructs the full URL.


76-78: LGTM!

The extractMessage method is well-structured and correctly extracts the message content from the response.


80-242: LGTM! But verify the animation logic.

The chat method is well-structured and correctly handles the chat interaction.

However, ensure that the use of requestAnimationFrame for animating response text is appropriate and performs as expected.


244-248: LGTM!

The usage method is well-structured and correctly returns the usage object.


251-253: LGTM!

The models method is well-structured and correctly returns an empty array of models.

app/components/chat.tsx (3)

Line range hint 470-619: LGTM!

The ChatActions function is well-structured and correctly handles various chat actions. The changes for handling the current model name and updating the session's model configuration are appropriate.


Line range hint 1-1032: LGTM! But verify the changes related to the current model name and session's model configuration.

The _Chat function is well-structured and correctly handles rendering the chat interface, user input, and chat session management.

However, ensure that the changes related to handling the current model name and updating the session's model configuration are appropriate and perform as expected.


Line range hint 1034-1037: LGTM!

The Chat function is well-structured and correctly renders the chat component based on the current session index.

<ListItem
title={Locale.Settings.Access.Alibaba.Endpoint.Title}
subTitle={
Locale.Settings.Access.Anthropic.Endpoint.SubTitle +
Copy link
Member Author

Choose a reason for hiding this comment

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

Alibaba

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3628d68 and 044c16d.

Files selected for processing (5)
  • README.md (2 hunks)
  • README_CN.md (2 hunks)
  • app/components/settings.tsx (2 hunks)
  • app/locales/cn.ts (1 hunks)
  • app/locales/en.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • README.md
  • README_CN.md
Additional comments not posted (7)
app/locales/cn.ts (2)

366-376: Add localization keys for ByteDance API settings.

The added localization keys for ByteDance API settings seem correct and consistent with the existing structure.


377-387: Add localization keys for Alibaba API settings.

The added localization keys for Alibaba API settings seem correct and consistent with the existing structure.

app/locales/en.ts (2)

353-363: Add localization keys for ByteDance API settings.

The added localization keys for ByteDance API settings seem correct and consistent with the existing structure.


364-374: Add localization keys for Alibaba API settings.

The added localization keys for Alibaba API settings seem correct and consistent with the existing structure.

app/components/settings.tsx (3)

57-58: Add imports for ByteDance and Alibaba constants.

The added imports for ByteDance and Alibaba constants are necessary for the new settings blocks.


1255-1298: Add conditional rendering block for ByteDance settings.

The conditional rendering block for ByteDance settings correctly integrates with the existing settings structure and provides the necessary functionality.


1300-1342: Add conditional rendering block for Alibaba settings.

The conditional rendering block for Alibaba settings correctly integrates with the existing settings structure and provides the necessary functionality.

@lloydzhou lloydzhou merged commit 844025e into ChatGPTNextWeb:main Jul 9, 2024
0 of 2 checks passed
@lloydzhou lloydzhou deleted the feature/alibaba branch August 1, 2024 05:13
This was referenced Sep 25, 2024
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