|
|
@@ -1,10 +1,13 @@
|
|
|
from __future__ import annotations
|
|
|
|
|
|
+import logging
|
|
|
from datetime import datetime, timezone
|
|
|
+from pathlib import Path
|
|
|
from typing import Any
|
|
|
|
|
|
from content_agent.constants import RUNTIME_RECORD_SCHEMA_VERSION
|
|
|
from content_agent.errors import ContentAgentError, ErrorCode
|
|
|
+from content_agent.integrations import config_store
|
|
|
from content_agent.integrations.query_prompt_config import DEFAULT_PROFILE
|
|
|
from content_agent.interfaces import QueryVariantClient, QueryVariantResult, RuntimeFileStore
|
|
|
from content_agent.record_payload import with_raw_payload
|
|
|
@@ -304,9 +307,31 @@ def _sample_elements(binding: dict[str, Any]) -> list[dict[str, Any]]:
|
|
|
return [item for item in values if isinstance(item, dict)] if isinstance(values, list) else []
|
|
|
|
|
|
|
|
|
+_LOG = logging.getLogger(__name__)
|
|
|
+_PURPOSE_PREFIX_PATH = Path("product_documents/配置/purpose_point_prefixes.v1.json")
|
|
|
+
|
|
|
+
|
|
|
+def _purpose_point_prefixes() -> tuple[str, ...]:
|
|
|
+ """目的点要剥的动作词前缀:**全部来自 JSON 配置**(config_store 按 mtime 缓存),代码不写死任何前缀表。
|
|
|
+ 以后加词只改 `product_documents/配置/purpose_point_prefixes.v1.json`。
|
|
|
+ 读不到/为空 → 不剥前缀并**告警**(而非静默退回旧表,免得配置没生效却看着像正常)。"""
|
|
|
+ try:
|
|
|
+ data, _ = config_store.load_json(_PURPOSE_PREFIX_PATH)
|
|
|
+ prefixes = data.get("prefixes") if isinstance(data, dict) else None
|
|
|
+ if isinstance(prefixes, list):
|
|
|
+ cleaned = tuple(str(p) for p in prefixes if p)
|
|
|
+ if cleaned:
|
|
|
+ return cleaned
|
|
|
+ except (FileNotFoundError, OSError, ValueError) as exc:
|
|
|
+ _LOG.warning("目的点前缀配置读取失败(%s),本次不剥前缀:%s", _PURPOSE_PREFIX_PATH, exc)
|
|
|
+ return ()
|
|
|
+ _LOG.warning("目的点前缀配置缺 prefixes 或为空(%s),本次不剥前缀", _PURPOSE_PREFIX_PATH)
|
|
|
+ return ()
|
|
|
+
|
|
|
+
|
|
|
def _cleanup_purpose_point(value: str) -> str:
|
|
|
text = _normalize_query(value)
|
|
|
- for prefix in ("分享", "讲述", "表达", "传递", "呼吁", "介绍", "展示", "记录", "呈现"):
|
|
|
+ for prefix in _purpose_point_prefixes():
|
|
|
if text.startswith(prefix) and len(text) > len(prefix):
|
|
|
text = text[len(prefix):].strip(" ,,。::")
|
|
|
break
|