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:
@@ -324,6 +324,31 @@
|
||||
<span class="form-desc form-desc--inline">{{ $t('model.editor.supportsVisionDesc') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Chat + 远程 API:思考模式参数格式 -->
|
||||
<div v-if="showThinkingControlField" class="form-item">
|
||||
<label class="form-label">{{ $t('model.editor.thinkingControlLabel') }}</label>
|
||||
<t-select
|
||||
v-model="formData.thinkingControl"
|
||||
:key="`thinking-${formData.id}-${formData.thinkingControl}`"
|
||||
:popup-props="{ overlayClassName: 'thinking-control-select-popup' }"
|
||||
@change="onThinkingControlManualPick"
|
||||
>
|
||||
<t-option
|
||||
v-for="opt in thinkingControlOptions"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
:label="opt.label"
|
||||
:show-overflow-tooltip="false"
|
||||
>
|
||||
<div class="thinking-control-option">
|
||||
<span class="thinking-control-option__title">{{ opt.label }}</span>
|
||||
<span class="thinking-control-option__hint">{{ opt.hint }}</span>
|
||||
</div>
|
||||
</t-option>
|
||||
</t-select>
|
||||
<p class="form-desc">{{ $t('model.editor.thinkingControlDesc') }}</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</t-form>
|
||||
@@ -342,6 +367,11 @@ import {
|
||||
} from '@/api/model'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
import {
|
||||
defaultThinkingControl,
|
||||
resolveThinkingControl,
|
||||
type ThinkingControlValue,
|
||||
} from '@/utils/thinkingControl'
|
||||
import SettingDrawer from '@/components/settings/SettingDrawer.vue'
|
||||
import CredentialResource, {
|
||||
type CredentialFieldDef,
|
||||
@@ -367,6 +397,8 @@ interface ModelFormData {
|
||||
interfaceType?: 'ollama' | 'openai'
|
||||
isDefault: boolean
|
||||
supportsVision?: boolean
|
||||
/** extra_config.thinking_control — how agent thinking on/off maps to API fields. */
|
||||
thinkingControl?: string
|
||||
// 自定义 HTTP 请求头(类似 OpenAI Python SDK 的 extra_headers)
|
||||
customHeaders?: CustomHeaderItem[]
|
||||
/** LKEAP Rerank:腾讯云 SecretKey(创建时写入 app_secret) */
|
||||
@@ -564,6 +596,51 @@ const dialogVisible = computed({
|
||||
|
||||
const isEdit = computed(() => !!props.modelData)
|
||||
|
||||
const showThinkingControlField = computed(() =>
|
||||
props.modelType === 'chat' && formData.value.source === 'remote',
|
||||
)
|
||||
|
||||
const resolvedThinkingControl = (): ThinkingControlValue =>
|
||||
defaultThinkingControl(
|
||||
formData.value.provider || '',
|
||||
formData.value.modelName || '',
|
||||
)
|
||||
|
||||
/** 用户是否手动改过思考参数格式(改过则不再自动覆盖,直到换服务商) */
|
||||
const thinkingControlManual = ref(false)
|
||||
/** 正在从 modelData 灌入表单,忽略厂商/来源控件的程序化 change 副作用 */
|
||||
const hydratingForm = ref(false)
|
||||
|
||||
const onThinkingControlManualPick = () => {
|
||||
thinkingControlManual.value = true
|
||||
}
|
||||
|
||||
const syncThinkingControlToForm = (force = false) => {
|
||||
if (!showThinkingControlField.value) return
|
||||
if (!force && !isEdit.value && thinkingControlManual.value) return
|
||||
formData.value.thinkingControl = resolvedThinkingControl()
|
||||
}
|
||||
|
||||
const applyThinkingControlFromModelData = () => {
|
||||
if (!props.modelData || props.modelType !== 'chat' || formData.value.source !== 'remote') return
|
||||
thinkingControlManual.value = !!props.modelData.thinkingControl
|
||||
formData.value.thinkingControl = resolveThinkingControl(
|
||||
props.modelData.thinkingControl,
|
||||
formData.value.provider || props.modelData.provider || '',
|
||||
formData.value.modelName || props.modelData.modelName || '',
|
||||
)
|
||||
}
|
||||
|
||||
const thinkingControlOptions = computed(() => {
|
||||
const keys = ['none', 'chatTemplateKwargs', 'enableThinking', 'thinkingType'] as const
|
||||
const values = ['none', 'chat_template_kwargs', 'enable_thinking', 'thinking_type'] as const
|
||||
return keys.map((key, i) => ({
|
||||
value: values[i],
|
||||
label: t(`model.editor.thinkingControl.${key}.label`),
|
||||
hint: t(`model.editor.thinkingControl.${key}.hint`),
|
||||
}))
|
||||
})
|
||||
|
||||
// Header icon for the SettingDrawer — uses the same TDesign icon name table
|
||||
// as the model card list, so the drawer's leading badge visually matches the
|
||||
// card the user just clicked on.
|
||||
@@ -697,6 +774,7 @@ const formData = ref<ModelFormData>({
|
||||
interfaceType: 'ollama',
|
||||
isDefault: false,
|
||||
supportsVision: false,
|
||||
thinkingControl: defaultThinkingControl('generic', ''),
|
||||
customHeaders: [],
|
||||
appSecret: '',
|
||||
lkeapRegion: 'ap-guangzhou',
|
||||
@@ -838,39 +916,53 @@ watch(() => props.visible, (val) => {
|
||||
|
||||
const currentId = props.modelData?.id ?? null
|
||||
|
||||
if (props.modelData) {
|
||||
// 编辑:始终用最新的 modelData 覆盖。apiKey field is left blank — in
|
||||
// edit mode the credential is owned by the <CredentialResource> card,
|
||||
// not by this form's apiKey field.
|
||||
formData.value = {
|
||||
...props.modelData,
|
||||
apiKey: '',
|
||||
customHeaders: Array.isArray(props.modelData.customHeaders)
|
||||
? props.modelData.customHeaders.map(h => ({ key: h.key, value: h.value }))
|
||||
: []
|
||||
hydratingForm.value = true
|
||||
try {
|
||||
if (props.modelData) {
|
||||
// 编辑:始终用最新的 modelData 覆盖。apiKey field is left blank — in
|
||||
// edit mode the credential is owned by the <CredentialResource> card,
|
||||
// not by this form's apiKey field.
|
||||
formData.value = {
|
||||
...props.modelData,
|
||||
apiKey: '',
|
||||
customHeaders: Array.isArray(props.modelData.customHeaders)
|
||||
? props.modelData.customHeaders.map(h => ({ key: h.key, value: h.value }))
|
||||
: [],
|
||||
}
|
||||
applyThinkingControlFromModelData()
|
||||
} else if (lastOpenedModelId.value !== null || !formData.value.id) {
|
||||
// 上次是编辑某个模型,或第一次新增 → 重置成空白
|
||||
resetForm()
|
||||
}
|
||||
} else if (lastOpenedModelId.value !== null || !formData.value.id) {
|
||||
// 上次是编辑某个模型,或第一次新增 → 重置成空白
|
||||
resetForm()
|
||||
}
|
||||
// 否则:连续两次"新增"打开(中间是点遮罩/ESC 关闭的)→ 保留上次填写
|
||||
// 否则:连续两次"新增"打开(中间是点遮罩/ESC 关闭的)→ 保留上次填写
|
||||
|
||||
lastOpenedModelId.value = currentId
|
||||
lastOpenedModelId.value = currentId
|
||||
|
||||
// ReRank 模型强制使用 remote 来源(Ollama 不支持 ReRank)
|
||||
if (props.modelType === 'rerank') {
|
||||
formData.value.source = 'remote'
|
||||
}
|
||||
// ReRank 模型强制使用 remote 来源(Ollama 不支持 ReRank)
|
||||
if (props.modelType === 'rerank') {
|
||||
formData.value.source = 'remote'
|
||||
}
|
||||
|
||||
// 如果当前 provider 是 WeKnoraCloud,检查凭证状态
|
||||
if (formData.value.provider === 'weknoracloud') {
|
||||
checkWkcCredentialStatus()
|
||||
// 如果当前 provider 是 WeKnoraCloud,检查凭证状态
|
||||
if (formData.value.provider === 'weknoracloud') {
|
||||
checkWkcCredentialStatus()
|
||||
}
|
||||
|
||||
if (showThinkingControlField.value && !isEdit.value) {
|
||||
thinkingControlManual.value = false
|
||||
syncThinkingControlToForm(true)
|
||||
}
|
||||
} finally {
|
||||
nextTick(() => {
|
||||
hydratingForm.value = false
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 重置表单
|
||||
const resetForm = () => {
|
||||
thinkingControlManual.value = false
|
||||
formData.value = {
|
||||
id: generateId(),
|
||||
name: '', // 保留字段但不使用,保存时用 modelName
|
||||
@@ -884,6 +976,7 @@ const resetForm = () => {
|
||||
interfaceType: undefined,
|
||||
isDefault: false,
|
||||
supportsVision: false,
|
||||
thinkingControl: defaultThinkingControl('generic', ''),
|
||||
customHeaders: [],
|
||||
appSecret: '',
|
||||
lkeapRegion: 'ap-guangzhou',
|
||||
@@ -920,8 +1013,43 @@ const handleProviderChange = (value: string) => {
|
||||
if (value === 'weknoracloud') {
|
||||
checkWkcCredentialStatus()
|
||||
}
|
||||
if (hydratingForm.value) return
|
||||
if (props.modelType !== 'chat' || formData.value.source !== 'remote') return
|
||||
if (!isEdit.value) {
|
||||
thinkingControlManual.value = false
|
||||
syncThinkingControlToForm(true)
|
||||
return
|
||||
}
|
||||
// 编辑时仅用户主动换厂商才跟随默认
|
||||
thinkingControlManual.value = false
|
||||
syncThinkingControlToForm(true)
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [formData.value.source, formData.value.provider, formData.value.modelName] as const,
|
||||
([source, provider, modelName], [prevSource, prevProvider, prevModelName]) => {
|
||||
if (hydratingForm.value || isEdit.value) return
|
||||
if (props.modelType !== 'chat' || source !== 'remote') return
|
||||
if (source === prevSource && provider === prevProvider && modelName === prevModelName) return
|
||||
|
||||
const providerChanged = provider !== prevProvider
|
||||
|
||||
if (providerChanged) {
|
||||
thinkingControlManual.value = false
|
||||
syncThinkingControlToForm(true)
|
||||
return
|
||||
}
|
||||
if (!thinkingControlManual.value) {
|
||||
syncThinkingControlToForm(true)
|
||||
return
|
||||
}
|
||||
const prevDefault = defaultThinkingControl(prevProvider || '', prevModelName || '')
|
||||
if (formData.value.thinkingControl === prevDefault) {
|
||||
syncThinkingControlToForm(true)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
// 监听来源变化,重置校验状态(已合并到下面的 watch)
|
||||
|
||||
// 生成唯一ID
|
||||
@@ -1388,6 +1516,16 @@ watch(() => formData.value.source, () => {
|
||||
downloading.value = false
|
||||
downloadProgress.value = 0
|
||||
currentDownloadModel.value = ''
|
||||
|
||||
if (
|
||||
!hydratingForm.value
|
||||
&& !isEdit.value
|
||||
&& formData.value.source === 'remote'
|
||||
&& props.modelType === 'chat'
|
||||
) {
|
||||
thinkingControlManual.value = false
|
||||
syncThinkingControlToForm(true)
|
||||
}
|
||||
})
|
||||
|
||||
// 监听模型名称变化,清理维度检测状态
|
||||
@@ -1871,6 +2009,14 @@ const handleCancel = () => {
|
||||
&--inline {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
&--recommend {
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
|
||||
&--warn {
|
||||
color: var(--td-warning-color);
|
||||
}
|
||||
}
|
||||
|
||||
.vision-toggle {
|
||||
@@ -1969,6 +2115,39 @@ const handleCancel = () => {
|
||||
|
||||
<!-- 非 scoped 样式:t-select popup 渲染到 body 下,scoped 样式无法覆盖 -->
|
||||
<style lang="less">
|
||||
.thinking-control-select-popup {
|
||||
min-width: 22rem;
|
||||
max-width: min(28rem, calc(100vw - 2rem));
|
||||
padding: 4px;
|
||||
|
||||
.t-select-option {
|
||||
height: auto !important;
|
||||
padding: 8px 10px;
|
||||
border-radius: 6px;
|
||||
margin: 2px 0;
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
|
||||
.thinking-control-option {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
line-height: 1.35;
|
||||
min-width: 0;
|
||||
|
||||
&__title {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
&__hint {
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
word-break: break-word;
|
||||
}
|
||||
}
|
||||
|
||||
.provider-select-popup {
|
||||
// 容器留点呼吸:避免选项贴着 popup 圆角
|
||||
padding: 4px;
|
||||
|
||||
@@ -3325,6 +3325,27 @@ export default {
|
||||
remoteDimensionDetected: 'Detected vector dimension: {value}',
|
||||
supportsVisionLabel: 'Supports Vision / Multimodal',
|
||||
supportsVisionDesc: 'Whether the model accepts image and multimodal input',
|
||||
thinkingControlLabel: 'Thinking mode request format',
|
||||
thinkingControlDesc:
|
||||
'Controls how the agent’s “Thinking mode” on/off switch is written to the API. We pre-select based on vendor/model when possible; change it to match your API docs. With “Do not send”, the agent Thinking mode switch has no effect.',
|
||||
thinkingControl: {
|
||||
none: {
|
||||
label: 'Do not send thinking fields',
|
||||
hint: 'Agent “Thinking mode” switch has no effect; thinking parameters are not sent in requests',
|
||||
},
|
||||
chatTemplateKwargs: {
|
||||
label: 'chat_template_kwargs',
|
||||
hint: 'Custom OpenAI-compatible gateways, NVIDIA NIM, vLLM / local Qwen',
|
||||
},
|
||||
enableThinking: {
|
||||
label: 'enable_thinking',
|
||||
hint: 'Alibaba DashScope: qwen3, qwen-plus, qwen-max, qwen-turbo',
|
||||
},
|
||||
thinkingType: {
|
||||
label: 'thinking.type',
|
||||
hint: 'Volcengine Ark; Tencent LKEAP (DeepSeek V3, etc.; default for LKEAP; use “Do not send” for R1)',
|
||||
},
|
||||
},
|
||||
dimensionHint: 'Model selected. Click "Detect Dimension" to fetch the vector dimension automatically.',
|
||||
loadModelListFailed: 'Failed to load model list',
|
||||
listRefreshed: 'List refreshed',
|
||||
|
||||
@@ -2542,6 +2542,27 @@ export default {
|
||||
remoteDimensionDetected: "감지된 벡터 차원: {value}",
|
||||
supportsVisionLabel: "비전/멀티모달 지원",
|
||||
supportsVisionDesc: "모델의 이미지 등 멀티모달 입력 지원 여부",
|
||||
thinkingControlLabel: "사고 모드 매개변수 형식",
|
||||
thinkingControlDesc:
|
||||
"에이전트 「사고 모드」 켜기/끄기 시 API에 어떻게 기록할지 결정합니다. 벤더/모델에 따라 미리 선택되며, 실제 API와 다르면 문서에 맞게 수정하세요. 「전송 안 함」을 선택하면 에이전트 「사고 모드」 스위치가 효과가 없습니다.",
|
||||
thinkingControl: {
|
||||
none: {
|
||||
label: "사고 매개변수 전송 안 함",
|
||||
hint: "에이전트 「사고 모드」 스위치가 효과 없음, 요청에 사고 관련 매개변수를 보내지 않음",
|
||||
},
|
||||
chatTemplateKwargs: {
|
||||
label: "chat_template_kwargs",
|
||||
hint: "사용자 정의 OpenAI 호환, NVIDIA NIM, vLLM / 로컬 Qwen 배포",
|
||||
},
|
||||
enableThinking: {
|
||||
label: "enable_thinking",
|
||||
hint: "Alibaba DashScope: qwen3, qwen-plus, qwen-max, qwen-turbo",
|
||||
},
|
||||
thinkingType: {
|
||||
label: "thinking.type",
|
||||
hint: 'Volcengine Ark; Tencent LKEAP (DeepSeek V3 등, LKEAP 기본값; R1은 「전송 안 함」)',
|
||||
},
|
||||
},
|
||||
dimensionHint:
|
||||
'모델이 선택되었습니다. "차원 감지" 버튼을 클릭하여 벡터 차원을 자동으로 가져옵니다',
|
||||
loadModelListFailed: "모델 목록 로드 실패",
|
||||
|
||||
@@ -2259,6 +2259,27 @@ export default {
|
||||
remoteDimensionDetected: 'Обнаружена размерность: {value}',
|
||||
supportsVisionLabel: 'Поддержка визуального / мультимодального ввода',
|
||||
supportsVisionDesc: 'Поддерживает ли модель изображения и другой мультимодальный ввод',
|
||||
thinkingControlLabel: 'Формат параметров режима размышления',
|
||||
thinkingControlDesc:
|
||||
'Определяет, как переключатель «Режим размышления» агента записывается в API. При возможности выбирается по поставщику/модели; при несоответствии измените по документации API. При выборе «Не отправлять» переключатель «Режим размышления» агента не действует.',
|
||||
thinkingControl: {
|
||||
none: {
|
||||
label: 'Не отправлять параметры размышления',
|
||||
hint: 'Переключатель «Режим размышления» агента не действует; параметры размышления не отправляются в запросе',
|
||||
},
|
||||
chatTemplateKwargs: {
|
||||
label: 'chat_template_kwargs',
|
||||
hint: 'Пользовательские OpenAI-совместимые шлюзы, NVIDIA NIM, vLLM / локальный Qwen',
|
||||
},
|
||||
enableThinking: {
|
||||
label: 'enable_thinking',
|
||||
hint: 'Alibaba DashScope: qwen3, qwen-plus, qwen-max, qwen-turbo',
|
||||
},
|
||||
thinkingType: {
|
||||
label: 'thinking.type',
|
||||
hint: 'Volcengine Ark; Tencent LKEAP (DeepSeek V3 и др.; по умолчанию для LKEAP; для R1 — «Не отправлять»)',
|
||||
},
|
||||
},
|
||||
dimensionHint: 'Модель выбрана. Нажмите «Определить размерность», чтобы автоматически получить значение.',
|
||||
loadModelListFailed: 'Не удалось загрузить список моделей',
|
||||
listRefreshed: 'Список обновлён',
|
||||
|
||||
@@ -2542,6 +2542,27 @@ export default {
|
||||
remoteDimensionDetected: "检测到向量维度:{value}",
|
||||
supportsVisionLabel: "支持视觉/多模态",
|
||||
supportsVisionDesc: "模型是否支持图片等多模态输入",
|
||||
thinkingControlLabel: "思考模式参数格式",
|
||||
thinkingControlDesc:
|
||||
"决定智能体「思考模式」开/关时如何写入 API。已尝试按厂商/模型预选,若与实际情况不符请按 API 文档手动修改;选「不写入」时,智能体「思考模式」开关不生效。",
|
||||
thinkingControl: {
|
||||
none: {
|
||||
label: "不写入思考参数",
|
||||
hint: "智能体「思考模式」开关不生效,不会在请求中写入思考相关参数",
|
||||
},
|
||||
chatTemplateKwargs: {
|
||||
label: "chat_template_kwargs",
|
||||
hint: "自定义 OpenAI 兼容、NVIDIA NIM、vLLM / 本地 Qwen 部署",
|
||||
},
|
||||
enableThinking: {
|
||||
label: "enable_thinking",
|
||||
hint: "阿里云 DashScope:qwen3、qwen-plus、qwen-max、qwen-turbo",
|
||||
},
|
||||
thinkingType: {
|
||||
label: "thinking.type",
|
||||
hint: "火山引擎 Ark;腾讯云 LKEAP(DeepSeek V3 等,选 LKEAP 时默认此项;R1 请改「不写入」)",
|
||||
},
|
||||
},
|
||||
dimensionHint: '模型已选择,点击"检测维度"按钮自动获取向量维度',
|
||||
loadModelListFailed: "加载模型列表失败",
|
||||
listRefreshed: "列表已刷新",
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -723,6 +723,17 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 思考模式(写入 config.thinking,映射到 LLM 请求参数) -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('agent.editor.thinking') }}</label>
|
||||
<p class="desc">{{ $t('agentEditor.desc.thinking') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch v-model="thinkingEnabled" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 最大迭代次数 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
|
||||
@@ -162,6 +162,8 @@ function convertToLegacyFormat(model: ModelConfig) {
|
||||
? Object.entries(model.parameters.custom_headers).map(([key, value]) => ({ key, value: String(value) }))
|
||||
: [],
|
||||
lkeapRegion: model.parameters.extra_config?.region || 'ap-guangzhou',
|
||||
// 原始存库值,编辑弹窗内再 resolve(避免打开时被推断值覆盖)
|
||||
thinkingControl: model.parameters.extra_config?.thinking_control,
|
||||
_modelType: backendTypeToModelType[model.type] || 'chat' as ModelType,
|
||||
// Preserve the credential metadata map so the editor dialog can render
|
||||
// the "Configured" state without an extra round-trip.
|
||||
@@ -375,14 +377,20 @@ const handleModelSave = async (modelData: any) => {
|
||||
const trimmedAppSecret = (modelData.appSecret ?? '').trim()
|
||||
const appSecretFields: { app_secret?: string } =
|
||||
!editingModel.value && trimmedAppSecret ? { app_secret: trimmedAppSecret } : {}
|
||||
const lkeapExtra =
|
||||
modelData.provider === 'lkeap' && currentModelType.value === 'rerank'
|
||||
? {
|
||||
extra_config: {
|
||||
region: (modelData.lkeapRegion || 'ap-guangzhou').trim(),
|
||||
},
|
||||
}
|
||||
: {}
|
||||
const extraConfig: Record<string, string> = {}
|
||||
if (modelData.provider === 'lkeap' && currentModelType.value === 'rerank') {
|
||||
extraConfig.region = (modelData.lkeapRegion || 'ap-guangzhou').trim()
|
||||
}
|
||||
if (
|
||||
currentModelType.value === 'chat'
|
||||
&& modelData.source === 'remote'
|
||||
&& modelData.thinkingControl
|
||||
) {
|
||||
extraConfig.thinking_control = modelData.thinkingControl
|
||||
}
|
||||
const extraConfigFields = Object.keys(extraConfig).length > 0
|
||||
? { extra_config: extraConfig }
|
||||
: {}
|
||||
|
||||
const apiModelData: ModelConfig = {
|
||||
name: modelData.modelName.trim(),
|
||||
@@ -395,7 +403,7 @@ const handleModelSave = async (modelData: any) => {
|
||||
...apiKeyFields,
|
||||
...appSecretFields,
|
||||
provider: modelData.provider || '',
|
||||
...lkeapExtra,
|
||||
...extraConfigFields,
|
||||
...(Object.keys(customHeadersMap).length > 0 ? { custom_headers: customHeadersMap } : {}),
|
||||
...(currentModelType.value === 'embedding' && modelData.dimension ? {
|
||||
embedding_parameters: {
|
||||
|
||||
@@ -1685,3 +1685,4 @@ onMounted(loadAll)
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user