dp-zp-agent/tools/answer_evaluation/render_answer.py

30 lines
1.5 KiB
Python

"""Render only validated structured facts; never infer facts or read gold."""
from copy import deepcopy
def render_graph_answer(answer: dict, context: dict) -> dict:
out = deepcopy(answer)
lines = []
if out['status'] == 'ok':
labels = {'title': 'názov práce', 'year': 'rok práce', 'start_year': 'začiatok štúdia',
'keyword': 'kľúčové slovo', 'category': 'kategória', 'document_author': 'autor dokumentu'}
for claim in out['claims']:
values = [f'{label}: {claim[key]}' for key, label in labels.items() if claim.get(key) is not None]
lines.append(claim['person'] + (' — ' + '; '.join(values) if values else '') + '.')
if out.get('count') is not None:
lines.append(f'Počet vyhovujúcich osôb: {out["count"]}.')
if context.get('complete') is False or context.get('truncated'):
lines.append('Výpis je neúplný.')
elif context.get('complete') is None:
lines.append('Úplnosť vyhľadania nemožno zaručiť.')
elif out['status'] == 'ambiguous':
lines.append('Požiadavka je nejednoznačná; údaje nemožno spoľahlivo určiť.')
elif out['status'] == 'error':
lines.append('Vyhľadanie zlyhalo; odpoveď nemožno pripraviť.')
else:
lines.append('Požadované údaje sa v dostupných podkladoch nenašli.')
if out['source_urls']:
lines.append('Zdroje: ' + ', '.join(out['source_urls']))
out['answer'] = '\n'.join(lines)
return out