fix:指标别名、维度别名、维度值别名智能填充添加标准回答示例,对大模型返回结果添加后处理,使用String.valueOf解决维度值为数… (#1431)

* fix:指标别名、维度别名、维度值别名智能填充添加标准回答示例,对大模型返回结果添加后处理,使用String.valueOf解决维度值为数值时无法维度值智能填充的问题

* fix:解决checkstyle错误

---------

Co-authored-by: sunhan
This commit is contained in:
S-robot-98
2024-07-22 22:46:14 +08:00
committed by GitHub
parent 73d9cbdbc1
commit f03e5a0d38
3 changed files with 30 additions and 13 deletions

View File

@@ -362,7 +362,8 @@ public class DimensionServiceImpl extends ServiceImpl<DimensionDOMapper, Dimensi
public List<String> mockAlias(DimensionReq dimensionReq, String mockType, User user) { public List<String> mockAlias(DimensionReq dimensionReq, String mockType, User user) {
String mockAlias = aliasGenerateHelper.generateAlias(mockType, dimensionReq.getName(), String mockAlias = aliasGenerateHelper.generateAlias(mockType, dimensionReq.getName(),
dimensionReq.getBizName(), "", dimensionReq.getDescription(), false); dimensionReq.getBizName(), "", dimensionReq.getDescription(), false);
return JSONObject.parseObject(mockAlias, new TypeReference<List<String>>() { String ret = mockAlias.replaceAll("`", "").replace("json", "").replace("\n", "").replace(" ", "");
return JSONObject.parseObject(ret, new TypeReference<List<String>>() {
}); });
} }
@@ -380,13 +381,13 @@ public class DimensionServiceImpl extends ServiceImpl<DimensionDOMapper, Dimensi
List<Map<String, Object>> resultList = semanticQueryResp.getResultList(); List<Map<String, Object>> resultList = semanticQueryResp.getResultList();
List<String> valueList = new ArrayList<>(); List<String> valueList = new ArrayList<>();
for (Map<String, Object> stringObjectMap : resultList) { for (Map<String, Object> stringObjectMap : resultList) {
String value = (String) stringObjectMap.get(dimensionReq.getBizName()); String value = String.valueOf(stringObjectMap.get(dimensionReq.getBizName()));
valueList.add(value); valueList.add(value);
} }
String json = aliasGenerateHelper.generateDimensionValueAlias(JSON.toJSONString(valueList)); String json = aliasGenerateHelper.generateDimensionValueAlias(JSON.toJSONString(valueList));
log.info("return llm res is :{}", json); log.info("return llm res is :{}", json);
String ret = json.replaceAll("`", "").replace("json", "").replace("\n", "").replace(" ", "");
JSONObject jsonObject = JSON.parseObject(json); JSONObject jsonObject = JSON.parseObject(ret);
List<DimValueMap> dimValueMapsResp = new ArrayList<>(); List<DimValueMap> dimValueMapsResp = new ArrayList<>();
int i = 0; int i = 0;

View File

@@ -553,7 +553,8 @@ public class MetricServiceImpl extends ServiceImpl<MetricDOMapper, MetricDO>
String mockAlias = aliasGenerateHelper.generateAlias(mockType, metricReq.getName(), metricReq.getBizName(), "", String mockAlias = aliasGenerateHelper.generateAlias(mockType, metricReq.getName(), metricReq.getBizName(), "",
metricReq.getDescription(), !"".equals(metricReq.getDataFormatType())); metricReq.getDescription(), !"".equals(metricReq.getDataFormatType()));
return JSONObject.parseObject(mockAlias, new TypeReference<List<String>>() { String ret = mockAlias.replaceAll("`", "").replace("json", "").replace("\n", "").replace(" ", "");
return JSONObject.parseObject(ret, new TypeReference<List<String>>() {
}); });
} }

View File

@@ -61,6 +61,14 @@ public class AliasGenerateHelper {
+ "},\n" + "},\n"
+ "\"additionalProperties\":false}\n" + "\"additionalProperties\":false}\n"
+ "Please double-check whether the answer conforms to the format described in the JSON-schema.\n" + "Please double-check whether the answer conforms to the format described in the JSON-schema.\n"
+ "回答格式示例:"
+ "[\n"
+ " \"人数\",\n"
+ " \"员工人数\",\n"
+ " \"员工数量\",\n"
+ " \"员工总数\"\n"
+ "]\n"
+ "请严格按照示例格式进行生成。"
+ "ANSWER JSON:"; + "ANSWER JSON:";
log.info("msg:{}", msg); log.info("msg:{}", msg);
return getChatCompletion(msg); return getChatCompletion(msg);
@@ -68,15 +76,22 @@ public class AliasGenerateHelper {
public String generateDimensionValueAlias(String json) { public String generateDimensionValueAlias(String json) {
String msg = "Assuming you are a professional data analyst specializing in indicators,for you a json list" String msg = "Assuming you are a professional data analyst specializing in indicators,for you a json list"
+ "the required content to follow is as follows: " + "the required content to follow is as follows: \n"
+ "1. The format of JSON," + "1. The format of JSON,\n"
+ "2. Only return in JSON format," + "2. Only return in JSON format,\n"
+ "3. the array item > 1 and < 5,more alias," + "3. the array item > 1 and < 5,more alias,\n"
+ "for exampleinput:[\"qq_music\",\"kugou_music\"]," + "for example\n"
+ "out:{\"tran\":[\"qq音乐\",\"酷狗音乐\"],\"alias\":{\"qq_music\":[\"q音\",\"qq音乐\"]," + "input:[\"qq_music\",\"kugou_music\"],\n"
+ "\"kugou_music\":[\"kugou\",\"酷狗\"]}}," + "out:{\"tran\":[\"qq音乐\",\"酷狗音乐\"],"
+ "\"alias\":{\"qq_music\":[\"q音\",\"qq音乐\"],\"kugou_music\":[\"kugou\",\"酷狗\"]}},\n"
+ "input:[\"qq_music\",\"kugou_music\"],\n"
+ "out:{\"tran\":[\"qq音乐\",\"酷狗音乐\"],"
+ "\"alias\":{\"qq_music\":[\"q音\",\"qq音乐\"],\"kugou_music\":[\"kugou\",\"酷狗\"]}},\n"
+ "input:[\"大专\",\"本科\",\"硕士研究生\"],\n"
+ "out:{\"tran\":[\"大专\",\"本科\",\"硕士研究生\"],"
+ "\"alias\":{\"大专\":[\"专科\",\"大学专科\"],\"本科\":[\"学士\",\"本科生\"],\"硕士研究生\":[\"硕士\",\"研究生\"]}},\n"
+ "now input: " + "now input: "
+ json + "," + json + ",\n"
+ "answer json:"; + "answer json:";
log.info("msg:{}", msg); log.info("msg:{}", msg);
return getChatCompletion(msg); return getChatCompletion(msg);