Commit fe27629d authored by alex yao's avatar alex yao

feat:优化图表插件 X宽度适配

parent 918b7f90
...@@ -642,15 +642,6 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -642,15 +642,6 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
private AgentResultEntity llmExecutorAndOutput(Float topP, boolean stream, String model, Message[] messageArray, FunctionResult functionResult, List<KnowledgeContentResult> knowledgeResult, List<DBChainResult> dbChainResults, HttpServletResponse httpServletResponse) throws Exception { private AgentResultEntity llmExecutorAndOutput(Float topP, boolean stream, String model, Message[] messageArray, FunctionResult functionResult, List<KnowledgeContentResult> knowledgeResult, List<DBChainResult> dbChainResults, HttpServletResponse httpServletResponse) throws Exception {
if (stream) { if (stream) {
SSEUtil sseUtil = new SSEUtil(httpServletResponse); SSEUtil sseUtil = new SSEUtil(httpServletResponse);
if (ObjectUtil.isNotNull(functionResult) && StringUtils.isNotBlank(functionResult.getFunctionName())) {
LargeModelDemandResult result = new LargeModelDemandResult();
result.setCode("0");
ToolFunction toolFunction = functionResultConvertToolFunction(functionResult);
result.setFunction(toolFunction);
result.setDbChainResult(null);
result.setKnowledgeContentResult(null);
sseUtil.send(JsonUtils.serialize(result));
}
if (CollectionUtils.isNotEmpty(dbChainResults)) { if (CollectionUtils.isNotEmpty(dbChainResults)) {
LargeModelDemandResult result = new LargeModelDemandResult(); LargeModelDemandResult result = new LargeModelDemandResult();
result.setCode("0"); result.setCode("0");
...@@ -667,6 +658,15 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -667,6 +658,15 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
result.setKnowledgeContentResult(knowledgeResult); result.setKnowledgeContentResult(knowledgeResult);
sseUtil.send(JsonUtils.serialize(result)); sseUtil.send(JsonUtils.serialize(result));
} }
if (ObjectUtil.isNotNull(functionResult) && StringUtils.isNotBlank(functionResult.getFunctionName())) {
LargeModelDemandResult result = new LargeModelDemandResult();
result.setCode("0");
ToolFunction toolFunction = functionResultConvertToolFunction(functionResult);
result.setFunction(toolFunction);
result.setDbChainResult(null);
result.setKnowledgeContentResult(null);
sseUtil.send(JsonUtils.serialize(result));
}
BufferedReader bufferedReader = invokeLLMStream(model, messageArray, topP); BufferedReader bufferedReader = invokeLLMStream(model, messageArray, topP);
return textOutputStream(sseUtil, bufferedReader); return textOutputStream(sseUtil, bufferedReader);
} else { } else {
......
...@@ -37,6 +37,7 @@ public class ChartGenerateFunction extends AbstractLargeModelFunction { ...@@ -37,6 +37,7 @@ public class ChartGenerateFunction extends AbstractLargeModelFunction {
private final Logger logger = LoggerFactory.getLogger(ChartGenerateFunction.class); private final Logger logger = LoggerFactory.getLogger(ChartGenerateFunction.class);
private final String MODEL = "deepseek-v3"; private final String MODEL = "deepseek-v3";
// private final String MODEL = "glm-4-plus";
private final String DESC = "根据用户问题和现有数据生成mermaid图表,如生成饼状图,折线图,散点图,柱状图,流程图等"; private final String DESC = "根据用户问题和现有数据生成mermaid图表,如生成饼状图,折线图,散点图,柱状图,流程图等";
...@@ -71,9 +72,22 @@ public class ChartGenerateFunction extends AbstractLargeModelFunction { ...@@ -71,9 +72,22 @@ public class ChartGenerateFunction extends AbstractLargeModelFunction {
"1. 图表标题应准确反映数据主题\n" + "1. 图表标题应准确反映数据主题\n" +
"2. 使用与数据类型匹配的图表子类型(如堆积柱状图、面积折线图等)\n" + "2. 使用与数据类型匹配的图表子类型(如堆积柱状图、面积折线图等)\n" +
"3. 坐标轴需要包含单位说明\n" + "3. 坐标轴需要包含单位说明\n" +
"4. 使用最简单的方式生成,不要样式\n" + "4. 注意样式,如x轴内容过多时适当调整x轴宽度\n" +
"5. 实际使用中用户的数据和要求不同,不能直接使用例子进行输出,要按照用户要求的图表进行\n" + "5. 实际使用中用户的数据和要求不同,不能直接使用例子进行输出,要按照用户要求的图表进行\n" +
"6. 注意样式,如x轴内容过多时适当调整x轴宽度\n" + "6. 当数据点超过5个时,x轴采用以下优化策略\n" +
" a) 使用config配置xyChart中的width调整适当宽度\n" +
" b) 调整xAxis的labelFontSize字体大小\n" +
"注意不要照搬例子宽度!需要自行思考配置,例子如下:\n" +
"---\n" +
"config:\n" +
" xyChart:\n" +
" width: 1950\n" +
" height: 600\n" +
" xAxis:\n" +
" labelFontSize: 8\n" +
"---\n" +
"xychart-beta\n" +
"......" +
"\n" + "\n" +
"**输出要求**:\n" + "**输出要求**:\n" +
"- 仅返回可直接用于Markdown的Mermaid配置\n" + "- 仅返回可直接用于Markdown的Mermaid配置\n" +
...@@ -96,7 +110,7 @@ public class ChartGenerateFunction extends AbstractLargeModelFunction { ...@@ -96,7 +110,7 @@ public class ChartGenerateFunction extends AbstractLargeModelFunction {
" x-axis \"请求类型\" [\"技术问题\", \"账单问题\", \"其他\"]\n" + " x-axis \"请求类型\" [\"技术问题\", \"账单问题\", \"其他\"]\n" +
" y-axis \"处理时间\" 0-->10\n" + " y-axis \"处理时间\" 0-->10\n" +
" bar [2, 8, 0.5]```\n" + " bar [2, 8, 0.5]```\n" +
"```" + "```\n" +
"\n" + "\n" +
"**示例2**\n" + "**示例2**\n" +
"问题: 帮我将一下数据生成折线图\n" + "问题: 帮我将一下数据生成折线图\n" +
...@@ -105,11 +119,19 @@ public class ChartGenerateFunction extends AbstractLargeModelFunction { ...@@ -105,11 +119,19 @@ public class ChartGenerateFunction extends AbstractLargeModelFunction {
"图形类型 :折线图\n" + "图形类型 :折线图\n" +
"输出:\n" + "输出:\n" +
"```mermaid\n" + "```mermaid\n" +
"---\n" +
"config:\n" +
" xyChart:\n" +
" width: 1950\n" +
" height: 600\n" +
" xAxis:\n" +
" labelFontSize: 11\n" +
"---\n" +
"xychart-beta\n" + "xychart-beta\n" +
" title \"购房款项支付情况\"\n" + " title \"购房款项支付情况\"\n" +
" x-axis \"日期\" [\"2022-03-15\", \"2022-04-01\", \"2022-04-20\", \"2022-05-05\", \"2022-10-01\", \"2022-11-01\"]\n" + " x-axis \"日期\" [\"2022-03-15\", \"2022-04-01\", \"2022-04-20\", \"2022-05-05\", \"2022-10-01\", \"2022-11-01\"]\n" +
" y-axis \"金额(元)\" 0-->3000000\n" + " y-axis \"金额(元)\" 0-->3000000\n" +
" line [500000, 1500000, 500000, 1500000, 2450000, 2550000]" + " line [500000, 1500000, 500000, 1500000, 2450000, 2550000]\n" +
"```"; "```";
@Override @Override
......
...@@ -49,9 +49,8 @@ public class ChartGenerateFunctionTest { ...@@ -49,9 +49,8 @@ public class ChartGenerateFunctionTest {
"1. 图表标题应准确反映数据主题\n" + "1. 图表标题应准确反映数据主题\n" +
"2. 使用与数据类型匹配的图表子类型(如堆积柱状图、面积折线图等)\n" + "2. 使用与数据类型匹配的图表子类型(如堆积柱状图、面积折线图等)\n" +
"3. 坐标轴需要包含单位说明\n" + "3. 坐标轴需要包含单位说明\n" +
"4. 使用最简单的方式生成,不要样式\n" + "4. 注意样式,如x轴内容过多时适当调整x轴宽度\n" +
"5. 实际使用中用户的数据和要求不同,不能直接使用例子进行输出,要按照用户要求的图表进行\n" + "5. 实际使用中用户的数据和要求不同,不能直接使用例子进行输出,要按照用户要求的图表进行\n" +
"6. 注意样式,如x轴内容过多时适当调整x轴宽度\n" +
"\n" + "\n" +
"**输出要求**:\n" + "**输出要求**:\n" +
"- 仅返回可直接用于Markdown的Mermaid配置\n" + "- 仅返回可直接用于Markdown的Mermaid配置\n" +
...@@ -98,13 +97,11 @@ public class ChartGenerateFunctionTest { ...@@ -98,13 +97,11 @@ public class ChartGenerateFunctionTest {
@Test @Test
public void test_doFunction() { public void test_doFunction() {
// String json = "{\"chart_type\": \"折线图\", \"data\": \"2022-03-15 500000.00 定金 银行转账 YXSK20220315001 1 购房定金 2022-04-01 1500000.00 首付 银行转账 YXSK20220401001 1 首付款30% 2022-10-01 2450000.00 尾款 银行转账 YXSK20221001001 1 银行按揭放款 2022-04-20 500000.00 定金 银行转账 YXSK20220420001 2 购房定金 2022-05-05 1500000.00 首付 银行转账 YXSK20220505001 2 首付款30% 2022-11-01 2550000.00 尾款 银行转账 YXSK20221101001 2 银行按揭放款\", \"question\": \"帮我将一下数据生成折线图\", \"theme\": \"购房款项支付情况\"}'}";
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("question", "帮我将一下数据生成折线图"); jsonObject.put("question", "查询销售数据,并生成折线图");
jsonObject.put("chart_type", "折线图"); jsonObject.put("chart_type", "折线图");
jsonObject.put("theme", "购房款项支付情况"); jsonObject.put("theme", "销售数据");
jsonObject.put("data", "2022-03-15 500000.00 定金 银行转账 YXSK20220315001 1 购房定金 2022-04-01 1500000.00 首付 银行转账 YXSK20220401001 1 首付款30% 2022-10-01 2450000.00 尾款 银行转账 YXSK20221001001 1 银行按揭放款 2022-04-20 500000.00 定金 银行转账 YXSK20220420001 2 购房定金 2022-05-05 1500000.00 首付 银行转账 YXSK20220505001 2 首付款30% 2022-11-01 2550000.00 尾款 银行转账 YXSK20221101001 2 银行按揭放款"); jsonObject.put("data", "[(datetime.date(2022, 3, 15), Decimal('4450000.00')), (datetime.date(2022, 4, 20), Decimal('4550000.00')), (datetime.date(2022, 5, 10), Decimal('5950000.00')), (datetime.date(2022, 6, 5), Decimal('6050000.00')), (datetime.date(2022, 7, 18), Decimal('3450000.00')), (datetime.date(2022, 8, 22), Decimal('4750000.00')), (datetime.date(2022, 9, 15), Decimal('4850000.00')), (datetime.date(2022, 10, 10), Decimal('6750000.00')), (datetime.date(2022, 11, 5), Decimal('3950000.00')), (datetime.date(2021, 5, 15), Decimal('4950000.00')), (datetime.date(2021, 6, 20), Decimal('4950000.00')), (datetime.date(2021, 7, 10), Decimal('5050000.00')), (datetime.date(2021, 8, 5), Decimal('5050000.00')), (datetime.date(2021, 9, 18), Decimal('5150000.00')), (datetime.date(2021, 10, 22), Decimal('6950000.00')), (datetime.date(2021, 11, 15), Decimal('7050000.00')), (datetime.date(2021, 12, 10), Decimal('7150000.00')), (datetime.date(2022, 1, 5), Decimal('8400000.00')), (datetime.date(2022, 2, 18), Decimal('8500000.00')), (datetime.date(2022, 9, 15), Decimal('4550000.00')), (datetime.date(2022, 10, 10), Decimal('4650000.00')), (datetime.date(2022, 11, 5), Decimal('6350000.00')), (datetime.date(2022, 12, 20), Decimal('3350000.00')), (datetime.date(2023, 1, 15), Decimal('4450000.00')), (datetime.date(2023, 2, 10), Decimal('4550000.00')), (datetime.date(2023, 3, 5), Decimal('4650000.00')), (datetime.date(2023, 4, 20), Decimal('6150000.00')), (datetime.date(2023, 6, 10), Decimal('4750000.00')), (datetime.date(2023, 7, 5), Decimal('4850000.00')), (datetime.date(2023, 8, 20), Decimal('4950000.00')), (datetime.date(2023, 9, 15), Decimal('6850000.00')), (datetime.date(2023, 10, 10), Decimal('6950000.00')), (datetime.date(2023, 11, 5), Decimal('4050000.00')), (datetime.date(2023, 12, 20), Decimal('5400000.00')), (datetime.date(2024, 1, 15), Decimal('5400000.00')), (datetime.date(2024, 2, 10), Decimal('5500000.00')), (datetime.date(2024, 3, 5), Decimal('5500000.00')), (datetime.date(2024, 4, 20), Decimal('5600000.00')), (datetime.date(2024, 5, 15), Decimal('4650000.00')), (datetime.date(2024, 6, 10), Decimal('4750000.00')), (datetime.date(2024, 7, 5), Decimal('6350000.00')), (datetime.date(2024, 8, 20), Decimal('6450000.00')), (datetime.date(2024, 9, 15), Decimal('6550000.00')), (datetime.date(2024, 10, 10), Decimal('3450000.00'))]");
String content = jsonObject.toJSONString(); String content = jsonObject.toJSONString();
String identifier = "test_function"; String identifier = "test_function";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment