- 在环境配置中新增 SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED 选项,默认关闭,需显式开启以支持自动上传。 - 引入新的 pytest.ini 文件,增加测试标记以支持自动化测试。 - 删除不再使用的 seed_shipping_notice_agents.py 文件,简化代码库。 - 更新相关 API,增强发货通知与候选资格评估功能,支持多种筛选条件。 - 增强文档与代码注释,反映新的业务逻辑与功能要求。
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
/**
|
|
* 去除模型推理与调试包装,供 Markdown 展示与出货模块使用。
|
|
* 仅处理明确的推理标签、纯调试 JSON 和开头技术诊断行,不改写正常业务回答。
|
|
*/
|
|
export const stripReasoningPrelude = (text: string) => {
|
|
if (!text) return '';
|
|
let cleaned = text
|
|
.replace(/<think[\s\S]*?<\/think>/gi, '')
|
|
.replace(/<analysis[\s\S]*?<\/analysis>/gi, '')
|
|
.trim();
|
|
|
|
if (/^(?:\{|\[)/.test(cleaned)) {
|
|
try {
|
|
const parsed = JSON.parse(cleaned) as unknown;
|
|
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
const keys = Object.keys(parsed as Record<string, unknown>);
|
|
const technicalKeys = new Set([
|
|
'workflow_run_id', 'node_id', 'node_execution_id', 'status', 'error',
|
|
'outputs', 'inputs', 'metadata', 'traceback', 'tool_output', 'tool_response',
|
|
]);
|
|
if (keys.length > 0 && keys.every((key) => technicalKeys.has(key))) return '';
|
|
}
|
|
} catch {
|
|
// 非完整 JSON 继续按普通回答展示。
|
|
}
|
|
}
|
|
|
|
const lines = cleaned.split('\n');
|
|
while (
|
|
lines.length > 1
|
|
&& /^\s*(?:workflow(?:_run)?_id|node(?:_execution)?_id|tool(?:_output|_response)?|traceback|status|error)(?:[_\s-]*(?:code|message))?\s*[:=]/i.test(lines[0] || '')
|
|
) {
|
|
lines.shift();
|
|
}
|
|
cleaned = lines.join('\n').trim();
|
|
|
|
const reasoningMarkers = [
|
|
'让我分析',
|
|
'根据应答生成规则',
|
|
'分析知识库返回的内容',
|
|
'我需要直接给出答案',
|
|
'思考过程',
|
|
'推理过程',
|
|
];
|
|
const hasReasoningMarker = reasoningMarkers.some((marker) => cleaned.includes(marker));
|
|
if (!hasReasoningMarker) return cleaned;
|
|
|
|
const headingMatch = cleaned.match(/(^|\n)\s{0,3}#{1,6}\s+/);
|
|
if (headingMatch && typeof headingMatch.index === 'number') {
|
|
const start = headingMatch.index + (headingMatch[1] ? headingMatch[1].length : 0);
|
|
cleaned = cleaned.slice(start).trim();
|
|
}
|
|
return cleaned;
|
|
};
|