feat(思维导图):AI 生成接入 lpt-ai 服务
RemoteAiMindMapClient 原为 TODO 空桩,依赖 lpt.ai.endpoint/api-key 配置,从未生效。现改为依赖 AiServiceClient(lpt.ai-service.url), 调用 lpt-ai 的 /ai/generate-mind-map 接口获取 AI 大纲。 变更: - AiServiceClient 新增 generateMindMap():调用 POST /ai/generate-mind-map - RemoteAiMindMapClient 重写:注入 AiServiceClient,isAvailable() 改为检查 AiServiceClient.isConfigured(),generate() 用 lpt-ai 返回的大纲文本解析为 MindMapNode 树 - StandardMindMapServiceImpl.doGenerate():优先选 AI 客户端 (非 BUILTIN),AI 失败时自动降级到内置规则引擎 - application.yml:移除不再使用的 lpt.ai.endpoint/api-key 配置
This commit is contained in:
@@ -89,4 +89,44 @@ public class AiServiceClient {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用 lpt-ai 从学习数据生成思维导图大纲(缩进文本格式)。
|
||||
*
|
||||
* @return 缩进大纲文本;服务未配置或调用失败时返回 empty
|
||||
*/
|
||||
public Optional<String> generateMindMap(String taskName, String taskDescription,
|
||||
List<String> reports, List<String> fragments) {
|
||||
if (!isConfigured()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
try {
|
||||
Map<String, Object> body = Map.of(
|
||||
"taskName", taskName,
|
||||
"taskDescription", taskDescription != null ? taskDescription : "",
|
||||
"reports", reports != null ? reports : List.of(),
|
||||
"fragments", fragments != null ? fragments : List.of()
|
||||
);
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(url + "/ai/generate-mind-map"))
|
||||
.timeout(Duration.ofSeconds(timeoutSeconds))
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(objectMapper.writeValueAsString(body)))
|
||||
.build();
|
||||
|
||||
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
if (response.statusCode() != 200) {
|
||||
log.warn("lpt-ai 生成思维导图失败: status={}, body={}", response.statusCode(),
|
||||
response.body() != null ? response.body().substring(0, Math.min(200, response.body().length())) : "");
|
||||
return Optional.empty();
|
||||
}
|
||||
JsonNode json = objectMapper.readTree(response.body());
|
||||
String outline = json.path("outline").asText(null);
|
||||
return Optional.ofNullable(outline).filter(s -> !s.isBlank());
|
||||
} catch (Exception e) {
|
||||
log.warn("lpt-ai 思维导图调用异常,将降级: {}", e.getMessage());
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user