-
Notifications
You must be signed in to change notification settings - Fork 60k
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
✨ feat: 调整模型列表,将自定义模型放在前面显示 #5180
Conversation
@frostime is attempting to deploy a commit to the NextChat Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe recent updates to the codebase enhance model management by introducing a new sorting function, Changes
Poem
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 as PR comments)
Additionally, you can add 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
Your build has completed! |
模型显示顺序和什么有关,我好像不同网页打开的显示顺序会不一样,有可能指定模型的排列顺序吗 |
What does the display order of models have to do with? It seems to me that the display order of different web pages will be different. Is it possible to specify the order of the models? |
app/utils/model.ts
Outdated
@@ -89,6 +80,15 @@ export function collectModelTable( | |||
} | |||
}); | |||
|
|||
// default models |
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.
简单的把这个default models移到后面,可能会有一些逻辑上的问题。
正确的处理方法,应该是不更改这里的逻辑,而是在 collectModels
函数中Object.values
后面引入一个排序逻辑
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.
好的,我在新的 commit (b023) 中,去掉了之前的实现方式;并按照你的建议,在 collect 函数后面增加了额外的排序处理。
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: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- app/utils/model.ts (4 hunks)
Additional comments not posted (7)
app/utils/model.ts (7)
14-31
: Sorting logic looks good.The sorting logic for custom and default models is clear and appears to be implemented correctly.
10-11
: Verify the handling of models without providers.The function correctly handles models where the
provider
isundefined
. Ensure this case is adequately tested.
125-134
: Verify the correctness of marking the default model.Ensure that the default model is correctly marked and the model table is updated accurately.
Line range hint
177-179
:
Verify the correctness of model availability check.Ensure that the function correctly determines if a model is available in the server.
169-172
: Verify the correctness of model collection, marking, and sorting.Ensure that models are collected, marked, and sorted correctly using the new
sortModelTable
function.
34-34
: Verify the correctness of custom model processing.Ensure that custom models are processed correctly and the model table is populated accurately.
152-154
: Verify the correctness of model collection and sorting.Ensure that models are collected and sorted correctly using the new
sortModelTable
function.
app/utils/model.ts
Outdated
if (aIsCustom) { | ||
return rule === "custom-first" ? -1 : 1; | ||
} else { | ||
return rule === "custom-first" ? 1 : -1; |
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.
这里排序,else的情况下,是否可以按providerType本身的字符顺序 + model_name的字符顺序排序?
这样的化,不是自定义模型的时候,其实也会有一个固定的顺序,而不会因为Object.values导致顺序不稳定。有的时候这个在前面,有的时候哪个在前面。
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.
好的,我回去后弄一下👌
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.
启用 -all 后能否直接按照自定义模型字符串的顺序来
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.
启用 -all 后能否直接按照自定义模型字符串的顺序来
你说的涉及到多个排序显示方案了。这个需要改动设置界面,增加更多选项。
这个 PR 里是写死了只有 custom first 的排序。虽然为了逻辑的完整,在 sort 函数里面定义了一个参数 rule
,但是实际上调用的时候只有 custom-first
一种方案会被使用。
后面也许会再提交别的 PR ,看看能否支持更多的排序方案。
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.
另外还有一点:
如果aIsCustom=ture以及aIsCustom也为true的时候,是不是也应该按字母顺序排序?
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.
或许应该换一种思路:
- 引入一个新的sorted字段进行排序
- constant.ts中对内置的provider配置排序字段
// constant let seq = 1000; // 内置的模型序号生成器从1000开始 export const DEFAULT_MODELS = [ ...openaiModels.map((name) => ({ name, available: true, sorted: seq++, // 这里使用一个全局的序号生成器 provider: { id: "openai", providerName: "OpenAI", providerType: "openai", sorted: 1 // 这里是固定的,确保顺序与之前内置的版本一致 }, })), // ...... ] as const;
- utils/model.ts中,针对新生成的模型,使用一个新的序号生成器(从-1000开始)确保排序在前面
let customSeq = -1000 // 这个是自定义的模型以及自定义的customProvider使用同一个序号生成器,从-1000开始自增 // 下面是确保自定义的model以及provider的sorted是负数,排序会在前面 const customProvider = (providerName: string) => ({ id: providerName.toLowerCase(), providerName: providerName, providerType: "custom", sorted: customSeq++, }); modelTable[`${customModelName}@${provider?.id}`] = { name: customModelName, displayName: displayName || customModelName, available, provider, // Use optional chaining sorted: customSeq++ };
- 更新sortModelTable函数,分别使用对应的sorted字段顺序排序即可
好的,commit 150fc 实现了你说的这个方案。
另外你提到的 customSeq
有点问题,由于 model.ts 会反复执行,所以这个变量会一直增长。出于鲁棒性的考量,我给改成了基于 map 的方案。其他的实现和你说的应该都是一致的。
排序的时候,首先比较 provider,然后比较 model。
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.
customSeq变量如果在module这一层。应该就不会无限制增长。
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.
啊呀,workflow 检查没过;加了一个 sorted 字段之后别的地方还得改,麻烦了😢。
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.
你的方案应该是正确的,这里会持续运行,确实会一直增长
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.
提交之前,可以本地使用 yarn run build 或者 yarn run export检查一下。
1. 在 Model 和 Provider 类型中增加 sorted 字段(api.ts) 2. 默认模型在初始化的时候,自动设置默认 sorted 字段,从 1000 开始自增长(constant.ts) 3. 自定义模型更新的时候,自动分配 sorted 字段(model.ts)
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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- app/client/api.ts (1 hunks)
- app/constant.ts (1 hunks)
- app/utils/model.ts (6 hunks)
Additional comments not posted (15)
app/utils/model.ts (6)
17-22
: LGTM!The
customProvider
function correctly utilizesCustomSeq.next
to assign a sequence number to each custom provider.
4-16
: Ensure efficient sequence management and cache usage.The
CustomSeq
object manages a sequence for custom models and caches the results for efficiency. Verify that the sequence management is efficient and the cache is used correctly to avoid potential performance issues.
Line range hint
39-118
:
Verify correctness of modifications.The
collectModelTable
function has been modified to include thesorted
property for models. Verify that the modifications are correct and do not introduce any issues.Verification successful
Modifications are correct and do not introduce any issues.
The
sorted
property is correctly implemented and utilized across the codebase. No issues were found related to the modifications in thecollectModelTable
function.
app/utils/model.ts
: Thesorted
property is set usingCustomSeq.next
and is used in sorting operations.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness of modifications to `collectModelTable`. # Test: Search for the usage of `collectModelTable`. Expect: Correct modifications and no introduced issues. rg --type ts -A 5 $'collectModelTable'Length of output: 1615
Script:
#!/bin/bash # Description: Verify the usage of the `sorted` property in the codebase. # Test: Search for the usage of the `sorted` property. Expect: Correct implementation and no introduced issues. rg --type ts 'sorted'Length of output: 1230
25-38
: Ensure robustness and efficiency of sorting logic.The
sortModelTable
function sorts an array of models based on their provider and model properties. Verify that the sorting logic handles all edge cases and performs efficiently.Verification successful
The sorting logic in
sortModelTable
is robust and efficient.The
modelTable
construction handles various cases, including setting theavailable
status, swappingname
anddisplayName
for specific providers, and setting default models. This suggests that edge cases are being considered, and the sorting logic is robust.
modelTable
is constructed usingcollectModelTable
andcollectModelTableWithDefaultModel
.- Various properties and edge cases are handled during the construction of
modelTable
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the robustness and efficiency of the sorting logic in `sortModelTable`. # Test: Search for the usage of `sortModelTable`. Expect: Robust handling of edge cases and efficient performance. rg --type ts -A 5 $'sortModelTable'Length of output: 852
Script:
#!/bin/bash # Description: Verify how `allModels` is constructed and manipulated to ensure edge cases are handled. # Search for the construction and manipulation of `allModels` within the file. rg --type ts -A 5 $'allModels'Length of output: 2693
Script:
#!/bin/bash # Description: Verify how `modelTable` is constructed and manipulated to ensure edge cases are handled. # Search for the construction and manipulation of `modelTable` within the codebase. rg --type ts -A 5 $'modelTable'Length of output: 4665
161-163
: Verify correctness of modifications.The
collectModels
function has been modified to callsortModelTable
. Verify that the modifications are correct and do not introduce any issues.
178-181
: Verify correctness of modifications.The
collectModelsWithDefaultModel
function has been modified to callsortModelTable
. Verify that the modifications are correct and do not introduce any issues.app/client/api.ts (2)
74-74
: Verify consistent usage ofsorted
property.The
LLMModelProvider
interface has been modified to include a newsorted
property. Verify that this property is used consistently throughout the codebase.
67-67
: Verify consistent usage ofsorted
property.The
LLMModel
interface has been modified to include a newsorted
property. Verify that this property is used consistently throughout the codebase.Verification successful
The
sorted
property is used consistently throughout the codebase.The
sorted
property in theLLMModel
interface is correctly integrated and used for sorting operations and assignments in the relevant files.
app/client/api.ts
app/constant.ts
app/utils/model.ts
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the consistent usage of the `sorted` property in `LLMModel`. # Test: Search for the usage of `LLMModel` and ensure the `sorted` property is used consistently. rg --type ts -A 5 $'LLMModel'Length of output: 7669
Script:
#!/bin/bash # Description: Verify the usage of the `sorted` property within the identified files. # List of files to check for the usage of the `sorted` property. files=( "app/utils/model.ts" "app/store/config.ts" "app/client/platforms/tencent.ts" "app/client/platforms/moonshot.ts" "app/client/platforms/google.ts" "app/client/platforms/openai.ts" "app/client/platforms/baidu.ts" "app/client/platforms/alibaba.ts" "app/client/platforms/bytedance.ts" ) # Search for the usage of the `sorted` property in the identified files. for file in "${files[@]}"; do echo "Checking file: $file" rg --type ts "sorted" "$file" doneLength of output: 2212
Script:
#!/bin/bash # Description: Verify the usage of the `sorted` property in all TypeScript files. # Search for the usage of the `sorted` property in all TypeScript files. rg --type ts "sorted"Length of output: 1230
app/constant.ts (7)
323-333
: Verify correctness and consistency ofsorted
property.The
openaiModels
entries have been modified to include asorted
property. Verify that this property is used consistently and does not introduce any issues.Verification successful
Verification successful: The
sorted
property is used consistently inopenaiModels
entries.The
sorted
property in theopenaiModels
entries is assigned usingseq++
, and this pattern is consistently applied for both OpenAI and Azure providers. No issues were found regarding the usage of thesorted
property.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness and consistency of the `sorted` property in `openaiModels` entries. # Test: Search for the usage of `openaiModels` and ensure the `sorted` property is used consistently. rg --type ts -A 5 $'openaiModels'Length of output: 715
372-377
: Verify correctness and consistency ofsorted
property.The
baiduModels
entries have been modified to include asorted
property. Verify that this property is used consistently and does not introduce any issues.Verification successful
The
sorted
property is used correctly and consistently within thebaiduModels
entries.The
baiduModels
entries inapp/constant.ts
include thesorted
property, and its usage is consistent within this file. There are no other occurrences ofbaiduModels
in the codebase that could introduce issues.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness and consistency of the `sorted` property in `baiduModels` entries. # Test: Search for the usage of `baiduModels` and ensure the `sorted` property is used consistently. rg --type ts -A 5 $'baiduModels'Length of output: 491
Script:
#!/bin/bash # Description: Search for all occurrences of `baiduModels` in the codebase to verify the usage of the `sorted` property. # Test: Search for all occurrences of `baiduModels` in the TypeScript files. rg --type ts 'baiduModels'Length of output: 114
394-399
: Verify correctness and consistency ofsorted
property.The
alibabaModes
entries have been modified to include asorted
property. Verify that this property is used consistently and does not introduce any issues.Verification successful
The
sorted
property is used correctly and consistently.The
sorted
property within thealibabaModes
entries inapp/constant.ts
is used both dynamically and statically to maintain a sequence order. This usage is consistent and appears to be intentional.
- The dynamic assignment using
seq++
ensures a sequential order.- The static assignments with fixed values ensure specific order for certain entries.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness and consistency of the `sorted` property in `alibabaModes` entries. # Test: Search for the usage of `alibabaModes` and ensure the `sorted` property is used consistently. rg --type ts -A 5 $'alibabaModes'Length of output: 455
Script:
#!/bin/bash # Description: Verify the usage of `sorted` property in app/constant.ts # Test: Search for all instances of the `sorted` property in the `app/constant.ts` file. rg --type ts 'sorted' app/constant.tsLength of output: 417
405-410
: Verify correctness and consistency ofsorted
property.The
tencentModels
entries have been modified to include asorted
property. Verify that this property is used consistently and does not introduce any issues.Verification successful
Verify initialization of
seq
and consistent usage ofsorted
property.The
tencentModels
entries include asorted
property that is incremented usingseq++
. Verify thatseq
is initialized correctly and that thesorted
property is used consistently across the codebase.
The
sorted
property is used correctly and consistently.The
seq
variable is initialized correctly, and thesorted
property is used consistently across the codebase without introducing any issues.
seq
is initialized inapp/constant.ts
with a value of 1000.- The
sorted
property is used in multiple files, includingapp/constant.ts
,app/utils/model.ts
, andapp/client/api.ts
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness and consistency of the `sorted` property in `tencentModels` entries. # Test: Search for the usage of `tencentModels` and ensure the `sorted` property is used consistently. rg --type ts -A 5 $'tencentModels'Length of output: 476
Script:
#!/bin/bash # Description: Verify the initialization of `seq` and consistent usage of `sorted` property in the codebase. # Test 1: Search for the initialization of the `seq` variable. rg --type ts 'let seq =' # Test 2: Search for the usage of the `sorted` property in the codebase. rg --type ts 'sorted'Length of output: 1362
350-355
: Verify correctness and consistency ofsorted
property.The
googleModels
entries have been modified to include asorted
property. Verify that this property is used consistently and does not introduce any issues.Verification successful
Verify correctness and consistency of
sorted
property.The
googleModels
entries have been modified to include asorted
property. Verify that this property is used consistently and does not introduce any issues by examining all references togoogleModels
in the codebase.
Verification successful:
sorted
property usage ingoogleModels
is correct and consistent.The
googleModels
entries have been modified to include asorted
property, and it is used consistently within the mapping function inapp/constant.ts
. There are no other references togoogleModels
in the codebase.
app/constant.ts
: Thesorted
property is correctly assigned within the mapping function.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness and consistency of the `sorted` property in `googleModels` entries. # Test: Search for the usage of `googleModels` and ensure the `sorted` property is used consistently. rg --type ts -A 5 $'googleModels'Length of output: 473
Script:
#!/bin/bash # Description: Search for all references to `googleModels` in the codebase to verify the consistent and correct usage of the `sorted` property. # Test: Find all references to `googleModels` and check for the usage of the `sorted` property. rg --type ts 'googleModels'Length of output: 117
361-366
: Verify correctness and consistency ofsorted
property.The
anthropicModels
entries have been modified to include asorted
property. Verify that this property is used consistently and does not introduce any issues.Verification successful
Verify the usage of the
sorted
property across the codebase.The
sorted
property has been added to theanthropicModels
entries. We need to ensure that this property is used correctly and consistently across the codebase. Let's search for the usage of thesorted
property to confirm its correctness.
The
sorted
property is used correctly and consistently.The
sorted
property has been verified to be used correctly and consistently across the codebase. It is primarily used for sorting models and providers, and its implementation aligns with the intended functionality.
app/constant.ts
: Thesorted
property is assigned sequentially to each model entry.app/utils/model.ts
: Thesorted
property is used in sorting functions to order models and providers.app/client/api.ts
: Thesorted
property is defined and used appropriately.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness and consistency of the `sorted` property in `anthropicModels` entries. # Test: Search for the usage of `anthropicModels` and ensure the `sorted` property is used consistently. rg --type ts -A 5 $'anthropicModels'Length of output: 497
Script:
#!/bin/bash # Description: Verify the usage of the `sorted` property across the codebase. # Test: Search for the usage of the `sorted` property in TypeScript files to ensure it is used correctly and consistently. rg --type ts 'sorted'Length of output: 1230
383-388
: Verify correctness and consistency ofsorted
property.The
bytedanceModels
entries have been modified to include asorted
property. Verify that this property is used consistently and does not introduce any issues.Verification successful
We need to verify the correctness and consistency of the
sorted
property in thebytedanceModels
entries. Let's search for all instances wherebytedanceModels
is used to ensure thesorted
property is being utilized correctly.
To ensure the
sorted
property is set correctly, we need to verify the definition and initialization of theseq
variable withinapp/constant.ts
.
The
sorted
property inbytedanceModels
entries is correctly and consistently used.The
seq
variable is initialized to 1000 and is used to set thesorted
property by incrementing it for each entry, ensuring unique values. No issues were found with the usage of thesorted
property.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness and consistency of the `sorted` property in `bytedanceModels` entries. # Test: Search for the usage of `bytedanceModels` and ensure the `sorted` property is used consistently. rg --type ts -A 5 $'bytedanceModels'Length of output: 485
Script:
#!/bin/bash # Search for all instances where `bytedanceModels` is used in the codebase. rg --type ts 'bytedanceModels'Length of output: 126
Script:
#!/bin/bash # Search for the definition and initialization of the `seq` variable in `app/constant.ts`. rg --type ts 'seq' app/constant.tsLength of output: 273
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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- app/client/platforms/openai.ts (1 hunks)
Additional comments not posted (3)
app/client/platforms/openai.ts (3)
414-415
: Verify the initialization ofseq
variable.The
seq
variable is initialized to 1000 to maintain consistency withConstant.ts
. Ensure that this value is appropriate and consistent with the sorting logic inConstant.ts
.Verification successful
Verified the initialization of
seq
variable.The
seq
variable is correctly initialized to 1000 inapp/client/platforms/openai.ts
, maintaining consistency withConstant.ts
.
app/constant.ts
:let seq = 1000; // 内置的模型序号生成器从1000开始
app/client/platforms/openai.ts
:let seq = 1000; //同 Constant.ts 中的排序保持一致
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the value of `seq` in `Constant.ts`. # Test: Search for the initialization of `seq` in `Constant.ts`. Expect: Value should be consistent with 1000. rg --type ts 'seq = 1000'Length of output: 156
424-424
: Ensure thesorted
property is correctly set for providers.The
sorted
property is added to each provider to ensure a specific order. Verify that this property is correctly set and used in the application.Verification successful
The
sorted
property is correctly set and used for providers. The property is consistently assigned and utilized across the application to ensure the correct order of providers.
app/constant.ts
: Uses both static values and dynamic sequences forsorted
property.app/utils/model.ts
: Utilizessorted
property for sorting logic.app/client/api.ts
: Definessorted
property.app/client/platforms/openai.ts
: Assignssorted
property dynamically.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `sorted` property for providers in the codebase. # Test: Search for the usage of `sorted` property for providers. Expect: The property should be used consistently for sorting providers. rg --type ts 'provider.*sorted'Length of output: 185
Script:
#!/bin/bash # Description: Verify the definition and assignment of `sorted` property for providers in the codebase. # Search for the definition of `sorted` property in TypeScript files. rg --type ts 'sorted' # Search for the assignment of `sorted` property in TypeScript files. rg --type ts 'sorted:'Length of output: 2390
419-419
: Ensure thesorted
property is correctly set for models.The
sorted
property is added to each model to ensure a specific order. Verify that this property is correctly set and used in the application.Verification successful
The
sorted
property is correctly set and used for sorting models.
- The
sorted
property is consistently used in thecustomProvider
function and when adding custom models to themodelTable
.- The
sortModelTable
function sorts models first by thesorted
property of the provider and then by thesorted
property of the model itself, ensuring the correct order.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `sorted` property in the codebase. # Test: Search for the usage of `sorted` property. Expect: The property should be used consistently for sorting models. rg --type ts 'sorted'Length of output: 1332
Script:
#!/bin/bash # Extract relevant code snippets around the usage of `sorted` to verify the sorting logic. # Extract 5 lines before and after the usage of `sorted` in app/utils/model.ts rg --type ts 'sorted' -A 5 -B 5 app/utils/model.tsLength of output: 1289
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
📝 补充信息 | Additional Information
效果展示:
Summary by CodeRabbit
sorted
property for better ordering and prioritization.