mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
fix:指标别名、维度别名、维度值别名智能填充添加标准回答示例,对大模型返回结果添加后处理,使用String.valueOf解决维度值为数… (#1431)
* fix:指标别名、维度别名、维度值别名智能填充添加标准回答示例,对大模型返回结果添加后处理,使用String.valueOf解决维度值为数值时无法维度值智能填充的问题 * fix:解决checkstyle错误 --------- Co-authored-by: sunhan
This commit is contained in:
@@ -362,7 +362,8 @@ public class DimensionServiceImpl extends ServiceImpl<DimensionDOMapper, Dimensi
|
||||
public List<String> mockAlias(DimensionReq dimensionReq, String mockType, User user) {
|
||||
String mockAlias = aliasGenerateHelper.generateAlias(mockType, dimensionReq.getName(),
|
||||
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<String> valueList = new ArrayList<>();
|
||||
for (Map<String, Object> stringObjectMap : resultList) {
|
||||
String value = (String) stringObjectMap.get(dimensionReq.getBizName());
|
||||
String value = String.valueOf(stringObjectMap.get(dimensionReq.getBizName()));
|
||||
valueList.add(value);
|
||||
}
|
||||
String json = aliasGenerateHelper.generateDimensionValueAlias(JSON.toJSONString(valueList));
|
||||
log.info("return llm res is :{}", json);
|
||||
|
||||
JSONObject jsonObject = JSON.parseObject(json);
|
||||
String ret = json.replaceAll("`", "").replace("json", "").replace("\n", "").replace(" ", "");
|
||||
JSONObject jsonObject = JSON.parseObject(ret);
|
||||
|
||||
List<DimValueMap> dimValueMapsResp = new ArrayList<>();
|
||||
int i = 0;
|
||||
|
||||
@@ -553,7 +553,8 @@ public class MetricServiceImpl extends ServiceImpl<MetricDOMapper, MetricDO>
|
||||
|
||||
String mockAlias = aliasGenerateHelper.generateAlias(mockType, metricReq.getName(), metricReq.getBizName(), "",
|
||||
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>>() {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,14 @@ public class AliasGenerateHelper {
|
||||
+ "},\n"
|
||||
+ "\"additionalProperties\":false}\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:";
|
||||
log.info("msg:{}", msg);
|
||||
return getChatCompletion(msg);
|
||||
@@ -68,15 +76,22 @@ public class AliasGenerateHelper {
|
||||
|
||||
public String generateDimensionValueAlias(String json) {
|
||||
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: "
|
||||
+ "1. The format of JSON,"
|
||||
+ "2. Only return in JSON format,"
|
||||
+ "3. the array item > 1 and < 5,more alias,"
|
||||
+ "for example:input:[\"qq_music\",\"kugou_music\"],"
|
||||
+ "out:{\"tran\":[\"qq音乐\",\"酷狗音乐\"],\"alias\":{\"qq_music\":[\"q音\",\"qq音乐\"],"
|
||||
+ "\"kugou_music\":[\"kugou\",\"酷狗\"]}},"
|
||||
+ "the required content to follow is as follows: \n"
|
||||
+ "1. The format of JSON,\n"
|
||||
+ "2. Only return in JSON format,\n"
|
||||
+ "3. the array item > 1 and < 5,more alias,\n"
|
||||
+ "for example:\n"
|
||||
+ "input:[\"qq_music\",\"kugou_music\"],\n"
|
||||
+ "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: "
|
||||
+ json + ","
|
||||
+ json + ",\n"
|
||||
+ "answer json:";
|
||||
log.info("msg:{}", msg);
|
||||
return getChatCompletion(msg);
|
||||
|
||||
Reference in New Issue
Block a user