ソースを参照

feat: AiGateway 新增文章答题出题方法

Sisyphus 16 時間 前
コミット
1e8a2d88cd

+ 34 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/AiGateway.java

@@ -690,4 +690,38 @@ public class AiGateway {
         }
     }
 
+    /**
+     * 生成文章阅读答题(调用 LangGraph article_quiz_graph)
+     * @return 题目列表(每项含 question/options/answer/dimension/explanation);失败返回 null
+     */
+    public List<Map<String, Object>> generateArticleQuiz(String articleTitle, String articleContent, String profileSummary) {
+        if (!enabled || isCircuitOpen()) return null;
+        try {
+            ObjectNode body = objectMapper.createObjectNode();
+            body.put("article_title", articleTitle != null ? articleTitle : "");
+            body.put("article_content", articleContent != null ? articleContent : "");
+            body.put("profile_summary", profileSummary != null ? profileSummary : "");
+
+            HttpEntity<String> entity = new HttpEntity<>(body.toString(), createJsonHeaders());
+            String url = baseUrl + "/api/v1/article/quiz/generate";
+
+            ResponseEntity<String> response = restTemplate.postForEntity(url, entity, String.class);
+            if (response.getStatusCode().is2xxSuccessful() && response.getBody() != null) {
+                JsonNode root = objectMapper.readTree(response.getBody());
+                JsonNode questions = root.get("questions");
+                if (questions != null && questions.isArray() && questions.size() > 0) {
+                    List<Map<String, Object>> list = objectMapper.convertValue(questions, List.class);
+                    consecutiveFailures.set(0);
+                    log.debug("AiGateway generateArticleQuiz 成功: {} 题", list.size());
+                    return list;
+                }
+            }
+            return null;
+        } catch (Exception e) {
+            log.warn("AiGateway generateArticleQuiz 调用失败: {}", e.getMessage());
+            recordFailure();
+            return null;
+        }
+    }
+
 }