♻️Refactor: InsightAgent 结合规则集输出见解
This commit is contained in:
@@ -34,11 +34,24 @@ public interface CommonConstant {
|
||||
" \"{明确的数据分析结论、越详细越好,不要生成多余的注释}\"";
|
||||
|
||||
String CHART_AGENT_PROMPT = """
|
||||
你是一个数据分析师和前端开发专家,我会按照以下固定格式给你提供内容:\
|
||||
你是一个数据分析师和前端开发专家,我会按照以下固定格式给你提供内容:
|
||||
分析需求:
|
||||
{数据分析的需求或者目标}
|
||||
原始数据
|
||||
{csv格式的原始数据,用,作为分隔符}
|
||||
请根据这两部分内容,按照以下指定格式生成内容
|
||||
{前端 Echarts V5 的 option 配置对象的json代码,合理地将数据进行可视化,不要生成任何多余的内容,比如注释}""";
|
||||
|
||||
String INSIGHT_AGENT_PROMPT = """
|
||||
你是一个数据分析师,我会按照以下固定格式给你提供内容:
|
||||
分析需求:
|
||||
{数据分析的需求或者目标}
|
||||
原始数据
|
||||
{csv格式的原始数据,用,作为分隔符}
|
||||
规则集
|
||||
{可选,可能为空}
|
||||
请根据以上内容,按照以下指定格式生成内容
|
||||
{Insight: 结构化见解}
|
||||
{Rules: 使用到的规则集}
|
||||
""";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.wonder.bi.manager;
|
||||
|
||||
import com.wonder.bi.constant.CommonConstant;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class InsightAgentManager {
|
||||
|
||||
private ChatClient client;
|
||||
|
||||
public InsightAgentManager(ChatClient.Builder chatClientBuilder) {
|
||||
this.client = chatClientBuilder
|
||||
.defaultSystem(CommonConstant.INSIGHT_AGENT_PROMPT)
|
||||
.build();
|
||||
}
|
||||
|
||||
public String getAnalysisInsight(String message) {
|
||||
String content = client
|
||||
.prompt(message)
|
||||
.call()
|
||||
.content();
|
||||
log.info(content);
|
||||
return content;
|
||||
}
|
||||
|
||||
public String getAnalysisInsight(String message, String rules) {
|
||||
String content = client
|
||||
.prompt(message + "\n【Rules】" + rules)
|
||||
.call()
|
||||
.content();
|
||||
log.info(content);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.wonder.bi.manager;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
class InsightAgentManagerTest {
|
||||
|
||||
@Resource
|
||||
private InsightAgentManager insightAgent;
|
||||
|
||||
@Test
|
||||
void getAnalysisInsight() {
|
||||
String insight = insightAgent.getAnalysisInsight("分析需求:\n" +
|
||||
"分析网站用户的增长情况\n" +
|
||||
"原始数据:\n" +
|
||||
"日期,用户数\n" +
|
||||
"1号,10\n" +
|
||||
"2号,20\n" +
|
||||
"3号,30\n",
|
||||
"定义增长 50% 及以上为快速增长");
|
||||
Assertions.assertNotNull(insight);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user