update
This commit is contained in:
@@ -64,7 +64,7 @@ def calendar_claim_issues(answer, today, records):
|
||||
|
||||
|
||||
def audit_answer(answer, references, records, limitations, invoke_model, timeout, *, today="", question=""):
|
||||
calendar_errors = calendar_claim_issues(answer, today, records) + missing_table_claim_issues(answer, records)
|
||||
calendar_errors = calendar_claim_issues(answer, today, records) + missing_table_claim_issues(answer, records) + unsupported_task_claims(answer, records, today=today)
|
||||
if calendar_errors:
|
||||
return AnswerAudit(supported=False, issues=calendar_errors)
|
||||
evidence = [record for record in records if record['source_id'] in references or record['source_id'].startswith('result:')]
|
||||
@@ -93,6 +93,56 @@ def audit_answer(answer, references, records, limitations, invoke_model, timeout
|
||||
return AnswerAudit.model_validate(raw)
|
||||
|
||||
|
||||
def unsupported_task_claims(answer, records, *, today=''):
|
||||
"""Reject common missing-field claims before semantic audit can approve them."""
|
||||
tasks = [r for r in records if r.get('resource') == 'tasks' and r.get('fields')]
|
||||
if not tasks:
|
||||
return []
|
||||
issues = []
|
||||
overdue = set()
|
||||
for row in tasks:
|
||||
fields = row['fields']
|
||||
if fields.get('状态') != '进行中' or not today:
|
||||
continue
|
||||
try:
|
||||
if date.fromisoformat(str(fields.get('截止日期', ''))[:10]) < date.fromisoformat(today):
|
||||
overdue.add(str(fields.get('任务名称') or row.get('title', '')))
|
||||
except ValueError:
|
||||
continue
|
||||
if overdue:
|
||||
if re.search(r'(?:没有|不存在|无)(?:任何)?(?:任务处于)?(?:逾期|延期)(?:状态|事实|记录)?|所有任务.{0,8}(?:按时|提前)|截止日期未过|尚未构成延期', answer):
|
||||
issues.append('已读取的进行中任务已过截止日期,不能断言没有逾期或所有任务按时;今天为'+today+'。')
|
||||
for line in answer.splitlines():
|
||||
if any(name and name in line for name in overdue) and re.search(r'剩余\s*\d+\s*天|还[有剩]\s*\d+\s*天', line):
|
||||
issues.append('进行中任务已过截止日期,不能写成距离截止还剩若干天。')
|
||||
header = None
|
||||
for line in answer.splitlines():
|
||||
if not line.strip().startswith('|'):
|
||||
header = None
|
||||
continue
|
||||
cells = [re.sub(r'[*`\s]', '', c) for c in line.strip().strip('|').split('|')]
|
||||
if all(re.fullmatch(r'[:\-]+', c) for c in cells):
|
||||
continue
|
||||
if header is None:
|
||||
header = cells
|
||||
continue
|
||||
if cells and cells[0] in overdue:
|
||||
for label, value in zip(header, cells):
|
||||
if '逾期' in label and value in {'否', '未逾期', '未超期', '0', '0天', '无'}:
|
||||
issues.append(cells[0]+'已过截止日期,表格不能标成未逾期。')
|
||||
has_completed_time = any(value not in (None, '', 'None', '未提供')
|
||||
for row in tasks for label, value in row['fields'].items() if label in {'完成时间', '完成日期', '实际完成时间'})
|
||||
if not has_completed_time and re.search(r'(?:按时|提前|准时)完成|(?:已于|于)\s*(?:\d{4}[-/年])?\d{1,2}[-/月]\d{1,2}日?\s*完成', answer):
|
||||
issues.append('未取得实际完成时间,不能把截止日期当成完成日期,也不能断言按时或提前完成。')
|
||||
if not any(r.get('resource') == 'task-updates' for r in records) and re.search(
|
||||
r'(?:当前|目前)?(?:没有|无|不存在)(?:任何|相关|后续)?(?:任务)?(?:进度)?(?:更新|反馈)(?:记录|信息)?', answer):
|
||||
issues.append('未读取任务反馈,只能说明本次没有取得反馈依据,不能断言没有反馈记录。')
|
||||
if re.search(r'状态滞后|未自动更新|同步延迟|缓存延迟', answer) and not any(
|
||||
term in str(row['fields']) for row in tasks for term in ('状态滞后', '未自动更新', '同步延迟', '缓存延迟')):
|
||||
issues.append('记录没有说明系统状态滞后或同步故障,不能臆测为原因;进行中与超过截止日期可以同时成立。')
|
||||
return issues[:6]
|
||||
|
||||
|
||||
def missing_table_claim_issues(answer, records):
|
||||
"""An empty source cell is unknown, never an affirmative or negative fact."""
|
||||
def clean(text):
|
||||
|
||||
Reference in New Issue
Block a user