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

Feature/byte dance #4939

Merged
merged 12 commits into from
Jul 9, 2024
Merged

Conversation

Dogtiti
Copy link
Member

@Dogtiti Dogtiti commented Jul 6, 2024

Summary by CodeRabbit

  • New Features

    • Added support for ByteDance in the Settings component, allowing users to configure ByteDance endpoints and API keys.
  • Enhancements

    • Introduced a new Doubao model provider for ByteDance, enabling integration with ByteDance services.
    • Updated chat components to display a more user-friendly model name for ByteDance models.
    • Improved localization with new ByteDance-related fields in both English and Chinese.
  • Configuration

    • Added server-side configurations to support Bytedance API keys and URLs.
  • Localization

    • Added localization keys for ByteDance fields, including API key and endpoint, in both English and Chinese.

@Dogtiti Dogtiti requested a review from lloydzhou July 6, 2024 15:00
Copy link

vercel bot commented Jul 6, 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 6, 2024

Walkthrough

This update integrates the Doubao model provider from ByteDance across the system. Key changes include new authentication handling for Doubao, the creation of a proxy route for ByteDance APIs, a new DoubaoApi class for client interactions, and added configuration support in settings. Localization entries for ByteDance and corresponding adjustments to the chat interface and model management functions have also been made.

Changes

Files/Directories Summary
app/api/auth.ts Added new case for ModelProvider.Doubao handling ByteDance authentication using serverConfig.bytedanceApiKey.
app/api/bytedance/[...path]/route.ts Introduced handler handle, constants GET, POST, runtime, preferredRegion, and function request.
app/client/api.ts Incorporated DoubaoApi for ByteDance platform support.
app/client/platforms/bytedance.ts Implemented DoubaoApi class for interacting with ByteDance services.
app/components/chat.tsx Enhanced ChatActions to display model names and handle provider-specific scenarios.
app/config/server.ts Added support for Bytedance configurations with BYTEDANCE_URL and BYTEDANCE_API_KEY.
app/constant.ts Added Bytedance constants and updated enums such as ApiPath, ServiceProvider, ModelProvider.
app/store/access.ts Updated DEFAULT_ACCESS_STATE and introduced methods isValidByteDance and related checks.
app/utils/model.ts Modified collectModelTable function to handle Bytedance model name configurations.
app/components/settings.tsx Added UI elements for configuring ByteDance endpoints and API keys.
app/locales/cn.ts and app/locales/en.ts Added localization keys for ByteDance API and endpoint fields.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant ByteDanceProxy
    participant ByteDanceAPI

    User->>App: Configure ByteDance API Key
    App->>App: Save configuration

    User->>App: Request model list
    App->>ByteDanceProxy: Forward request
    ByteDanceProxy->>ByteDanceAPI: Fetch models
    ByteDanceAPI->>ByteDanceProxy: Return models
    ByteDanceProxy->>App: Provide models
    App->>User: Display models
Loading
sequenceDiagram
    participant User
    participant App
    participant DoubaoApi

    User->>App: Initiate chat
    App->>DoubaoApi: Send chat request
    DoubaoApi->>App: Receive chat response
    App->>User: Display chat response
Loading

Poem

A ByteDance flowed into our stream,
Code enhanced with Doubao's gleam.
Chat and chat with ease you'll find,
Models dancing in your mind.
Settings polished, configs set,
ByteDance support? You bet!
APIs now with a new role,
Brought to life—a rabbit's goal.
🐇✨


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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7218f13 and 1caa61f.

Files selected for processing (8)
  • app/api/auth.ts (1 hunks)
  • app/api/bytedance/[...path]/route.ts (1 hunks)
  • app/client/api.ts (3 hunks)
  • app/client/platforms/bytedance.ts (1 hunks)
  • app/config/server.ts (3 hunks)
  • app/constant.ts (6 hunks)
  • app/store/access.ts (3 hunks)
  • app/utils/model.ts (2 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 (24)
app/store/access.ts (2)

50-52: LGTM!

The addition of ByteDance API key and URL in DEFAULT_ACCESS_STATE is correct.


90-92: LGTM!

The isValidByteDance function is correct and consistent with other similar validation functions.

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

15-39: LGTM!

The handle function is well-structured and handles errors appropriately.


44-63: LGTM!

The runtime and preferredRegion settings are appropriate for the intended use case.


65-159: Review the use of the duplex option in fetchOptions.

The duplex option is non-standard and might cause issues in some environments.

Please verify its necessity and compatibility.


105-134: LGTM!

The model availability check is correct and necessary for restricting access to certain models.

app/config/server.ts (3)

38-40: LGTM!

The addition of BYTEDANCE_URL and BYTEDANCE_API_KEY in the global declaration looks good.


99-99: LGTM!

The addition of isBytedance to check for the presence of the ByteDance API key looks good.


134-137: LGTM!

The addition of bytedanceApiKey and bytedanceUrl in the server-side configuration looks good.

app/client/api.ts (3)

12-12: LGTM!

The import of DoubaoApi looks good.


109-111: LGTM!

The addition of DoubaoApi in the ClientApi class looks good.


228-229: LGTM!

The addition of DoubaoApi in the getClientApi function looks good.

app/constant.ts (7)

17-18: LGTM!

The addition of BYTEDANCE_BASE_URL looks good.


33-33: LGTM!

The addition of ByteDance in the ApiPath enum looks good.


77-77: LGTM!

The addition of ByteDance in the ServiceProvider enum looks good.


84-84: LGTM!

The addition of Doubao in the ModelProvider enum looks good.


112-115: LGTM!

The addition of ByteDance endpoints looks good.


186-193: LGTM!

The addition of Doubao models looks good.


232-240: LGTM!

The addition of Doubao models to the DEFAULT_MODELS array looks good.

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

1-9: LGTM!

The imports for the DoubaoApi class look good.


26-33: LGTM!

The addition of the OpenAIListModelResponse interface looks good.


35-47: LGTM!

The addition of the RequestPayload interface looks good.


49-259: LGTM!

The implementation of the DoubaoApi class looks good.


260-260: LGTM!

The export of ByteDance looks good.

app/api/auth.ts Show resolved Hide resolved
app/utils/model.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@lloydzhou lloydzhou left a comment

Choose a reason for hiding this comment

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

另外,这个pr缺少配置文档,需要在readme 以及readme_cn里面体现

app/client/platforms/bytedance.ts Outdated Show resolved Hide resolved
app/client/platforms/bytedance.ts Outdated Show resolved Hide resolved
app/client/platforms/bytedance.ts Show resolved Hide resolved
app/constant.ts Outdated Show resolved Hide resolved
app/utils/model.ts Outdated Show resolved Hide resolved
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

Outside diff range and nitpick comments (1)
app/config/server.ts (1)

48-51: Add comments for new environment variables.

Adding comments for new environment variables helps maintain clarity and understanding.

      // bytedance only
      BYTEDANCE_URL?: string; // ByteDance API URL
      BYTEDANCE_API_KEY?: string; // ByteDance API Key
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1caa61f and b302354.

Files selected for processing (6)
  • app/api/auth.ts (1 hunks)
  • app/client/api.ts (3 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 as they are similar to previous changes (3)
  • app/api/auth.ts
  • app/constant.ts
  • app/store/access.ts
Additional comments not posted (7)
app/utils/model.ts (2)

42-42: Simplify the code for swapping name and displayName.

Use destructuring assignment to simplify the code.

-            if (providerName === "bytedance") {
-              const tempName = name;
-              name = displayName;
-              displayName = tempName;
-              modelTable[fullName]["name"] = name;
-            }
+            if (providerName === "bytedance") {
+              [name, displayName] = [displayName, name];
+              modelTable[fullName]["name"] = name;
+            }

62-66: Simplify the code for swapping name and displayName.

Use destructuring assignment to simplify the code.

-            if (providerName === "bytedance") {
-              const tempName = name;
-              name = displayName;
-              displayName = tempName;
-              modelTable[fullName]["name"] = name;
-            }
+            if (providerName === "bytedance") {
+              [name, displayName] = [displayName, name];
+              modelTable[fullName]["name"] = name;
+            }
app/config/server.ts (2)

110-110: Ensure proper handling of ByteDance configurations.

Verify that the isBytedance flag is correctly utilized in the rest of the codebase.


147-150: Ensure correct initialization of ByteDance configurations.

Verify that bytedanceApiKey and bytedanceUrl are correctly used in the codebase.

app/client/api.ts (3)

13-13: Import statement added for DoubaoApi.

The import statement for DoubaoApi is correctly added.


113-115: Ensure proper initialization of DoubaoApi.

Verify that the DoubaoApi initialization is correctly integrated and tested.


234-235: Ensure proper handling of ByteDance provider in getClientApi.

Verify that the ByteDance provider is correctly handled and tested in the getClientApi function.

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 b302354 and 9d7e19c.

Files selected for processing (3)
  • app/api/bytedance/[...path]/route.ts (1 hunks)
  • app/client/platforms/bytedance.ts (1 hunks)
  • app/components/chat.tsx (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • app/api/bytedance/[...path]/route.ts
  • app/client/platforms/bytedance.ts
Additional comments not posted (3)
app/components/chat.tsx (3)

470-477: LGTM! The use of useMemo for currentModelName is appropriate.

The use of useMemo to memoize the currentModelName ensures that the value is only recalculated when necessary, optimizing performance.


500-504: LGTM! The useEffect hook correctly handles model availability and image upload visibility.

The useEffect hook ensures that the application switches to the first available model if the current model is unavailable and handles the visibility of the upload image button based on the current model.


611-619: LGTM! The onSelection callback correctly updates the session and displays the appropriate model information.

The onSelection callback updates the current session's model configuration and displays a toast message with the selected model's display name or name based on the provider.

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 9d7e19c and 1149d45.

Files selected for processing (1)
  • app/client/platforms/bytedance.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/platforms/bytedance.ts

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 1149d45 and bb349a0.

Files selected for processing (4)
  • README.md (2 hunks)
  • README_CN.md (2 hunks)
  • app/client/api.ts (5 hunks)
  • app/components/chat.tsx (4 hunks)
Files skipped from review due to trivial changes (1)
  • README.md
Files skipped from review as they are similar to previous changes (1)
  • app/components/chat.tsx
Additional comments not posted (7)
README_CN.md (2)

142-145: LGTM! Documentation for BYTEDANCE_API_KEY is clear and well-formatted.

The addition of BYTEDANCE_API_KEY is correctly documented.


146-149: LGTM! Documentation for BYTEDANCE_URL is clear and well-formatted.

The addition of BYTEDANCE_URL is correctly documented.

app/client/api.ts (5)

13-13: LGTM! Import statement for DoubaoApi is correctly added.

The addition of DoubaoApi import is necessary for the integration.


113-115: LGTM! Case for ModelProvider.Doubao is correctly implemented.

The addition follows the existing pattern for initializing APIs.


183-192: LGTM! ByteDance check in getConfig function is correctly implemented.

The addition follows the existing pattern for checking different providers.


218-225: LGTM! ByteDance check in getHeaders function is correctly implemented.

The addition follows the existing pattern for checking different providers.


254-255: LGTM! Case for ServiceProvider.ByteDance is correctly implemented.

The addition follows the existing pattern for returning ClientApi instances.

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 bb349a0 and 7573a19.

Files selected for processing (3)
  • app/components/settings.tsx (2 hunks)
  • app/locales/cn.ts (1 hunks)
  • app/locales/en.ts (1 hunks)
Additional comments not posted (4)
app/locales/cn.ts (1)

366-376: Localization keys for ByteDance integration look good.

The added keys follow the existing structure and naming conventions.

app/locales/en.ts (1)

353-363: Localization keys for ByteDance integration look good.

The added keys follow the existing structure and naming conventions.

app/components/settings.tsx (2)

57-57: Imports for ByteDance integration look good.

The added imports are consistent with the existing import structure.


1253-1297: Settings components for ByteDance integration look good.

The added settings components follow the existing structure and naming conventions.

app/components/settings.tsx Outdated Show resolved Hide resolved
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 7573a19 and cd4784c.

Files selected for processing (1)
  • app/components/settings.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/components/settings.tsx

@lloydzhou lloydzhou merged commit 94bc91c into ChatGPTNextWeb:main Jul 9, 2024
0 of 2 checks passed
@lloydzhou lloydzhou deleted the feature/ByteDance branch August 1, 2024 05:13
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