|
|
@@ -58,6 +58,7 @@ class TopicTablePreview:
|
|
|
result: GenerationResult
|
|
|
source: dict[str, Any]
|
|
|
topic: dict[str, Any]
|
|
|
+ field_catalog: list[dict[str, Any]]
|
|
|
llm_output: dict[str, Any]
|
|
|
|
|
|
|
|
|
@@ -181,6 +182,7 @@ def _field_catalog(snapshot: dict[str, Any]) -> list[dict[str, Any]]:
|
|
|
route: str,
|
|
|
point_id: Any = None,
|
|
|
item_ids: list[Any] | None = None,
|
|
|
+ is_current: bool = True,
|
|
|
) -> None:
|
|
|
value = str(field_value or "").strip()
|
|
|
if not value:
|
|
|
@@ -195,6 +197,7 @@ def _field_catalog(snapshot: dict[str, Any]) -> list[dict[str, Any]]:
|
|
|
"source_group_label": ROUTES[route]["label"],
|
|
|
"point_id": point_id,
|
|
|
"item_ids": list(item_ids or []),
|
|
|
+ "is_current": is_current,
|
|
|
}
|
|
|
)
|
|
|
|
|
|
@@ -262,21 +265,26 @@ def _field_catalog(snapshot: dict[str, Any]) -> list[dict[str, Any]]:
|
|
|
route="evidence_gap",
|
|
|
item_ids=[item_id],
|
|
|
)
|
|
|
+ active_item_ids = {
|
|
|
+ item.get("id") for item in topic.get("composition_items") or []
|
|
|
+ }
|
|
|
for relation_index, relation in enumerate(topic.get("item_relations") or []):
|
|
|
+ relation_item_ids = [
|
|
|
+ value
|
|
|
+ for value in (
|
|
|
+ relation.get("source_item_id"),
|
|
|
+ relation.get("target_item_id"),
|
|
|
+ )
|
|
|
+ if value is not None
|
|
|
+ ]
|
|
|
add(
|
|
|
field_key=f"relation:{relation_index}:reason",
|
|
|
field_path=f"topics[id={topic_id}].item_relations[{relation_index}].reason",
|
|
|
field_label="元素关系说明",
|
|
|
field_value=relation.get("reason"),
|
|
|
route="cross_dimension",
|
|
|
- item_ids=[
|
|
|
- value
|
|
|
- for value in (
|
|
|
- relation.get("source_item_id"),
|
|
|
- relation.get("target_item_id"),
|
|
|
- )
|
|
|
- if value is not None
|
|
|
- ],
|
|
|
+ item_ids=relation_item_ids,
|
|
|
+ is_current=all(item_id in active_item_ids for item_id in relation_item_ids),
|
|
|
)
|
|
|
return fields
|
|
|
|
|
|
@@ -519,6 +527,7 @@ def generate_topic_table_preview(
|
|
|
"source_url": source_payload.get("source_url"),
|
|
|
},
|
|
|
topic=snapshot["topic"],
|
|
|
+ field_catalog=field_catalog,
|
|
|
llm_output=llm_output,
|
|
|
)
|
|
|
|
|
|
@@ -553,6 +562,14 @@ def preview_to_dict(preview: TopicTablePreview) -> dict[str, Any]:
|
|
|
for need_key in need_keys:
|
|
|
if need_key:
|
|
|
queries_by_need.setdefault(need_key, []).append(query.query_text)
|
|
|
+ selected_by_field_key = {
|
|
|
+ str(need.source_ref.get("field_key")): {
|
|
|
+ "judgement": need.decision_context,
|
|
|
+ "queries": queries_by_need.get(need.need_key, []),
|
|
|
+ }
|
|
|
+ for need in result.knowledge_needs
|
|
|
+ if need.source_ref.get("field_key")
|
|
|
+ }
|
|
|
return {
|
|
|
"generator_kind": GeneratorKind.TOPIC_TABLE.value,
|
|
|
"source": preview.source,
|
|
|
@@ -598,6 +615,46 @@ def preview_to_dict(preview: TopicTablePreview) -> dict[str, Any]:
|
|
|
"key": route,
|
|
|
"label": config["label"],
|
|
|
"source_description": config["source_description"],
|
|
|
+ "field_count": sum(
|
|
|
+ 1
|
|
|
+ for field in preview.field_catalog
|
|
|
+ if field["source_group_key"] == route
|
|
|
+ ),
|
|
|
+ "selected_field_count": sum(
|
|
|
+ 1
|
|
|
+ for field in preview.field_catalog
|
|
|
+ if field["source_group_key"] == route
|
|
|
+ and field["field_key"] in selected_by_field_key
|
|
|
+ and selected_by_field_key[field["field_key"]]["queries"]
|
|
|
+ ),
|
|
|
+ "historical_field_count": sum(
|
|
|
+ 1
|
|
|
+ for field in preview.field_catalog
|
|
|
+ if field["source_group_key"] == route
|
|
|
+ and not field.get("is_current", True)
|
|
|
+ ),
|
|
|
+ "fields": [
|
|
|
+ {
|
|
|
+ "field_key": field["field_key"],
|
|
|
+ "field_path": field["field_path"],
|
|
|
+ "field_label": field["field_label"],
|
|
|
+ "field_value": field["field_value"],
|
|
|
+ "is_current": field.get("is_current", True),
|
|
|
+ "used_for_query": bool(
|
|
|
+ selected_by_field_key.get(field["field_key"], {}).get(
|
|
|
+ "queries"
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ "judgement": selected_by_field_key.get(
|
|
|
+ field["field_key"], {}
|
|
|
+ ).get("judgement"),
|
|
|
+ "queries": selected_by_field_key.get(
|
|
|
+ field["field_key"], {}
|
|
|
+ ).get("queries", []),
|
|
|
+ }
|
|
|
+ for field in preview.field_catalog
|
|
|
+ if field["source_group_key"] == route
|
|
|
+ ],
|
|
|
"field_mappings": [
|
|
|
{
|
|
|
"field_key": need.source_ref.get("field_key"),
|