Files
BossAi/fix_element_chinese.py
selfreleaseandDevin 7a788bf8dc
CI / 后端测试 (push) Has been cancelled
CI / 前端构建 (push) Has been cancelled
feat: 话题动态化 + 要素化立案 + 知识库增强
话题动态化:
- 新增 POST /topics 端点,AI 根据场景+画像动态生成话题
- 前端3个助手页面改为兜底话题先行,换一批时AI生成
- 去除固化话题列表,支持个性化推荐

要素化立案(对接最高法67类要素表):
- 导入68类要素式起诉状模板到知识库(法〔2025〕82号)
- 覆盖民事/商事/知识产权/行政/刑事自诉/海事/环境/国家赔偿/执行9领域
- ask-analyze 法务场景自动匹配案由模板
- 新增 POST /element-filing 端点,AI填充要素生成要素式起诉状
- ChatPanel 确认事实后可一键生成要素式起诉状,支持复制全文

知识库增强:
- 要素表模板展示全中文化(type/required/标签翻译)
- 知识库页面要素表模板结构化展示(案由/要素清单/诉讼请求)
- 各类型tab显示数量和总数量

画像翻译完善:
- 补充90+个key_facts key中文翻译
- MyProfile多列紧凑布局

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-08-30 15:12:33 +08:00

90 lines
3.0 KiB
Python

"""将知识库中要素表模板的英文字段值全部转为中文。
转换内容:
- type: text→文本, textarea→长文本, date→日期, number→数字, select→选择, boolean→是否
- required: true→是, false→否
- doc_type 展示标签: element_template→要素表模板(仅展示用,存储值不变以兼容检索)
"""
import json
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from bossai import KnowledgeStore
TYPE_MAP = {
"text": "文本",
"textarea": "长文本",
"date": "日期",
"number": "数字",
"select": "选择",
"boolean": "是否",
}
REQUIRED_MAP = {
True: "是",
False: "否",
}
def convert_template(tmpl: dict) -> dict:
"""递归转换模板中的英文值为中文。"""
# 转换 elements 中的 type 和 required
elements = tmpl.get("elements", [])
for e in elements:
if "type" in e and e["type"] in TYPE_MAP:
e["type"] = TYPE_MAP[e["type"]]
if "required" in e:
val = e["required"]
if val in REQUIRED_MAP:
e["required"] = REQUIRED_MAP[val]
elif isinstance(val, str) and val.lower() == "true":
e["required"] = "是"
elif isinstance(val, str) and val.lower() == "false":
e["required"] = "否"
return tmpl
def main():
store = KnowledgeStore()
with store._conn() as conn:
with conn.cursor() as cur:
cur.execute(
"SELECT id, title, content FROM knowledge_docs WHERE doc_type='element_template' ORDER BY id"
)
rows = cur.fetchall()
print(f"找到 {len(rows)} 条要素表模板,开始转换...")
updated = 0
for doc_id, title, content in rows:
try:
tmpl = json.loads(content)
tmpl = convert_template(tmpl)
new_content = json.dumps(tmpl, ensure_ascii=False, indent=2)
if new_content != content:
cur.execute(
"UPDATE knowledge_docs SET content=%s WHERE id=%s",
(new_content, doc_id),
)
updated += 1
except Exception as e:
print(f" 跳过 {title}: {e}")
print(f"已转换 {updated}/{len(rows)} 条记录")
# 验证
with store._conn() as conn:
with conn.cursor() as cur:
cur.execute(
"SELECT content FROM knowledge_docs WHERE doc_type='element_template' LIMIT 1"
)
row = cur.fetchone()
if row:
tmpl = json.loads(row[0])
print(f"\n验证示例({tmpl.get('cause_of_action', '')}):")
for e in tmpl.get("elements", [])[:3]:
print(f" {e.get('label')}: type={e.get('type')}, required={e.get('required')}")
if __name__ == "__main__":
main()