46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
|
|
import re
|
|||
|
|
|
|||
|
|
file_path = 'server/src/app/services/user_agent_knowledge.py'
|
|||
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
content = re.sub(
|
|||
|
|
r'(def _build_fast_knowledge_answer\([\s\S]*?-> str \| None:\n)',
|
|||
|
|
r'\1 return None\n',
|
|||
|
|
content
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
content = re.sub(
|
|||
|
|
r'heading_text = f" > \{heading\}" if heading else ""',
|
|||
|
|
r'if "表格行级检索线索" in heading:\n heading = heading.replace("表格行级检索线索", "").strip(" >")\n heading_text = f"({heading})" if heading else ""\n item_title = item.get("title") or title',
|
|||
|
|
content
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
content = re.sub(
|
|||
|
|
r'evidence_lines\.append\(f"- 《\{item\.get\(\'title\'\) or title\}》\{heading_text\}:\{summary\}\\n\{preview\}"\)',
|
|||
|
|
r'evidence_lines.append(f"- **《{item_title}》** {heading_text}\\n {summary}\\n{preview}")',
|
|||
|
|
content
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
content = re.sub(
|
|||
|
|
r'evidence_lines\.append\(f"- 《\{item\.get\(\'title\'\) or title\}》\{heading_text\}:\\n\{rendered\}"\)',
|
|||
|
|
r'evidence_lines.append(f"- **《{item_title}》** {heading_text}\\n{rendered}")',
|
|||
|
|
content
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
content = re.sub(
|
|||
|
|
r'evidence_lines\.append\(f"- 《\{item\.get\(\'title\'\) or title\}》\{heading_text\}:\{rendered\}"\)',
|
|||
|
|
r'evidence_lines.append(f"- **《{item_title}》** {heading_text}\\n {rendered}")',
|
|||
|
|
content
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
content = re.sub(
|
|||
|
|
r'evidence_lines\.append\(f"- 《\{item_title\}》:\{excerpt\}"\)',
|
|||
|
|
r'evidence_lines.append(f"- **《{item_title}》**:{excerpt}")',
|
|||
|
|
content
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
with open(file_path, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
print('Done.')
|