♻️Refactor: 输出 MarkDown 格式见解
This commit is contained in:
@@ -50,8 +50,8 @@ public interface CommonConstant {
|
||||
{csv格式的原始数据,用,作为分隔符}
|
||||
规则集
|
||||
{可选,可能为空}
|
||||
请根据以上内容,按照以下指定格式生成内容
|
||||
{Insight: 结构化见解}
|
||||
请根据以上内容,按照以下结构生成内容,格式是 MarkDown
|
||||
{Insight: 见解}
|
||||
{Rules: 使用到的规则集}
|
||||
""";
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import com.wonder.bi.constant.CommonConstant;
|
||||
import com.wonder.bi.constant.UserConstant;
|
||||
import com.wonder.bi.exception.BusinessException;
|
||||
import com.wonder.bi.exception.ThrowUtils;
|
||||
import com.wonder.bi.manager.ChartAgentManager;
|
||||
import com.wonder.bi.manager.InsightAgentManager;
|
||||
import com.wonder.bi.manager.OpenAiManager;
|
||||
import com.wonder.bi.manager.RedisLimiterManager;
|
||||
import com.wonder.bi.model.dto.chart.*;
|
||||
@@ -54,8 +56,14 @@ public class ChartController {
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
// @Resource
|
||||
// private OpenAiManager openAiManager;
|
||||
|
||||
@Resource
|
||||
private OpenAiManager openAiManager;
|
||||
private ChartAgentManager chartAgent;
|
||||
|
||||
@Resource
|
||||
private InsightAgentManager insightAgent;
|
||||
|
||||
@Resource
|
||||
private RedisLimiterManager redisLimiterManager;
|
||||
@@ -293,17 +301,15 @@ public class ChartController {
|
||||
String csvData = ExcelUtils.excelToCsv(multipartFile);
|
||||
userInput.append(csvData).append("\n");
|
||||
|
||||
String result = openAiManager.doChat(userInput.toString());
|
||||
String[] splits = Arrays.stream(result.split("【【【【【"))
|
||||
.filter(s -> !s.equals("\n") && !s.isEmpty())
|
||||
.toArray(String[]::new);
|
||||
// String result = openAiManager.doChat(userInput.toString());
|
||||
|
||||
|
||||
// if (splits.length < 3) {
|
||||
// throw new BusinessException(ErrorCode.SYSTEM_ERROR, "AI 生成错误");
|
||||
// }
|
||||
|
||||
String genChart = splits[0].trim();
|
||||
String genResult = splits[1].trim();
|
||||
String genChart = chartAgent.getChartJson(userInput.toString());
|
||||
String genResult = insightAgent.getAnalysisInsight(userInput.toString());
|
||||
// 插入到数据库
|
||||
Chart chart = new Chart();
|
||||
chart.setName(name);
|
||||
@@ -354,24 +360,6 @@ public class ChartController {
|
||||
// 限流判断,每个用户一个限流器
|
||||
redisLimiterManager.doRateLimit("genChartByAi_" + loginUser.getId());
|
||||
|
||||
// final String prompt = "你是一个数据分析师和前端开发专家,接下来我会按照以下固定格式给你提供内容:\n" +
|
||||
// "分析需求:\n" +
|
||||
// "{数据分析的需求或者目标}\n" +
|
||||
// "原始数据:\n" +
|
||||
// "{csv格式的原始数据,用,作为分隔符}\n" +
|
||||
// "请根据这两部分内容,按照以下指定格式生成内容(此外不要输出任何多余的开头、结尾、注释)\n" +
|
||||
// "【【【【【\n" +
|
||||
// "{前端 Echarts V5 的 option 配置对象js代码,合理地将数据进行可视化,不要生成任何多余的内容,比如注释}\n" +
|
||||
// "【【【【【\n" +
|
||||
// "{明确的数据分析结论、越详细越好,不要生成多余的注释}";
|
||||
// 分析需求:
|
||||
// 分析网站用户的增长情况
|
||||
// 原始数据:
|
||||
// 日期,用户数
|
||||
// 1号,10
|
||||
// 2号,20
|
||||
// 3号,30
|
||||
|
||||
// 构造用户输入
|
||||
StringBuilder userInput = new StringBuilder();
|
||||
userInput.append("分析需求:").append("\n");
|
||||
@@ -410,14 +398,14 @@ public class ChartController {
|
||||
return;
|
||||
}
|
||||
// 调用 AI
|
||||
String result = openAiManager.doChat(userInput.toString());
|
||||
String[] splits = result.split("【【【【【");
|
||||
if (splits.length < 3) {
|
||||
handleChartUpdateError(chart.getId(), "AI 生成错误");
|
||||
return;
|
||||
}
|
||||
String genChart = splits[1].trim();
|
||||
String genResult = splits[2].trim();
|
||||
// String result = openAiManager.doChat(userInput.toString());
|
||||
// String[] splits = result.split("【【【【【");
|
||||
// if (splits.length < 3) {
|
||||
// handleChartUpdateError(chart.getId(), "AI 生成错误");
|
||||
// return;
|
||||
// }
|
||||
String genChart = chartAgent.getChartJson(userInput.toString());
|
||||
String genResult = insightAgent.getAnalysisInsight(userInput.toString());
|
||||
Chart updateChartResult = new Chart();
|
||||
updateChartResult.setId(chart.getId());
|
||||
updateChartResult.setGenChart(genChart);
|
||||
|
||||
Reference in New Issue
Block a user