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: config hydration and default model forced to set gpt-3.5-turbo #5444

Merged
merged 2 commits into from
Sep 18, 2024

Conversation

skymkmk
Copy link
Contributor

@skymkmk skymkmk commented Sep 15, 2024

💻 变更类型 | Change Type

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

🔀 变更说明 | Description of Change

修复了持久模型不随源码更新而更新的问题

修复了当服务器未设置默认模型时默认模型不跟随 DEFAULT_CONFIG 而被强制设置为 gpt-3.5-turbo 的问题

📝 补充信息 | Additional Information

#5433 应当是历史遗留问题:zustand 在水和时,默认执行的是 {...currentState, ...persistedState},这样做很不幸 models 会被 persistedState 覆盖;同时 mergeModels 方法在 home 组件挂载时,会被执行一次,可见

export function useLoadData() {
const config = useAppConfig();
const api: ClientApi = getClientApi(config.modelConfig.providerName);
useEffect(() => {
(async () => {
const models = await api.llm.models();
config.mergeModels(models);
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}

可能是由于竞争的关系,很不幸 mergeModels 的努力会被 zustand 水合时给覆盖掉, 在开发时,React 严格模式会挂载组件 两次,而此刻 mergeModels 竞争过了水合,所以在开发模式下未重现此问题;而平常很多人的使用环境都是在 server 端 customize 模型,所以很难发现这种问题。

我认为所有找不到 o1 模型的人,理应也找不到 chatgpt-4o-latest 等随着时间更新的模型。个人愚见,欢迎讨论。

Summary by CodeRabbit

  • New Features
    • Introduced a new function to merge persisted application states, improving configuration management.
  • Improvements
    • Enhanced logic for setting default model configurations, ensuring clarity and better handling of model defaults.

Copy link

vercel bot commented Sep 15, 2024

@skymkmk 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 Sep 15, 2024

Walkthrough

The changes involve modifications to the logic within the useAccessStore and useAppConfig functions. In useAccessStore, the default model configuration logic is refined to ensure that fallback values are only used when no valid default model is provided. In useAppConfig, a new merge function is introduced to effectively combine persisted state with the current application state, enhancing model management.

Changes

Files Change Summary
app/store/access.ts Modified the logic in useAccessStore to update the default model configuration conditionally, ensuring fallback values are used only when necessary.
app/store/config.ts Introduced a new merge function in useAppConfig to merge persisted state with the current application state, updating or adding models as needed.

Possibly related PRs

🐰 In the code we hop and play,
With models bright, we find our way.
A merge of states, a clearer path,
In logic's dance, we find our math.
So let us cheer, with joy we sing,
For changes made, new hopes they bring! 🌟


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 027e5ad and 36a0c7b.

Files selected for processing (2)
  • app/store/access.ts (1 hunks)
  • app/store/config.ts (1 hunks)
Additional comments not posted (2)
app/store/config.ts (1)

147-159: LGTM! The merge function is a valuable addition to the useAppConfig store configuration.

The merge function effectively handles the merging of the persisted state with the current state of the application. It correctly checks for the existence of a persisted state and returns the current state unchanged if none exists. When a persisted state is present, it intelligently merges the models by updating existing models and adding new models based on the name and provider match.

The function enhances the application's ability to manage and synchronize configuration states, ensuring that the latest changes are preserved. The returned state object correctly combines the current state, persisted state, and updated models list.

Overall, the merge function is a well-implemented solution to the state management and synchronization challenges faced by the application.

app/store/access.ts (1)

207-208: LGTM! The conditional check improves the default model configuration.

The introduction of the conditional statement to update DEFAULT_CONFIG.modelConfig.model only when defaultModel is not an empty string is a positive change. It ensures that the default model is set correctly based on the server configuration and prevents the hardcoded fallback value from being used unnecessarily.

This change aligns with the PR objectives of properly hydrating the model configuration and addresses the issue of the default model being incorrectly set to "gpt-3.5-turbo" when the server does not have a default model configured.

The conditional check enhances the clarity and intent of the code by explicitly handling the case when defaultModel is an empty string, making the logic more readable and maintainable.


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 generate interesting stats about this repository and render them as a table.
    -- @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 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

Your build has completed!

Preview deployment

@Dogtiti Dogtiti merged commit d51bbb4 into ChatGPTNextWeb:main Sep 18, 2024
1 of 2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Sep 27, 2024
10 tasks
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.

3 participants