feat: 优化AI助手响应构建

- 增加剔除推理块功能
This commit is contained in:
kuaifan 2025-11-10 16:13:05 +00:00
parent 0790eae8c6
commit 64d4492806

View File

@ -69,7 +69,7 @@
<OptionGroup <OptionGroup
v-for="group in modelGroups" v-for="group in modelGroups"
:key="group.type" :key="group.type"
:label="$L(group.label)"> :label="group.label">
<Option <Option
v-for="option in group.options" v-for="option in group.options"
:key="option.id" :key="option.id"
@ -690,7 +690,7 @@ export default {
return; return;
} }
response.applyLoading = true; response.applyLoading = true;
const payload = this.buildResponsePayload(response); const payload = this.buildResponsePayload(response, true);
try { try {
const result = this.applyHook(payload); const result = this.applyHook(payload);
if (result && typeof result.then === 'function') { if (result && typeof result.then === 'function') {
@ -714,7 +714,7 @@ export default {
/** /**
* 构造发送给外部回调的统一数据结构 * 构造发送给外部回调的统一数据结构
*/ */
buildResponsePayload(response) { buildResponsePayload(response, removeReasoning = false) {
if (!response) { if (!response) {
return { return {
model: '', model: '',
@ -727,10 +727,20 @@ export default {
model: response.model, model: response.model,
type: response.type, type: response.type,
prompt: response.prompt, prompt: response.prompt,
rawOutput: response.rawOutput, rawOutput: removeReasoning ? this.removeReasoningSections(response.rawOutput) : response.rawOutput,
}; };
}, },
/**
* 从回调中剔除 reasoning block
*/
removeReasoningSections(text) {
if (typeof text !== 'string') {
return text;
}
return text.replace(/:::\s*reasoning[\s\S]*?:::/gi, '').trim();
},
/** /**
* 根据 onRender 回调生成展示文本 * 根据 onRender 回调生成展示文本
*/ */
@ -808,6 +818,7 @@ export default {
<style lang="scss"> <style lang="scss">
.ai-assistant-modal { .ai-assistant-modal {
--apply-reasoning-before-bg: #e1e1e1;
.ivu-modal { .ivu-modal {
transition: max-width 0.3s ease; transition: max-width 0.3s ease;
.ivu-modal-header { .ivu-modal-header {
@ -926,6 +937,35 @@ export default {
.ai-assistant-output-markdown { .ai-assistant-output-markdown {
margin-top: 12px; margin-top: 12px;
font-size: 13px; font-size: 13px;
.apply-reasoning {
margin: 0 0 12px 0;
padding: 0 0 0 13px;
line-height: 26px;
position: relative;
&:before {
content: "";
position: absolute;
top: 0;
left: 0;
bottom: 0;
width: 2px;
background-color: var(--apply-reasoning-before-bg);
}
.reasoning-label {
margin-bottom: 4px;
opacity: 0.9;
}
.reasoning-content {
opacity: 0.5;
> p:last-child {
margin-bottom: 0;
}
}
}
} }
} }
@ -958,4 +998,9 @@ export default {
} }
} }
} }
body.dark-mode-reverse {
.ai-assistant-modal {
--apply-reasoning-before-bg: #4e4e56;
}
}
</style> </style>