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

Refactor model table #4923

Merged
merged 8 commits into from
Jul 4, 2024
Merged

Conversation

lloydzhou
Copy link
Contributor

@lloydzhou lloydzhou commented Jul 4, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a more robust model availability check to improve the reliability of model selection in the server.
  • Improvements

    • Enhanced model mapping by including provider IDs, ensuring more precise model availability handling.
  • Bug Fixes

    • Revised logic in model availability checks and request handling to improve consistency and accuracy.
  • Code Refactor

    • Replaced collectModelTable function with isModelAvailableInServer for better clarity and performance in model availability determination.

@lloydzhou lloydzhou requested a review from Dogtiti July 4, 2024 07:44
Copy link

vercel bot commented Jul 4, 2024

@lloydzhou 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 4, 2024

Walkthrough

The recent updates introduce a new function isModelAvailableInServer to check model availability, replacing the older collectModelTable function. They also refine how model names and provider IDs are handled, impacting the logic across various modules, including API routing and configuration storage.

Changes

File Change Summary
app/api/anthropic/[...path]/route.ts Replaced collectModelTable with isModelAvailableInServer for model availability checks. Updated related logic accordingly.
app/api/common.ts Renamed collectModelTable to isModelAvailableInServer and revised requestOpenai function to reflect new model availability check logic. Adjusted logging and header handling.
app/store/config.ts Updated modelMap key assignment to include provider ID with the model name.
app/utils/model.ts Modified collectModelTable to handle model-provided names. Added a new function isModelAvailableInServer for model availability checks.

Poem

In the code where models dwell,
New logic rings a mighty bell,
Providers paired with names so bright,
Model checks now take the flight.
With changes made and code refined,
Availability we now define.
🐰✨


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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2803a91 and b9ffd50.

Files selected for processing (4)
  • app/api/anthropic/[...path]/route.ts (2 hunks)
  • app/api/common.ts (4 hunks)
  • app/store/config.ts (1 hunks)
  • app/utils/model.ts (4 hunks)
Additional context used
Biome
app/utils/model.ts

[error] 47-47: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (2)
app/utils/model.ts (1)

Line range hint 27-69:
LGTM!

The changes to handle model names with provider names and set availability are well-implemented.

Tools
Biome

[error] 47-47: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

app/store/config.ts (1)

119-124: LGTM!

The changes to use the provider name in the model key are well-implemented.

app/utils/model.ts Outdated Show resolved Hide resolved
app/api/anthropic/[...path]/route.ts Outdated Show resolved Hide resolved
app/api/common.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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b9ffd50 and 7a5596b.

Files selected for processing (1)
  • app/api/anthropic/[...path]/route.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/api/anthropic/[...path]/route.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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7a5596b and 97aa72e.

Files selected for processing (4)
  • app/api/anthropic/[...path]/route.ts (2 hunks)
  • app/api/common.ts (4 hunks)
  • app/store/config.ts (1 hunks)
  • app/utils/model.ts (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • app/api/anthropic/[...path]/route.ts
  • app/api/common.ts
Additional context used
Biome
app/utils/model.ts

[error] 47-47: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (6)
app/utils/model.ts (5)

47-47: Avoid assignment in an expression.

The assignment should not be in an expression as it can be confusing.

-        Object.values(modelTable).forEach(
-          (model) => (model.available = available),
-        );
+        Object.values(modelTable).forEach((model) => {
+          model.available = available;
+        });
Tools
Biome

[error] 47-47: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


55-55: Check for undefined model.

Ensure that the model exists in the modelTable before accessing the available property to avoid potential runtime errors.

-  return modelTable[modelName ?? ""].available === false;
+  return modelTable[modelName ?? ""]?.available === false;

Line range hint 79-90:
LGTM!

The function correctly adds the default model to the model table.


Line range hint 97-104:
LGTM!

The function correctly generates the model table.


Line range hint 108-115:
LGTM!

The function correctly adds the default model to the model table.

app/store/config.ts (1)

119-124: LGTM!

The changes correctly update the keys in modelMap to include the provider ID alongside the model name.

Copy link
Contributor

github-actions bot commented Jul 4, 2024

Your build has completed!

Preview deployment

@lloydzhou lloydzhou added enhancement New feature or request planned planned feature, will support in the future labels Jul 4, 2024
@lloydzhou lloydzhou self-assigned this Jul 4, 2024
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 97aa72e and 31d9444.

Files selected for processing (1)
  • app/utils/model.ts (4 hunks)
Additional context used
Biome
app/utils/model.ts

[error] 47-47: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (2)
app/utils/model.ts (2)

1-1: Import Statement: Ensure consistency and correctness.

The import statement for DEFAULT_MODELS is correct. Ensure that DEFAULT_MODELS is defined and exported correctly in ../constant.

Verification successful

Import Statement: Ensure consistency and correctness.

The import statement for DEFAULT_MODELS is correct, as it is defined and exported in app/constant.ts.

  • app/constant.ts: export const DEFAULT_MODELS = [ ... ];
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition and export of `DEFAULT_MODELS` in `../constant`.

# Test: Search for the definition of `DEFAULT_MODELS`. Expect: Correct definition and export.
rg --type typescript 'DEFAULT_MODELS' ../constant

Length of output: 84


Script:

#!/bin/bash
# Description: Verify the definition and export of `DEFAULT_MODELS` in `../constant`.

# Test: Search for the definition of `DEFAULT_MODELS`. Expect: Correct definition and export.
rg 'DEFAULT_MODELS' ../constant

Length of output: 83


Script:

#!/bin/bash
# Description: Locate the `constant` file and verify the definition and export of `DEFAULT_MODELS`.

# Step 1: Locate the `constant` file.
constant_file=$(fd -e ts -e tsx -e js -e jsx -e json -e mjs -e cjs -e mts -e cts -e d.ts -e d.tsx -e d.mts -e d.cts -e tsbuildinfo -e ts.map -e tsx.map -e js.map -e jsx.map -e mjs.map -e cjs.map -e mts.map -e cts.map -e d.ts.map -e d.tsx.map -e d.mts.map -e d.cts.map constant)

# Step 2: Verify the definition and export of `DEFAULT_MODELS` in the located `constant` file.
if [[ -n "$constant_file" ]]; then
  rg 'DEFAULT_MODELS' "$constant_file"
else
  echo "constant file not found"
fi

Length of output: 390


27-28: Provider-specific model names: Ensure correctness.

The change to use <modelName>@<providerId> as the full name is correct. Ensure that the provider.id is always defined.

app/utils/model.ts Show resolved Hide resolved
app/utils/model.ts Show resolved Hide resolved
app/utils/model.ts Show resolved Hide resolved
@Dogtiti Dogtiti merged commit c4a6c93 into ChatGPTNextWeb:main Jul 4, 2024
1 of 2 checks passed
@lloydzhou lloydzhou deleted the refactor-model-table branch August 1, 2024 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request planned planned feature, will support in the future
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants