seed_defense_questions.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # seed_defense_questions.py
  2. # 向 defense_questions 表插入 10 道 AI大模型开发工程师 答辩问题
  3. # 运行:conda activate edu_agent && python backend/agents/defense/manual_tests/seed_defense_questions.py
  4. import sys, asyncio, json
  5. sys.path.insert(0, ".")
  6. from dotenv import load_dotenv
  7. load_dotenv(".env.local")
  8. from sqlalchemy import text
  9. from backend.dependencies import AsyncSessionLocal
  10. TARGET_POSITION = "AI大模型开发工程师"
  11. QUESTIONS = [
  12. {
  13. "content": "请解释 Transformer 的自注意力机制(Self-Attention)原理,并说明 Q、K、V 矩阵的含义和计算过程。",
  14. "difficulty": "medium",
  15. "tags": ["Transformer", "Self-Attention", "深度学习基础"],
  16. },
  17. {
  18. "content": "大模型微调有哪些主流方法?请对比 Full Fine-tuning、LoRA、QLoRA 的适用场景和资源消耗差异。",
  19. "difficulty": "medium",
  20. "tags": ["微调", "LoRA", "QLoRA", "大模型训练"],
  21. },
  22. {
  23. "content": "什么是 RAG(检索增强生成)?请描述其完整流程,并说明为什么 RAG 比直接 Prompt 更适合处理私域知识问答。",
  24. "difficulty": "easy",
  25. "tags": ["RAG", "向量检索", "知识库"],
  26. },
  27. {
  28. "content": "向量数据库的作用是什么?Faiss、Milvus、Chroma 各有什么特点,你会如何在生产环境中选型?",
  29. "difficulty": "medium",
  30. "tags": ["向量数据库", "Faiss", "Milvus", "Chroma"],
  31. },
  32. {
  33. "content": "LLM 推理时的 KV Cache 是什么机制?它如何减少重复计算,对推理速度有什么影响?",
  34. "difficulty": "hard",
  35. "tags": ["KV Cache", "推理优化", "大模型部署"],
  36. },
  37. {
  38. "content": "请解释 LangChain 中 Chain 和 Agent 的区别,并举例说明你会在什么场景下选择 Agent 而非固定 Chain。",
  39. "difficulty": "medium",
  40. "tags": ["LangChain", "Agent", "工程实践"],
  41. },
  42. {
  43. "content": "如何评估一个 RAG 系统的效果?你了解哪些 RAG 评测指标(如 Faithfulness、Answer Relevancy),如何用 RAGAS 进行评测?",
  44. "difficulty": "hard",
  45. "tags": ["RAG评测", "RAGAS", "Faithfulness"],
  46. },
  47. {
  48. "content": "Prompt Engineering 有哪些常用技巧?请对比 Zero-shot、Few-shot、Chain-of-Thought 各自的适用场景。",
  49. "difficulty": "easy",
  50. "tags": ["Prompt Engineering", "CoT", "Few-shot"],
  51. },
  52. {
  53. "content": "大模型部署时如何做量化(Quantization)?INT8 和 INT4 量化各有什么优缺点,对精度和速度的影响如何?",
  54. "difficulty": "hard",
  55. "tags": ["量化", "INT8", "INT4", "大模型部署"],
  56. },
  57. {
  58. "content": "LangGraph 与 LangChain 的 AgentExecutor 有什么区别?LangGraph 适合解决什么类型的问题,请举一个实际应用场景。",
  59. "difficulty": "medium",
  60. "tags": ["LangGraph", "状态机", "多步推理"],
  61. },
  62. ]
  63. async def main():
  64. async with AsyncSessionLocal() as session:
  65. async with session.begin():
  66. for q in QUESTIONS:
  67. await session.execute(
  68. text("""
  69. INSERT INTO defense_questions
  70. (content, difficulty, tags, target_position, tenant_id, is_active)
  71. VALUES
  72. (:content, :difficulty, :tags, :target_position, 'tenant_default', TRUE)
  73. """),
  74. {
  75. "content": q["content"],
  76. "difficulty": q["difficulty"],
  77. "tags": json.dumps(q["tags"], ensure_ascii=False),
  78. "target_position": TARGET_POSITION,
  79. },
  80. )
  81. # 验证写入
  82. async with AsyncSessionLocal() as session:
  83. result = await session.execute(
  84. text("SELECT id, difficulty, LEFT(content, 30) AS preview FROM defense_questions WHERE target_position = :pos ORDER BY created_at"),
  85. {"pos": TARGET_POSITION},
  86. )
  87. rows = result.mappings().all()
  88. print(f"\n插入成功,共 {len(rows)} 条评分项:")
  89. for i, r in enumerate(rows, 1):
  90. print(f" {i:2d}. [{r['difficulty']:6s}] {r['preview']}...")
  91. asyncio.run(main())