|
|
@@ -256,6 +256,60 @@ public class AiGateway {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 生成自检 AI 建议(调用 LangGraph self_check_analysis_graph)
|
|
|
+ * @return 含 "advice_json" 和 "fallback_used" 的 Map;失败返回 null
|
|
|
+ */
|
|
|
+ public Map<String, Object> generateSelfCheckAdvice(Map<String, Object> inputs) {
|
|
|
+ if (!enabled || isCircuitOpen()) return null;
|
|
|
+ try {
|
|
|
+ ObjectNode body = objectMapper.valueToTree(inputs);
|
|
|
+ HttpEntity<String> entity = new HttpEntity<>(body.toString(), createJsonHeaders());
|
|
|
+ String url = baseUrl + "/api/v1/self-check/analysis";
|
|
|
+ ResponseEntity<String> response = restTemplate.postForEntity(url, entity, String.class);
|
|
|
+ if (response.getStatusCode().is2xxSuccessful() && response.getBody() != null) {
|
|
|
+ JsonNode root = objectMapper.readTree(response.getBody());
|
|
|
+ Map<String, Object> result = new LinkedHashMap<>();
|
|
|
+ result.put("advice_json", root.has("advice_json") ? root.get("advice_json").asText() : null);
|
|
|
+ result.put("fallback_used", root.has("fallback_used") ? root.get("fallback_used").asBoolean() : true);
|
|
|
+ consecutiveFailures.set(0);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("AiGateway generateSelfCheckAdvice 调用失败: {}", e.getMessage());
|
|
|
+ recordFailure();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成自检趋势分析(调用 LangGraph self_check_trend_graph)
|
|
|
+ * @return 含 "aiInsight" 和 "trendSummary" 的 Map;失败返回 null
|
|
|
+ */
|
|
|
+ public Map<String, Object> generateSelfCheckTrend(Map<String, Object> inputs) {
|
|
|
+ if (!enabled || isCircuitOpen()) return null;
|
|
|
+ try {
|
|
|
+ ObjectNode body = objectMapper.valueToTree(inputs);
|
|
|
+ HttpEntity<String> entity = new HttpEntity<>(body.toString(), createJsonHeaders());
|
|
|
+ String url = baseUrl + "/api/v1/self-check/trend";
|
|
|
+ ResponseEntity<String> response = restTemplate.postForEntity(url, entity, String.class);
|
|
|
+ if (response.getStatusCode().is2xxSuccessful() && response.getBody() != null) {
|
|
|
+ JsonNode root = objectMapper.readTree(response.getBody());
|
|
|
+ Map<String, Object> result = new LinkedHashMap<>();
|
|
|
+ result.put("aiInsight", root.has("aiInsight") ? root.get("aiInsight").asText() : "");
|
|
|
+ result.put("trendSummary", root.has("trendSummary") ? root.get("trendSummary").asText() : "");
|
|
|
+ consecutiveFailures.set(0);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("AiGateway generateSelfCheckTrend 调用失败: {}", e.getMessage());
|
|
|
+ recordFailure();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private List<Map<String, Object>> parseTasks(JsonNode tasksNode) {
|
|
|
List<Map<String, Object>> tasks = new ArrayList<>();
|
|
|
if (tasksNode != null && tasksNode.isArray()) {
|