feat(thinkingControl): implement thinking mode configuration in model editor
- Added a new thinking mode control field in the ModelEditorDialog, allowing users to specify how the agent's thinking mode is formatted for API requests. - Introduced localization strings for thinking mode labels and descriptions in English, Korean, Russian, and Chinese, enhancing user experience across multiple languages. - Updated the model form data structure to include thinking control settings, ensuring proper handling during model edits and saves. - Implemented utility functions for resolving and defaulting thinking control values based on provider and model, improving backend integration. - Added tests for the new thinking control functionality to ensure reliability and correctness in handling user configurations.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import { defaultThinkingControl } from './thinkingControl.ts'
|
||||
|
||||
// Cases mirror internal/models/chat/provider_test.go TestResolveProvider thinking defaults.
|
||||
test('defaultThinkingControl matches backend provider adapters', () => {
|
||||
const cases: Array<[string, string, ReturnType<typeof defaultThinkingControl>]> = [
|
||||
['generic', 'anything', 'chat_template_kwargs'],
|
||||
['nvidia', 'anything', 'chat_template_kwargs'],
|
||||
['volcengine', 'doubao', 'thinking_type'],
|
||||
['aliyun', 'qwen3-32b', 'enable_thinking'],
|
||||
['aliyun', 'qwen-plus', 'enable_thinking'],
|
||||
['aliyun', 'gpt-4', 'none'],
|
||||
['lkeap', '', 'thinking_type'],
|
||||
['lkeap', 'deepseek-v3.1', 'thinking_type'],
|
||||
['lkeap', 'deepseek-r1', 'none'],
|
||||
['openai', 'gpt-4o', 'none'],
|
||||
['openai', 'gpt-5', 'none'],
|
||||
['azure_openai', 'gpt-4', 'none'],
|
||||
['deepseek', 'deepseek-chat', 'none'],
|
||||
['zhipu', 'glm-4', 'none'],
|
||||
['gemini', 'gemini-2.0', 'none'],
|
||||
['siliconflow', 'qwen3-8b', 'none'],
|
||||
['hunyuan', 'hunyuan-turbo', 'none'],
|
||||
['moonshot', 'moonshot-v1-8k', 'none'],
|
||||
['weknoracloud', 'anything', 'none'],
|
||||
]
|
||||
for (const [provider, model, want] of cases) {
|
||||
assert.equal(
|
||||
defaultThinkingControl(provider, model),
|
||||
want,
|
||||
`${provider}/${model}`,
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,71 @@
|
||||
/** Mirrors backend internal/models/provider.IsQwenThinkingModel */
|
||||
export function isQwenThinkingModel(modelName: string): boolean {
|
||||
const lower = modelName.trim().toLowerCase()
|
||||
return (
|
||||
lower.startsWith('qwen3')
|
||||
|| lower.startsWith('qwen-plus')
|
||||
|| lower.startsWith('qwen-max')
|
||||
|| lower.startsWith('qwen-turbo')
|
||||
)
|
||||
}
|
||||
|
||||
/** Mirrors backend internal/models/provider.IsLKEAPDeepSeekR1Model */
|
||||
export function isLkeapDeepSeekR1Model(modelName: string): boolean {
|
||||
return modelName.toLowerCase().includes('deepseek-r1')
|
||||
}
|
||||
|
||||
export type ThinkingControlValue =
|
||||
| 'none'
|
||||
| 'chat_template_kwargs'
|
||||
| 'enable_thinking'
|
||||
| 'thinking_type'
|
||||
|
||||
const THINKING_CONTROL_VALUES: ThinkingControlValue[] = [
|
||||
'none',
|
||||
'chat_template_kwargs',
|
||||
'enable_thinking',
|
||||
'thinking_type',
|
||||
]
|
||||
|
||||
/**
|
||||
* Default thinking_control for provider+model.
|
||||
* Must stay aligned with chat.resolveProvider(...).Thinking() in provider.go.
|
||||
*/
|
||||
export function defaultThinkingControl(
|
||||
provider: string,
|
||||
modelName = '',
|
||||
): ThinkingControlValue {
|
||||
const p = provider.trim().toLowerCase()
|
||||
const model = modelName.trim()
|
||||
|
||||
switch (p) {
|
||||
case 'aliyun':
|
||||
return isQwenThinkingModel(model) ? 'enable_thinking' : 'none'
|
||||
case 'lkeap':
|
||||
// R1 系列后端不发 thinking 参数;其余(含未填模型名)按 LKEAP 的 thinking.type 格式预选
|
||||
if (model && isLkeapDeepSeekR1Model(model)) return 'none'
|
||||
return 'thinking_type'
|
||||
case 'generic':
|
||||
case 'nvidia':
|
||||
return 'chat_template_kwargs'
|
||||
case 'volcengine':
|
||||
return 'thinking_type'
|
||||
default:
|
||||
// openai, azure_openai, anthropic, zhipu, deepseek, gemini, siliconflow,
|
||||
// hunyuan, moonshot, openrouter, weknoracloud, … → baseProvider / noThinking
|
||||
return 'none'
|
||||
}
|
||||
}
|
||||
|
||||
/** Resolve stored extra_config or fall back to the provider default. */
|
||||
export function resolveThinkingControl(
|
||||
saved: string | undefined,
|
||||
provider: string,
|
||||
modelName = '',
|
||||
): ThinkingControlValue {
|
||||
const v = saved?.trim().toLowerCase()
|
||||
if (THINKING_CONTROL_VALUES.includes(v as ThinkingControlValue)) {
|
||||
return v as ThinkingControlValue
|
||||
}
|
||||
return defaultThinkingControl(provider, modelName)
|
||||
}
|
||||
Reference in New Issue
Block a user