diff --git a/scripts/nao_evidence_finalizer.py b/scripts/nao_evidence_finalizer.py index 2e80778..3d5b277 100644 --- a/scripts/nao_evidence_finalizer.py +++ b/scripts/nao_evidence_finalizer.py @@ -251,7 +251,8 @@ def synthesize(*, base_url: str, api_key: str, model: str, question: str, 'VCM亮片只录合计是既有业务口径,不视为零缺陷、漏导入或系统故障;其他小额差额不作为关注重点。' '用户问普通统计变化时,已有指标、分组、规格和缺陷事实通常足以回答,不要求现场生产原因或全部原始行。' '只返回JSON:groupFactIds、productFactIds、defectFactIds、otherFactIds分别为对应候选中的id数组。每类候选非空时至少选1项、最多2项,空候选返回空数组;总共最多6项,禁止编造。evidenceSufficient为布尔值,' - 'missingEvidence为仅与用户明确问题相关的缺失证据字符串数组。证据确实不足时填写缺项并设false。') + 'missingEvidence为仅与用户明确问题相关的缺失证据字符串数组。证据确实不足时填写具体缺项并设false;' + '没有具体缺项时必须返回空数组并设true,不能仅因返回Top排名、未查询全部原始行或未查现场原因而设false。') body={'model':model,'stream':False,'max_completion_tokens':4096, 'thinking':{'type':'disabled'},'response_format':{'type':'json_object'}, 'messages':[{'role':'system','content':system},{'role':'user','content':selector_text}]} @@ -283,8 +284,12 @@ def synthesize(*, base_url: str, api_key: str, model: str, question: str, sufficient=parsed.get('evidenceSufficient');missing=parsed.get('missingEvidence') if (not isinstance(sufficient,bool) or not isinstance(missing,list) or any(not isinstance(x,str) for x in missing)):raise ValueError('invalid evidence completion') + missing=list(dict.fromkeys(item.strip() for item in missing if item.strip()))[:10] + # 模型的孤立 false 不能证明数据缺失;具体缺项仍阻止完成,调用方另行检查服务端覆盖。 + completion_adjusted = not sufficient and not missing text=render_report(report,selected,missing[:10]) - return {'answer':text,'evidenceSufficient':sufficient and not missing,'missingEvidence':missing[:10], + return {'answer':text,'evidenceSufficient':not missing,'missingEvidence':missing, + 'modelDeclaredEvidenceSufficient':sufficient,'completionAdjusted':completion_adjusted, 'model':document.get('model',model),'usage':document.get('usage') if isinstance(document.get('usage'),dict) else {}, 'finishReason':'stop','selectedFactIds':selected,'factCount':len(report['facts']), 'selectionAdjusted':selection_adjusted} diff --git a/scripts/nao_quality_runtime.py b/scripts/nao_quality_runtime.py index 2eab3f1..fcd317e 100644 --- a/scripts/nao_quality_runtime.py +++ b/scripts/nao_quality_runtime.py @@ -1977,6 +1977,7 @@ def run_turn(payload: dict[str, Any], *, stdout: Any = sys.stdout, stdin: Any = ) from nao_evidence_finalizer import eligible, evidence_summaries, synthesize, coverage_sufficient, FinalizationUnavailable finalized = False + evidence_completion = None if eligible(model_name, status, stop_reason, accumulator.tool_calls, cancel_event.is_set(), stop_succeeded): final_call = None try: @@ -2006,8 +2007,13 @@ def run_turn(payload: dict[str, Any], *, stdout: Any = sys.stdout, stdin: Any = if not (entry.get("kind") == "assistant" and native_answer and entry.get("text") == public_progress_text(native_answer))] accumulator.record_event("assistant",text=public_progress_text(final["answer"])) - status = "COMPLETED" if final["evidenceSufficient"] and coverage_sufficient(evidence,request["question"]) else "PARTIAL" - _atomic_json(actor_root / "finalization.json", {"turnId":request["turnId"],"status":status,"nativeStopReason":stop_reason,"model":final["model"],"requestParameters":{"max_completion_tokens":4096,"thinking":{"type":"disabled"},"stream":False},"evidenceRefs":[d["evidenceRef"] for d in evidence],"usage":final["usage"],"finishReason":final["finishReason"],"modelDeclaredEvidenceSufficient":final["evidenceSufficient"],"serverCoverageSufficient":coverage_sufficient(evidence,request["question"]),"missingEvidence":final["missingEvidence"]}) + server_coverage = coverage_sufficient(evidence,request["question"]) + status = "COMPLETED" if final["evidenceSufficient"] and server_coverage else "PARTIAL" + completion = {"modelDeclaredEvidenceSufficient":final.get("modelDeclaredEvidenceSufficient", final["evidenceSufficient"]), + "serverCoverageSufficient":server_coverage,"missingEvidence":final["missingEvidence"], + "completionAdjusted":final.get("completionAdjusted",False)} + _atomic_json(actor_root / "finalization.json", {"turnId":request["turnId"],"status":status,"nativeStopReason":stop_reason,"model":final["model"],"requestParameters":{"max_completion_tokens":4096,"thinking":{"type":"disabled"},"stream":False},"evidenceRefs":[d["evidenceRef"] for d in evidence],"usage":final["usage"],"finishReason":final["finishReason"],**completion}) + evidence_completion = completion stop_reason, finalized = "evidence_finalized" if status=="COMPLETED" else "evidence_incomplete", True accumulator.finish_reasons.append("stop") except (FinalizationUnavailable, OSError, ValueError) as error: @@ -2039,6 +2045,8 @@ def run_turn(payload: dict[str, Any], *, stdout: Any = sys.stdout, stdin: Any = "nativeStopSucceeded": stop_succeeded, "finishReason": accumulator.finish_reasons[-1] if accumulator.finish_reasons else None, } + if finalized: + result["evidenceCompletion"] = evidence_completion if report_markdown is not None: result["reportMarkdown"] = report_markdown if report_html is not None: diff --git a/web/src/QueryPage.tsx b/web/src/QueryPage.tsx index 516e6eb..23ecf4b 100644 --- a/web/src/QueryPage.tsx +++ b/web/src/QueryPage.tsx @@ -453,7 +453,7 @@ export default function QueryPage({ page, onUnauthorized }: { setTrendObjectMetricsLoading(true); setTrendObjectMetricsError(''); api.metrics({ ...defectQueryParams, trendGranularity: 'month' }, controller.signal) - .then(result => setTrendObjectMetrics({ key: defectQueryKey, data: result })) + .then(result => { if (!controller.signal.aborted) setTrendObjectMetrics({ key: defectQueryKey, data: result }); }) .catch(errorValue => { if (controller.signal.aborted) return; if (!onUnauthorized(errorValue)) setTrendObjectMetricsError(chooseError(errorValue)); @@ -620,8 +620,12 @@ export default function QueryPage({ page, onUnauthorized }: { const activeDefectData = trendObject ? defectQueryKey === queryKey ? currentMetricsData : trendObjectMetrics?.key === defectQueryKey ? trendObjectMetrics.data : null : currentMetricsData; - const rowForSummary = currentMetricsData?.summary; - const rawFormulaDescriptions = currentMetricsData?.context.metricFormulaDescriptions; + // 产品月度下钻复用当前对象的服务端指标,汇总表仍保留父层结果供返回。 + const summaryMetricsData = drilledProduct ? activeDefectData : currentMetricsData; + const summaryMetricsError = drilledProduct ? trendObjectMetricsError : currentMetricsError; + const summaryBusy = drilledProduct ? trendObjectMetricsLoading || !summaryMetricsData && !summaryMetricsError : queryBusy; + const rowForSummary = summaryMetricsData?.summary; + const rawFormulaDescriptions = summaryMetricsData?.context.metricFormulaDescriptions; const formulaDescriptions = rawFormulaDescriptions && typeof rawFormulaDescriptions === 'object' && !Array.isArray(rawFormulaDescriptions) ? rawFormulaDescriptions as Record : {}; const compositeFormula = formulaDescriptions[rateBasis === 'original' ? 'compositeRate' : 'compositeRateWithoutHeadquartersScrap']; const brightFormula = formulaDescriptions[rateBasis === 'original' ? 'brightRate' : 'brightRateWithoutHeadquartersScrap']; @@ -702,7 +706,7 @@ export default function QueryPage({ page, onUnauthorized }: { setIncludeUnassigned(event.target.checked)}>包含未分类行
- {queryBusy ? '正在查询' : currentMetricsError ? '查询失败' : '查询完成'} + {queryBusy || summaryBusy ? '正在查询' : currentMetricsError || summaryMetricsError ? '查询失败' : '查询完成'}
{organizationSummary.length > 0 &&
@@ -712,17 +716,18 @@ export default function QueryPage({ page, onUnauthorized }: { {currentMetricsError && } onClick={() => setQueryRevision(value => value + 1)}>重试} />} -
+ {drilledProduct && summaryMetricsError && setQueryRevision(value => value + 1)}>重试} />} +
亮片本部报废调整 setRateBasis(value as typeof rateBasis)} aria-label="合格率口径" />
setBasisOpen(true)} /> - openRecords(null, 'black')} /> - openRecords(null, 'bright')} /> - openRecords(null, 'black')} /> + openRecords(null, 'black')} /> + openRecords(null, 'bright')} /> + openRecords(null, 'black')} />
- {currentMetricsData ? <>来源覆盖 {currentMetricsData.coverage.sourceMonths.filter(item => item.blackRows > 0 || item.brightRows > 0).length} 个月 · 参与计算 {currentMetricsData.coverage.includedRows.toLocaleString('zh-CN')} / 原始 {currentMetricsData.coverage.rawRows.toLocaleString('zh-CN')} 行 · 未分类 {currentMetricsData.coverage.excludedBlankRows.toLocaleString('zh-CN')} 行({includeUnassigned ? '已包含' : '本次排除'}) : queryBusy ? '正在更新来源覆盖…' : '来源覆盖暂不可用'} - + {drilledProduct && <>{drilledProduct} · }{summaryMetricsData ? <>来源覆盖 {summaryMetricsData.coverage.sourceMonths.filter(item => item.blackRows > 0 || item.brightRows > 0).length} 个月 · 参与计算 {summaryMetricsData.coverage.includedRows.toLocaleString('zh-CN')} / 原始 {summaryMetricsData.coverage.rawRows.toLocaleString('zh-CN')} 行 · 未分类 {summaryMetricsData.coverage.excludedBlankRows.toLocaleString('zh-CN')} 行({includeUnassigned ? '已包含' : '本次排除'}) : summaryBusy ? '正在更新来源覆盖…' : '来源覆盖暂不可用'} +
{['department', 'group', 'product'].includes(page) && <> @@ -844,12 +849,12 @@ export default function QueryPage({ page, onUnauthorized }: {
综合公式
{formulaText(compositeFormula)}
黑片公式
{formulaText(formulaDescriptions.blackRate)}
{rateBasis === 'original' ? '亮片公式' : '亮片调整公式'}
{formulaText(brightFormula)}
-
统计范围
{year}年{period === 'month' ? ` ${MONTHS[month - 1]}` : period === 'quarter' ? ` 第${quarter}季度` : '度'} · {scopeName}
+
统计范围
{year}年{period === 'month' ? ` ${MONTHS[month - 1]}` : period === 'quarter' ? ` 第${quarter}季度` : '度'} · {drilledProduct || scopeName}
适用总重量
黑片 {numberText(rowForSummary?.black?.totalWeight)} kg · 亮片 {numberText(rowForSummary?.bright?.totalWeight)} kg
覆盖行数
黑片 {rowForSummary?.coverage.blackRows ?? '—'} · 亮片 {rowForSummary?.coverage.brightRows ?? '—'}
-
来源行覆盖
原始 {currentMetricsData?.coverage.rawRows ?? '—'} · 参与 {currentMetricsData?.coverage.includedRows ?? '—'} · 未分类行 {includeUnassigned ? '(已选择包含)' : '(本次排除)'} {currentMetricsData?.coverage.excludedBlankRows ?? '—'}
-
业务分类映射
未映射 {currentMetricsData?.coverage.unmappedRows ?? '—'} 行
-
项目组维度
{currentMetricsData?.coverage.projectGroupUnconfiguredRows ?? '—'} 行未配置项目组归属。该计数不等于排除行数;是否参与指标由当前筛选及规则决定。
+
来源行覆盖
原始 {summaryMetricsData?.coverage.rawRows ?? '—'} · 参与 {summaryMetricsData?.coverage.includedRows ?? '—'} · 未分类行 {includeUnassigned ? '(已选择包含)' : '(本次排除)'} {summaryMetricsData?.coverage.excludedBlankRows ?? '—'}
+
业务分类映射
未映射 {summaryMetricsData?.coverage.unmappedRows ?? '—'} 行
+
项目组维度
{summaryMetricsData?.coverage.projectGroupUnconfiguredRows ?? '—'} 行未配置项目组归属。该计数不等于排除行数;是否参与指标由当前筛选及规则决定。
查看服务返回的公式原文
{JSON.stringify(formulaDescriptions, null, 2)}
@@ -860,7 +865,7 @@ export default function QueryPage({ page, onUnauthorized }: { stage={recordStage} onStage={setRecordStage} onClose={() => { setSelectedRecord(null); setRecordMonth(undefined); setRecordsOpen(false); }} - query={queryParams} + query={drilledProduct ? defectQueryParams : queryParams} view={view} month={recordMonth} onUnauthorized={onUnauthorized} diff --git a/web/src/analysisConversationState.ts b/web/src/analysisConversationState.ts index b4a7be6..5390bff 100644 --- a/web/src/analysisConversationState.ts +++ b/web/src/analysisConversationState.ts @@ -87,7 +87,7 @@ export function partialAnalysisNotice(reason: unknown): string { if (value === 'mcp_error') return '部分数据查询未成功,已保留其余分析结果。可以重试或继续追问。'; if (value === 'length') return '回答达到输出长度上限,已保存现有内容。可以重试或继续追问。'; if (/timeout|超时/.test(value)) return '本轮分析达到处理时限,已保存现有结果。可以重试或继续追问。'; - if (value === 'evidence_incomplete') return '所需数据尚未齐全,已展示现有结果。可以继续追问。'; + if (value === 'evidence_incomplete') return '本轮分析被标记为部分完成,已展示现有结果。可以继续追问。'; return '本轮分析未完整结束,已保存现有结果。可以重试或继续追问。'; }