fix(platform): 合并本地修复到测试环境
This commit is contained in:
commit
975e8bbcf5
41 files changed
+4564
-768
No files matched your search
@@ -0,0 +1,82 @@
|
||||
"""
|
||||
scripts/seed_fire_extinguisher_faq.py
|
||||
|
||||
用途:为“人事规章”Agent 写入灭火器常见问题的本地 FAQ 兜底。
|
||||
依赖:Flask 应用、PostgreSQL quick_questions 表。
|
||||
逻辑:按 Agent 名称和标准问题幂等查找;不存在则创建,存在则补齐同义问法与标准答案。
|
||||
执行:在仓库根目录运行 `python scripts/seed_fire_extinguisher_faq.py`。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / 'backend'))
|
||||
|
||||
from app import create_app, db # noqa: E402
|
||||
from app.models import Agent, QuickQuestion # noqa: E402
|
||||
|
||||
|
||||
FAQ_ITEMS = [
|
||||
{
|
||||
'title': '水型灭火器适用场合',
|
||||
'question': '水型灭火器适用场合',
|
||||
'aliases': [
|
||||
'水型灭火器适用于什么火灾',
|
||||
'水基灭火器能灭什么火',
|
||||
'水型灭火器适用范围',
|
||||
'A类火灾用什么灭火器',
|
||||
],
|
||||
'answer': (
|
||||
'水型灭火器主要适用于 A 类火灾,即木材、纸张、棉麻等固体可燃物火灾。'
|
||||
'不适用于油类、汽油等 B 类液体火灾,也不适用于带电设备火灾;具体以现场灭火器标识和公司安全制度为准。'
|
||||
),
|
||||
},
|
||||
{
|
||||
'title': '不同类型灭火器怎么使用',
|
||||
'question': '不同类型灭火器怎么使用',
|
||||
'aliases': [
|
||||
'灭火器使用方法',
|
||||
'灭火器适用场合和使用注意事项',
|
||||
'各种灭火器分别适合什么火灾',
|
||||
],
|
||||
'answer': (
|
||||
'使用灭火器前先确认火灾类型并站在上风口。水型灭火器主要用于 A 类固体火灾;'
|
||||
'干粉灭火器适用范围较广,但仍需按瓶身标识选择;二氧化碳灭火器常用于电气设备和精密仪器。'
|
||||
'油类、电气等场景不要盲目使用水型灭火器,应先断电并按现场安全制度处置。'
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def main() -> None:
|
||||
app = create_app()
|
||||
with app.app_context():
|
||||
agent = db.session.query(Agent).filter(Agent.name == '人事规章').first()
|
||||
if not agent:
|
||||
raise RuntimeError('未找到“人事规章”Agent,请先确认 Agent 已初始化。')
|
||||
for item in FAQ_ITEMS:
|
||||
faq = db.session.query(QuickQuestion).filter(
|
||||
QuickQuestion.user_id.is_(None),
|
||||
QuickQuestion.agent_id == agent.id,
|
||||
QuickQuestion.question == item['question'],
|
||||
).first()
|
||||
if faq is None:
|
||||
faq = QuickQuestion(user_id=None, agent_id=agent.id, sort_order=10)
|
||||
db.session.add(faq)
|
||||
faq.title = item['title']
|
||||
faq.question = item['question']
|
||||
faq.aliases = item['aliases']
|
||||
faq.answer = item['answer']
|
||||
faq.cache_enabled = True
|
||||
faq.is_enabled = True
|
||||
faq.stale_at = None
|
||||
faq.stale_reason = None
|
||||
db.session.commit()
|
||||
print(f'已为 Agent={agent.id} 写入 {len(FAQ_ITEMS)} 条灭火器 FAQ。')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in new issue
Block a user