-
Notifications
You must be signed in to change notification settings - Fork 61.2k
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
修复app-config.models 重复保存的问题(#6266) #6268
base: main
Are you sure you want to change the base?
Conversation
@code-october is attempting to deploy a commit to the NextChat Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe changes update the merging logic within the Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant U as useAppConfig.merge
participant M as Models Array
C->>U: Call merge(model)
U->>M: Search for model by comparing:
note right of U: Checks include:\n- name\n- id\n- providerName\n- providerType
alt Model Found
M-->>U: Return matching index
U->>U: Update existing model with new data
else Model Not Found
M-->>U: No match found
U->>U: Add new model to array
end
U->>C: Return updated state
Poem
✨ Finishing Touches
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 (1)
app/store/config.ts (1)
205-210
: Consider extracting model comparison logic into a helper function.While the current implementation is correct, the comparison logic could be more maintainable if extracted into a helper function.
+ const isModelEqual = (model1: LLMModel, model2: LLMModel) => { + return model1.name === model2.name + && model1.provider.id === model2.provider.id + && model1.provider.providerName === model2.provider.providerName + && model1.provider.providerType === model2.provider.providerType; + }; const idx = models.findIndex( - (v) => v.name === pModel.name - && v.provider.id === pModel.provider.id - && v.provider.providerName === pModel.provider.providerName - && v.provider.providerType === pModel.provider.providerType, + (v) => isModelEqual(v, pModel) );
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/store/config.ts
(1 hunks)
🔇 Additional comments (2)
app/store/config.ts (2)
205-210
: LGTM! Enhanced model comparison logic prevents duplicate models.The expanded comparison logic now correctly identifies unique models by checking not just the name but also the provider's
id
,providerName
, andproviderType
. This fix effectively prevents duplicate model entries that could occur when models share the same name but have different providers.
205-210
: Add null checks for provider object to prevent runtime errors.The current implementation assumes the provider object and its properties always exist. Consider adding null checks to handle cases where the provider object might be undefined.
const idx = models.findIndex( (v) => v.name === pModel.name - && v.provider.id === pModel.provider.id - && v.provider.providerName === pModel.provider.providerName - && v.provider.providerType === pModel.provider.providerType, + && v.provider?.id === pModel.provider?.id + && v.provider?.providerName === pModel.provider?.providerName + && v.provider?.providerType === pModel.provider?.providerType, );
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
📝 补充信息 | Additional Information
Summary by CodeRabbit
Refactor
Style