main
HuangHai 1 month ago
parent 33e37947fe
commit 9c0b21775a

@ -111,8 +111,51 @@ public class AiGenerate extends PptAIKit {
* PPT * PPT
*/ */
private static String createPptPrompt(String dataContent, String[] cities) { private static String createPptPrompt(String dataContent, String[] cities) {
//todo try {
return "请基于以下教育资源配置数据,为" + String.join("与", cities) + // 构建给 DeepSeek 的精简提示词
String deepseekPrompt = "你是一位专业的教育数据分析专家,请将以下教育资源配置数据进行精简总结," +
"提取关键信息和对比要点控制在500字以内重点突出" + String.join("与", cities) + "的对比差异:\n\n" +
dataContent;
System.out.println("正在调用 DeepSeek 精简数据...");
// 调用 DeepSeek 获取精简内容
String simplifiedContent = CallDeepSeek.callDeepSeek(deepseekPrompt);
if (simplifiedContent != null && !simplifiedContent.trim().isEmpty()) {
System.out.println("DeepSeek 精简完成,精简后长度: " + simplifiedContent.length());
// 使用精简后的内容构建 PPT 提示词
return "请基于以下教育资源配置数据,为" + String.join("与", cities) +
"教育资源配置对比分析创建一个专业的PPT大纲。\n\n" +
"PPT应包含以下主要部分\n" +
"1. 封面 - 标题和基本信息\n" +
"2. 目录 - 分析框架\n" +
"3. 数据概览 - 关键指标对比\n" +
"4. 详细分析 - 各维度深入对比\n" +
"5. 问题识别 - 存在的主要问题\n" +
"6. 建议方案 - 改进措施\n" +
"7. 总结 - 结论和展望\n\n" +
"请确保内容简洁明了适合PPT展示。\n\n" +
"=== 精简后的关键数据 ===\n" + simplifiedContent;
} else {
System.out.println("DeepSeek 调用失败,使用基础提示词");
return createBasicPptPrompt(cities);
}
} catch (Exception e) {
System.err.println("调用 DeepSeek 精简数据时出错: " + e.getMessage());
e.printStackTrace();
// 如果 DeepSeek 调用失败,返回基础提示词
return createBasicPptPrompt(cities);
}
}
/**
* PPT
*/
private static String createBasicPptPrompt(String[] cities) {
return "请为" + String.join("与", cities) +
"教育资源配置对比分析创建一个专业的PPT大纲。\n\n" + "教育资源配置对比分析创建一个专业的PPT大纲。\n\n" +
"PPT应包含以下主要部分\n" + "PPT应包含以下主要部分\n" +
"1. 封面 - 标题和基本信息\n" + "1. 封面 - 标题和基本信息\n" +
@ -122,8 +165,7 @@ public class AiGenerate extends PptAIKit {
"5. 问题识别 - 存在的主要问题\n" + "5. 问题识别 - 存在的主要问题\n" +
"6. 建议方案 - 改进措施\n" + "6. 建议方案 - 改进措施\n" +
"7. 总结 - 结论和展望\n\n" + "7. 总结 - 结论和展望\n\n" +
"请确保内容简洁明了适合PPT展示。\n\n" + "请基于教育资源配置的一般分析框架,重点关注对比分析结果。";
"=== 原始数据 ===\n" + dataContent;
} }
/** /**

@ -175,5 +175,42 @@ public class CallDeepSeek {
void onError(String error); void onError(String error);
} }
/**
* DeepSeek API
*
* @param prompt
* @return DeepSeek
*/
public static String callDeepSeek(String prompt) {
try {
JSONObject jsonPayload = createRequestPayload(prompt);
// 设置为非流式响应
jsonPayload.set("stream", false);
HttpClient client = createHttpClient();
java.net.http.HttpRequest request = createHttpRequest(jsonPayload);
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
JSONObject responseJson = JSONUtil.parseObj(response.body());
if (responseJson.containsKey("choices")) {
return responseJson.getJSONArray("choices")
.getJSONObject(0)
.getJSONObject("message")
.getStr("content", "");
}
} else {
System.err.println("DeepSeek API调用失败: " + response.statusCode() + " Body: " + response.body());
return null;
}
} catch (Exception e) {
System.err.println("调用DeepSeek API时出错: " + e.getMessage());
e.printStackTrace();
return null;
}
return null;
}
} }

Loading…
Cancel
Save