update
This commit is contained in:
@@ -8,6 +8,7 @@ from app.core.config import get_settings
|
||||
from app.modules.work_assistant.model_gateway import complete_json
|
||||
from app.modules.work_assistant.schemas import AnswerRequest
|
||||
from app.modules.work_assistant.presentation import append_note, answer_footer, display_note
|
||||
from app.modules.work_assistant.context_text import excerpt
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -50,7 +51,7 @@ def select_evidence(payload: AnswerRequest, *, invoke_model=None) -> dict:
|
||||
for row in item.rows[:10]:
|
||||
if invoke_model is None and not any(len(str(row.get(key,"")))>500 for key in item.fields):
|
||||
continue
|
||||
fields = {key: str(row[key])[:1600] for key in item.fields if row.get(key) not in (None, "")}
|
||||
fields = {key: excerpt(str(row[key]), payload.message) for key in item.fields if row.get(key) not in (None, "")}
|
||||
record = {"query_id": _identifier(index, item), "purpose": item.purpose,
|
||||
"record_id": str(row.get("id", "")), "title": str(row.get("title", ""))[:200],
|
||||
"labels": item.fields, "fields": fields}
|
||||
@@ -131,9 +132,17 @@ def compose_verified_answer(payload: AnswerRequest, *, invoke_model=None) -> dic
|
||||
# Prefixing it again repeats a caveat already explained in context.
|
||||
rendered['verification'] = 'source_bound'
|
||||
return rendered
|
||||
selected = select_evidence(payload, invoke_model=invoke_model)
|
||||
incomplete = bool(payload.investigation_note)
|
||||
# A failed synthesis must not trigger another model call just to display
|
||||
# records. Keep a short, clearly labelled partial result under outages.
|
||||
selected = {} if incomplete else select_evidence(payload, invoke_model=invoke_model)
|
||||
definitions = {item["id"]: item for item in payload.available_resources if "id" in item}
|
||||
blocks, citations, facts = [], [], []
|
||||
if incomplete:
|
||||
detail = ("已取得部分资料,下面保留相关记录供核对;可以继续重试当前问题。"
|
||||
if any(item.status == "ok" for item in payload.evidence)
|
||||
else "相关资料尚未取得,暂不能给出可靠结论;可以继续重试当前问题。")
|
||||
blocks.append("**本次回答尚未完成。** " + detail)
|
||||
blocks.extend(payload.question_spec.get("scope_notes", []))
|
||||
if payload.question_spec.get("response_kind") == "capability_gap":
|
||||
gap = payload.question_spec.get("limitation", "")
|
||||
@@ -142,6 +151,8 @@ def compose_verified_answer(payload: AnswerRequest, *, invoke_model=None) -> dic
|
||||
indexed = list(enumerate(payload.evidence))
|
||||
indexed.sort(key=lambda pair: 0 if pair[1].purpose == "primary" else 1)
|
||||
for index, item in indexed:
|
||||
if incomplete and len(item.rows) > 3:
|
||||
item = item.model_copy(update={"rows": item.rows[:3]})
|
||||
if item.query == "current-user":
|
||||
from app.modules.work_assistant.service import compose_answer
|
||||
rendered=compose_answer(payload.model_copy(update={"protocol_version":1,"evidence":[item],"skill_ids":[],
|
||||
@@ -195,7 +206,7 @@ def compose_verified_answer(payload: AnswerRequest, *, invoke_model=None) -> dic
|
||||
continue
|
||||
value = extracts.get((rid, name), str(raw))
|
||||
if len(value) > 500:
|
||||
value = value[:500] + "…(内容已截取)"
|
||||
value = excerpt(value, payload.message, 500)
|
||||
facts.append({"query_id": key, "record_id": rid, "field": name, "value": value})
|
||||
if value == title:
|
||||
continue
|
||||
@@ -224,7 +235,8 @@ def compose_verified_answer(payload: AnswerRequest, *, invoke_model=None) -> dic
|
||||
if note and note not in '\n'.join(blocks + lines):
|
||||
lines.extend(["", "> " + note.replace("\n", "\n> ")])
|
||||
blocks.append("\n".join(lines))
|
||||
append_note(blocks, payload.investigation_note)
|
||||
if not incomplete:
|
||||
append_note(blocks, payload.investigation_note)
|
||||
append_note(blocks, answer_footer(payload))
|
||||
return {"answer": "\n\n".join(blocks), "source_ids": citations[:20], "skill_names": [],
|
||||
"verification": "evidence_bound", "facts": facts}
|
||||
"verification": "evidence_bound", "answer_status": "partial" if incomplete else "complete", "facts": facts}
|
||||
|
||||
Reference in New Issue
Block a user