ai.php 4.6 KB

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