Skip to content

Commit 6c99862

Browse files
authored
chore: 优化模型分组逻辑 (#60)
1 parent a13226d commit 6c99862

File tree

4 files changed

+50
-13
lines changed

4 files changed

+50
-13
lines changed

images/image-list-model.jpg

72.5 KB
Loading

ui/ModelModal/src/components/Tags/ModelCapabilities/CodeTag.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const CodeTag = ({ size, showTooltip, showLabel, ...restProps }: Props) =
1515
<CustomTag
1616
size={size}
1717
color="#6366f1"
18-
icon="Code"
18+
icon="代码生成"
1919
tooltip={showTooltip ? t('models.type.code_generation') : undefined}
2020
{...restProps}>
2121
{showLabel ? t('models.type.code_generation') : ''}

ui/ModelModal/src/components/Tags/ModelCapabilities/ReasoningTag.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const ReasoningTag = ({ size, showTooltip, showLabel, ...restProps }: Pro
1414
<CustomTag
1515
size={size}
1616
color="#6372bd"
17-
icon="推理"
17+
icon="深度思考"
1818
tooltip={showTooltip ? t('models.type.reasoning') : undefined}
1919
{...restProps}>
2020
{showLabel ? t('models.type.reasoning') : ''}

ui/ModelModal/src/utils/model.ts

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -562,17 +562,6 @@ export function isWebSearchModel(model_id: string, provider: string): boolean {
562562
return false
563563
}
564564

565-
export const getModelGroup = (model_id: string): string => {
566-
// 1. 提取model_id第一个-之前的部分
567-
const firstPart = model_id.split('-')[0];
568-
569-
// 2. 从头获取连续的纯字母部分
570-
const withoutNumbers = firstPart.match(/^[a-zA-Z]+/)?.[0] || '';
571-
572-
// 3. 返回结果
573-
return withoutNumbers;
574-
}
575-
576565
export function getModelLogo(modelId: string) {
577566
const isLight = true
578567

@@ -706,4 +695,52 @@ export function getModelLogo(modelId: string) {
706695
}
707696

708697
return undefined
698+
}
699+
700+
/**
701+
* 从模型 ID 中提取默认组名。
702+
* 规则如下:
703+
* 1. 第一类分隔规则:以第一个出现的分隔符分割,取第 0 个部分作为组名。
704+
* 2. 第二类分隔规则:取前两个部分拼接(如 'a-b-c' 得到 'a-b')。
705+
* 3. 其他情况返回 id。
706+
*
707+
* 例如:
708+
* - 'gpt-3.5-turbo-16k-0613' => 'gpt-3.5'
709+
* - 'qwen3:32b' => 'qwen3'
710+
* - 'Qwen/Qwen3-32b' => 'qwen'
711+
* - 'deepseek-r1' => 'deepseek-r1'
712+
* - 'o3' => 'o3'
713+
*
714+
* @param {string} id 模型 ID 字符串
715+
* @param {string} [provider] 提供商 ID 字符串
716+
* @returns {string} 提取的组名
717+
*/
718+
export const getModelGroup = (id: string, provider?: string): string => {
719+
const str = id.toLowerCase()
720+
721+
// 定义分隔符
722+
let firstDelimiters = ['/', ' ', ':']
723+
let secondDelimiters = ['-', '_']
724+
725+
if (provider && ['aihubmix', 'silicon', 'ocoolai', 'o3', 'dmxapi'].includes(provider.toLowerCase())) {
726+
firstDelimiters = ['/', ' ', '-', '_', ':']
727+
secondDelimiters = []
728+
}
729+
730+
// 第一类分隔规则
731+
for (const delimiter of firstDelimiters) {
732+
if (str.includes(delimiter)) {
733+
return str.split(delimiter)[0]
734+
}
735+
}
736+
737+
// 第二类分隔规则
738+
for (const delimiter of secondDelimiters) {
739+
if (str.includes(delimiter)) {
740+
const parts = str.split(delimiter)
741+
return parts.length > 1 ? parts[0] + '-' + parts[1] : parts[0]
742+
}
743+
}
744+
745+
return str
709746
}

0 commit comments

Comments
 (0)