允许 Agent 在循环中查目录、修正查询和提问,保留实时权限检查及模型原始回答。 统一相同查询证据与图表资源;排名补齐阶段指标,修正 OR 重量筛选,并限制模型明细输入。 增加运行恢复、图表自适应坐标轴与两位小数,修复报告主图选择、重复图及边缘标签。 验证:独立副本通过 162 项 Python、73 项前端及 21 项后端测试,前端构建通过。 线上已用原 8 题复测,并追加两轮双期对比;TOP100 与组合筛选分别核对 100 行和 20 行。
53 lines
2.7 KiB
Python
53 lines
2.7 KiB
Python
"""把意图提示转换为可启动的 DSH 执行信封,不在启动前确认业务参数。"""
|
|
import copy
|
|
|
|
|
|
def execution_task(hint, question, directory):
|
|
from nao_period import normalize_period
|
|
hint = hint if isinstance(hint, dict) else {}
|
|
years = []
|
|
for item in directory.get('periods', []):
|
|
try:
|
|
year = int(item[:4]) if isinstance(item, str) else int(item['year'])
|
|
if 1900 <= year <= 2200:
|
|
years.append(year)
|
|
except (ValueError, TypeError, KeyError):
|
|
pass
|
|
latest = directory.get('latestDataPeriod') or {}
|
|
if isinstance(latest, dict) and type(latest.get('year')) is int:
|
|
years.append(latest['year'])
|
|
period = None
|
|
try:
|
|
period = normalize_period(hint.get('period'))
|
|
except (ValueError, TypeError):
|
|
pass
|
|
if not period and years:
|
|
period = {'year': max(years)}
|
|
# 期间只是省略参数时的默认值;实际工具调用可自行指定或修正期间。
|
|
task = {**copy.deepcopy(hint), 'version': 1, 'question': question, 'goal': question[:1600],
|
|
'kind': 'analysis', 'executionMode': 'native_agent', 'agentDriven': True,
|
|
'needsClarification': False, 'clarification': '', 'filters': {},
|
|
'period': period, 'freshQuery': True,
|
|
'responseStyle': hint.get('responseStyle', 'standard'),
|
|
'visualPreference': hint.get('visualPreference', 'auto'), 'visualType': None,
|
|
'historyMode': 'none', 'memberFields': [], 'sourceFieldLabels': {}}
|
|
for key, allowed, default in [('fields', {'rate','scrapRate','totalWeight','scrapWeight'}, ['rate']),
|
|
('stages', {'black','bright'}, []),
|
|
('dimensions', {'department','group','product','defect'}, [])]:
|
|
raw = hint.get(key)
|
|
task[key] = list(dict.fromkeys(v for v in raw if isinstance(v, str) and v in allowed)) if isinstance(raw, list) else default
|
|
if key == 'fields' and not task[key]:
|
|
task[key] = default
|
|
for key in ('trendRequired','comparisonRequired','verifySource','fullDetails'):
|
|
task[key] = hint.get(key) is True
|
|
for key in ('queryPlan','clarificationRequest','productResolution','productMatch','directResponse','comparisonMode'):
|
|
task.pop(key, None)
|
|
from dsh_model_input import canonical_proposal
|
|
from dsh_row_selection import selection_hint
|
|
literal = selection_hint(question)
|
|
if literal:
|
|
task['aggregateSelection'] = literal
|
|
task['fields'] = canonical_proposal({'fields': task['fields']}, question=question).get('fields', task['fields'])
|
|
task['dimensionStages'] = {dimension: task['stages'] for dimension in task['dimensions']}
|
|
return task
|