ai.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. return [
  3. /*
  4. |--------------------------------------------------------------------------
  5. | AI Service Configuration
  6. |--------------------------------------------------------------------------
  7. */
  8. 'driver' => env('AI_DRIVER', 'deepseek'),
  9. 'deepseek' => [
  10. 'api_key' => env('DEEPSEEK_API_KEY'),
  11. 'base_url' => 'https://api.deepseek.com/v1',
  12. 'model' => 'deepseek-chat',
  13. 'timeout' => 30,
  14. ],
  15. 'openai' => [
  16. 'api_key' => env('OPENAI_API_KEY'),
  17. 'base_url' => 'https://api.openai.com/v1',
  18. 'model' => 'gpt-3.5-turbo',
  19. 'timeout' => 30,
  20. ],
  21. 'question_detection_prompt' => <<<'PROMPT'
  22. 请判断下面这段 Markdown 是否是一道数学题目。
  23. 判断逻辑:
  24. - 若包含题号(例:1. 2. 3.)
  25. - 或包含数学公式、括号空格(___)、选项(A. B.)
  26. - 或包含题图
  27. 非题目内容包括:知识点介绍、章节标题、教材说明、前言、目录、示例说明。
  28. 题目内容:
  29. {content}
  30. 请输出 JSON 格式:
  31. {
  32. "is_question": true|false,
  33. "confidence": 0 ~ 1
  34. }
  35. PROMPT,
  36. 'question_parse_prompt' => <<<'PROMPT'
  37. 你是一名“数学题目结构化解析器”。请把下面这段 Markdown 解析成一条题目候选的结构化 JSON。
  38. 要求:
  39. - 只输出 JSON,不要输出其它文本
  40. - 必须包含字段:index, stem, options, images, tables, is_question_candidate, ai_confidence
  41. - index 为题号(整数);若无法识别,则使用输入 index
  42. - stem 为题干字符串(保留 Markdown/LaTeX)
  43. - options 为对象,key 为 A/B/C/D...(若没有选项则为 null)
  44. - images 为数组,包含图片 URL(Markdown 图片或 <img src="">)
  45. - tables 为数组,包含表格 HTML 或 Markdown 表格原文
  46. - is_question_candidate 为布尔值:是否为“可进入候选库”的题目
  47. - ai_confidence 为 0~1 的浮点数
  48. 输入 index: {index}
  49. 输入内容:
  50. {content}
  51. 输出 JSON 示例:
  52. {
  53. "index": 1,
  54. "stem": "....",
  55. "options": {"A": "...", "B": "..."},
  56. "images": ["https://..."],
  57. "tables": [],
  58. "is_question_candidate": true,
  59. "ai_confidence": 0.82
  60. }
  61. PROMPT,
  62. 'knowledge_match_prompt' => <<<'PROMPT'
  63. 你是一名数学知识点匹配器。给定题目内容与知识点候选列表,输出最相关的知识点。
  64. 要求:
  65. - 只输出 JSON,不要输出其它内容
  66. - 输出字段为 knowledge_points 数组,每个元素包含 kp_code 与 weight (0~1)
  67. - 若无法匹配,返回空数组
  68. 题目内容:
  69. {question}
  70. 候选列表:
  71. {candidates}
  72. 输出 JSON 示例:
  73. {
  74. "knowledge_points": [
  75. {"kp_code": "A01", "weight": 0.82},
  76. {"kp_code": "B03", "weight": 0.45}
  77. ]
  78. }
  79. PROMPT,
  80. 'solution_steps_prompt' => <<<'PROMPT'
  81. 你是一名数学解题专家,请为题目生成“分步骤评分解题过程”。
  82. 要求:
  83. - 只输出 JSON
  84. - steps 为数组,每一步包含:
  85. - step_index: 从 1 开始
  86. - title: 本步标题
  87. - content: 本步解释
  88. - score: 本步分值(数字)
  89. - kp_codes: 与本步相关的知识点数组
  90. 题目内容:
  91. {question}
  92. 输出 JSON 示例:
  93. {
  94. "solution": "整体解题思路概述",
  95. "steps": [
  96. {"step_index": 1, "title": "...", "content": "...", "score": 4, "kp_codes": ["A01"]},
  97. {"step_index": 2, "title": "...", "content": "...", "score": 6, "kp_codes": ["B02", "C03"]}
  98. ]
  99. }
  100. PROMPT,
  101. 'question_generation_prompt' => <<<'PROMPT'
  102. 你是一名“数学题目完善助手”。给定原题干与可选图片外链,请补全题目关键信息并做轻量修订。
  103. 要求:
  104. - 只输出 JSON
  105. - 必须包含字段:stem, options, answer, solution, question_type, difficulty, knowledge_points, solution_steps
  106. - 可选字段:abilities(能力/技能点数组)
  107. - stem 只做轻微修订(排版/符号/错别字),不得改题意
  108. - 若提供图片外链(image_urls),可结合图片理解题意,但不要生成 SVG
  109. - question_type 仅允许:choice / fill / answer
  110. - answer 类题目必须提供 solution_steps(分步评分),每步包含 score 与 kp_codes
  111. - knowledge_points 为题目级知识点列表
  112. 材料内容(含题干与图片):
  113. {content}
  114. 输出 JSON 示例:
  115. {
  116. "stem": "...",
  117. "options": {"A": "...", "B": "..."},
  118. "answer": "...",
  119. "solution": "...",
  120. "question_type": "answer",
  121. "difficulty": 0.6,
  122. "knowledge_points": ["A01"],
  123. "solution_steps": [
  124. {"step_index": 1, "title": "...", "content": "...", "score": 4, "kp_codes": ["A01"]}
  125. ],
  126. "abilities": ["计算能力", "分析能力"]
  127. }
  128. PROMPT,
  129. ];