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

fix custom models setting #6000

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

QAbot-zh
Copy link

@QAbot-zh QAbot-zh commented Dec 29, 2024

💻 变更类型 | Change Type

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

🔀 变更说明 | Description of Change

修复模型可用性检验后产生的新问题,在原项目中用户可以省略后缀@OpenAI或者使用任意非标准后缀标注 @xxx 来通过 OpenAI 格式调用指定模型,任意后缀导致无法直接通过模型名称索引到 modelTable,将 fullname 修改为 <modelName>@<providerType> 的形式,所有非标后缀使用默认 custom 作为后缀修饰,确保模型可以被索引到

一些相关话题:
#5001 (comment)
https://linux.do/t/topic/318245

📝 补充信息 | Additional Information

Summary by CodeRabbit

  • Bug Fixes

    • Improved model validation logic for server-side model availability checks.
    • Updated model naming convention to use provider type instead of provider ID.
  • Refactor

    • Refined OpenAI request handling process.
  • Tests

    • Added new test scenarios for custom model validation.
    • Updated test coverage for model availability checks, including custom models without specified providers.

Copy link

vercel bot commented Dec 29, 2024

@QAbot-zh is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Dec 29, 2024

Walkthrough

The pull request introduces modifications to model validation and handling across multiple files. In app/api/common.ts, the requestOpenai function's model validation logic is updated to include a new check for chat requests and to use "custom" as a static string for unspecified models. The app/utils/model.ts file changes how model full names are constructed, now using providerType instead of providerId. The accompanying test file test/model-available.test.ts adds new test cases to verify the updated model availability checking mechanism.

Changes

File Change Summary
app/api/common.ts Modified requestOpenai function to enhance model validation logic, including checks for chat requests and using "custom" for unspecified models.
app/utils/model.ts Updated collectModelTable to construct model full names using providerType instead of providerId.
test/model-available.test.ts Added new test cases for model availability checks, commented out existing multi-provider test case.

Possibly related PRs

Suggested labels

enhancement, help wanted

Suggested reviewers

  • Dogtiti

Poem

🐰 Hop, hop, through the code we go,
Models dancing, validation's new flow!
Custom strings and provider's might,
Refactoring with rabbit's delight!
Validation magic, smooth and clean,
A code adventure yet unseen! 🌟


📜 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 da9963d and ecc65fa.

📒 Files selected for processing (1)
  • app/utils/model.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/utils/model.ts

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. (Beta)
  • @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 (2)
app/utils/model.ts (1)

129-129: Ensure consistent sorting logic when building custom model entries.

Using CustomSeq.next with <modelName>@<providerType> is a valid approach. However, consider adding a brief comment about why the sequence is based on both the model name and provider type, which could help future maintainers quickly grasp the rationale behind this design.

Here’s a small diff you might consider:

+ // Use modelName@providerType to ensure uniqueness among custom providers
  sorted: CustomSeq.next(`${customModelName}@${provider?.providerType}`),
test/model-available.test.ts (1)

56-56: Remove or address this FIXME to maintain a clean test suite.

Leaving unfinished test cases may introduce confusion. If the test is genuinely problematic, consider deleting or refactoring it into a passing state.

Would you like me to propose a new test scenario that accurately covers multiple providers and ensures the correct pass/fail behavior?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e1cb8e3 and 24ff78e.

📒 Files selected for processing (3)
  • app/api/common.ts (1 hunks)
  • app/utils/model.ts (2 hunks)
  • test/model-available.test.ts (2 hunks)
🧰 Additional context used
📓 Learnings (1)
test/model-available.test.ts (1)
Learnt from: code-october
PR: ChatGPTNextWeb/ChatGPT-Next-Web#5883
File: test/model-available.test.ts:46-52
Timestamp: 2024-11-30T07:30:14.257Z
Learning: 在测试文件中,对于没有指定 provider 的模型,`providerNames` 应该设置为 `modelName`,`"Default"` 不是有效的 provider 参数,应避免使用。
🔇 Additional comments (4)
app/api/common.ts (1)

127-127: Consider verifying that "custom" as a provider does not overwrite a genuine provider.

By hardcoding the provider as "custom," there is a potential risk of overshadowing a valid provider if it wasn't properly identified earlier. Ensure that all genuine providers (e.g., "OpenAI", "Azure") are still routed correctly, and only truly unspecified models default to "custom."

Would you like a follow-up script that checks usage patterns of this provider in other files to confirm that “custom” is only used when no provider is determined?

app/utils/model.ts (1)

69-70: Implementation aligns with the new naming convention.

You've updated the model name to use <modelName>@<providerType> as the full identifier. This fits the PR objective of standardizing how custom providers are handled. Make sure all other references in the codebase have been updated accordingly.

test/model-available.test.ts (2)

72-79: Great coverage for custom models.

This test ensures that a user-specified model without an explicit provider defaults to “custom.” The assertion expect(result).toBe(false); correctly validates that the model is available.


81-84: Verify handling of non-standard providers.

By specifying "custom" for providerNames, you confirm that models with any unusual suffix (e.g., @DeepSeek) are recognized correctly. Ensure that additional exotic providers similarly fall under the correct logic if introduced in the future.

@QAbot-zh
Copy link
Author

新增修复,已通过本地测试

image

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Added fixes, passed local testing

image

@Dogtiti Dogtiti self-requested a review December 31, 2024 02:02
Copy link
Contributor

Your build has completed!

Preview deployment

@QAbot-zh
Copy link
Author

QAbot-zh commented Dec 31, 2024

这个 fail 看起来是另一个 vision-model-checker.test.ts 引起的,有什么办法只测试和当前 pr 相关的 test 文件吗 @Dogtiti

image

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