Skip to content

Commit d370c2f

Browse files
committed
feat(playground): split dynamic model to thinking and not thinking model when enable_thinking is true
1 parent 58db026 commit d370c2f

1 file changed

Lines changed: 27 additions & 9 deletions

File tree

sites/playground/server/src/opentiny-models.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ interface OpenTinyModel {
55
display_name: string;
66
capabilities?: {
77
vision?: boolean;
8+
reasoning?: {
9+
enable_thinking?: boolean;
10+
[key: string]: any;
11+
};
812
fileUpload?: {
913
supportDirectImage?: boolean;
1014
[key: string]: any;
@@ -13,6 +17,17 @@ interface OpenTinyModel {
1317
};
1418
}
1519

20+
const EXTRA_BODY_THINKING_DISABLED = { thinking: { type: 'disabled' as const } };
21+
const EXTRA_BODY_THINKING_ENABLED = { thinking: { type: 'enabled' as const } };
22+
23+
function shouldSplitThinkingModel(capabilities?: OpenTinyModel['capabilities']): boolean {
24+
const reasoning = capabilities?.reasoning;
25+
if (reasoning == null || typeof reasoning !== 'object' || Array.isArray(reasoning)) {
26+
return false;
27+
}
28+
return reasoning.enable_thinking === true;
29+
}
30+
1631
interface OpenTinyModelsResponse {
1732
models: OpenTinyModel[];
1833
[key: string]: any;
@@ -25,22 +40,25 @@ interface OpenTinyModelsResponse {
2540
export function convertOpenTinyToProviderModelsData(resp: OpenTinyModelsResponse): Record<string, any> {
2641
const models = Array.isArray(resp?.models) ? resp.models : [];
2742

28-
const convertedModels = models.map((model) => {
43+
const convertedModels = models.flatMap((model) => {
2944
const { display_name, id, type, capabilities, provider } = model;
3045
const supportImage =
3146
type === 'vision' || capabilities?.vision === true || capabilities?.fileUpload?.supportDirectImage === true;
3247

3348
const modelName = display_name && provider ? `${provider}_${display_name}` : id;
34-
const modelData: any = {
35-
name: modelName,
36-
id,
37-
};
38-
49+
const base: any = { id };
3950
if (supportImage) {
40-
modelData.features = { supportImage: true };
51+
base.features = { supportImage: true };
52+
}
53+
54+
if (!shouldSplitThinkingModel(capabilities)) {
55+
return [{ name: modelName, ...base }];
4156
}
4257

43-
return modelData;
58+
return [
59+
{ name: modelName, ...base, extraBody: EXTRA_BODY_THINKING_DISABLED },
60+
{ name: `${modelName}-thinking`, ...base, extraBody: EXTRA_BODY_THINKING_ENABLED },
61+
];
4462
});
4563

4664
// 为了与现有 opentiny-models.json 保持一致,统一放在 deepseek 提供商下
@@ -49,7 +67,7 @@ export function convertOpenTinyToProviderModelsData(resp: OpenTinyModelsResponse
4967
name: 'deepseek',
5068
apiKeyEnvName: 'DYNAMIC_API_KEY',
5169
baseUrlEnvName: 'DYNAMIC_BASE_URL',
52-
models: convertedModels,
70+
models: convertedModels,
5371
},
5472
};
5573
}

0 commit comments

Comments
 (0)