RunRealTestMain.java
13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
//package com.glsk.llm;
//
//import com.alibaba.dashscope.exception.InputRequiredException;
//import com.alibaba.dashscope.exception.NoApiKeyException;
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.glsk.conf.ConfigurationManager;
//import com.glsk.connection.MysqlConn;
//import com.glsk.llm.impl.LLMToolFactory;
//import com.glsk.llm.impl.LLMTools;
//import com.glsk.llm.model.LLMRequest;
//import org.apache.poi.xssf.usermodel.XSSFCell;
//import org.apache.poi.xssf.usermodel.XSSFRow;
//import org.apache.poi.xssf.usermodel.XSSFSheet;
//import org.apache.poi.xssf.usermodel.XSSFWorkbook;
//
//import java.io.*;
//import java.sql.Connection;
//import java.util.*;
//import java.util.stream.Collectors;
//
///**
// * 跑线上测试用例
// */
//public class RunRealTestMain {
// public static void main(String[] args) throws IOException, NoApiKeyException, InputRequiredException {
// long bgnTime = System.currentTimeMillis();
//
// // 配置提示词版本及模型类型(1-智普 2-千问 3-豆包 4-百度)
// String version = "(250513-qwen-plus)";
// Integer modeType = 2;
//// String modeName = "qwen2.5-72b-instruct";
//// String modeName = "qwen2-72b-instruct";
// String modeName = "qwen-plus";
//// String modeName = "qwen-plus-0806";
//
// // data_new/data_tianwu
// String dataType = "data_tianwu";
//// String dataType = "data_new";
//
// Connection myConn = MysqlConn.getConnection(ConfigurationManager.getProperty("mysql.url"));
// Map<String, String> nameMap = getNameMap();
//
// // ruleCode -> rule
// String query = "select rule_code,sub_rule,rule_score,main_rule_code from llm_rule where status = 1;";
// ArrayList<ArrayList<String>> ery = MysqlConn.executeQuery(myConn, query, 4);
//
// Map<String, Double> codeScoreMap = new HashMap<>();
// Map<String, String> nameCodeMap = new HashMap<>();
// Map<String, String> codeMainCodeMap = new HashMap<>();
//
// Map<String, Double> mainCodeScoreMap = new HashMap<>();
//
// for (ArrayList<String> e : ery) {
// String[] codes = e.get(0).split("\\;");
// for (String code : codes) {
// codeScoreMap.put(code, Double.valueOf(e.get(2)));
// codeMainCodeMap.put(code,e.get(3));
// }
//
// nameCodeMap.put(e.get(1), e.get(3));
// mainCodeScoreMap.put(e.get(3), Double.valueOf(e.get(2)));
// }
//
//
// // 获取system prompt
//// String sql = "select system_prompt,user_prompt from llm_prompt where type_id = 5 and status = 1";
// String sql = "select system_prompt,user_prompt from llm_prompt where type_id = 1 and status = 1";
// ArrayList<ArrayList<String>> executeQuery = MysqlConn.executeQuery(myConn, sql, 2);
//
// String systemPrompt = executeQuery.get(0).get(0);
//// String userPrompt = executeQuery.get(0).get(1).replaceAll("\r", "");
// String userPrompt = executeQuery.get(0).get(1);
//
// // 获取用例
// List<String> contentList = new ArrayList<>();
//// InputStream in = new FileInputStream("F:\\AI技术研究\\话术质检模型测试用例.xlsx");
// InputStream in = new FileInputStream("F:\\AI技术研究\\用例及提示词优化记录\\话术质检模型测试用例合集.xlsx");
// XSSFWorkbook sheets = new XSSFWorkbook(in);
//// String sheetName = "实际话术样本预期结果汇总";
// String sheetName = "实际话术样本预期结果汇总【0505规则版】";
//
// XSSFSheet sheet = sheets.getSheet(sheetName);
// int rows = sheet.getPhysicalNumberOfRows();
//
// BufferedWriter totalWriter = new BufferedWriter(new FileWriter(new File("return_real" + File.separator + "总览" + version)));
//
//
// BufferedWriter writer = new BufferedWriter(new FileWriter(new File("return_real" + File.separator + "用例分析" + version + ".csv")));
//// List<String> codeList = codeScoreMap.keySet().stream().sorted().collect(Collectors.toList());
// List<String> codeList = codeMainCodeMap.values().stream().distinct().sorted().collect(Collectors.toList());
//
// String header = "用例,";
// for (String code : codeList) {
// header += code+"_art," + code+"_llm," + code+"_diff,";
// }
// writer.write(header+"成交/战败情况\n");
// writer.flush();
//
// List<String> exampleDetails = new ArrayList<>();
//// List<Integer> idList = new ArrayList<>();
//// idList.add(11);
//// idList.add(15);
//// idList.add(19);
//// idList.add(20);
//// idList.add(22);
//// idList.add(23);
//// idList.add(30);
//// idList.add(31);
//// idList.add(32);
//// idList.add(33);
//
//// for (int i : idList) {
// for (int i = 11; i < 41; i++) {
//// for (int i = 1; i < rows; i++) {
//// int i = 24;
//
//
// XSSFRow row = sheet.getRow(i);
//
// XSSFCell cell = row.getCell(0);
// String caseNo = cell.getStringCellValue();
// System.out.println("开始用例" + caseNo + "....");
//
//// if (1 == 1) continue;
//
//
// // dataNo多少
// cell = row.getCell(1);
// String dataNo = cell.getStringCellValue();
//
// BufferedReader reader = new BufferedReader(new FileReader(new File(dataType+ File.separator + dataNo + "_" + caseNo + ".txt")));
//// BufferedReader reader = new BufferedReader(new FileReader(new File("data_new" + File.separator + dataNo + "_" + caseNo + ".txt")));
// StringBuffer buffer = new StringBuffer();
// String line = null;
// while ((line = reader.readLine()) != null) {
// buffer.append(line).append("\n");
// }
//
// // 成交或战败
// cell = row.getCell(2);
// String realTrade = cell.getStringCellValue();
//
//
// cell = row.getCell(3);
// double maxScore = cell.getNumericCellValue();
//
// // 预期得分
// TreeMap<String, Double> expectedMap = new TreeMap<>();
// for (int k=5; k < 95; k++) {
//// System.out.println(row.getCell(k).getStringCellValue() + ":" + row.getCell(k+2).getNumericCellValue());
// expectedMap.put(nameCodeMap.get(nameMap.get(row.getCell(k).getStringCellValue())), row.getCell(k+2).getNumericCellValue());
// k += 3;
// }
//
// // 实际得分
// HashMap<String, Double> actualMap = new HashMap<>();
//
// LLMTools llmTool = LLMToolFactory.createLLMTool(modeType).init("");
// LLMRequest req = new LLMRequest();
// req.setSystem(systemPrompt);
// req.setUser(userPrompt);
// req.setContent(buffer.toString());
// req.setModeName(modeName);
// String retContent = llmTool.lauchLLM(req);
//
// String detail = FormatUtil.extractJsonData(retContent);
// detail = FormatUtil.formatStandard(detail);
// System.out.println("格式化返回:\n" + detail);
//
// JSONObject object = JSON.parseObject(detail);
// JSONArray scores = object.getJSONArray("scores");
// List<JSONObject> jsonObjects = JSON.parseArray(scores.toJSONString(), JSONObject.class);
//
// JSONObject summary = object.getJSONObject("summary");
// String trade = summary.getString("trade");
//
//
// // 模型总分
// double llmTotalScore = 0;
// // 人工总分
// double artTotalScore = 0;
// HashMap<String, Boolean> ruleObjMap = new HashMap<>();
// for (JSONObject obj : jsonObjects) {
// if (obj.getBooleanValue("match") == false) continue;
//
// String[] ruleCodes = obj.getString("rule").split("\\;");
// for (String code : ruleCodes) {
// ruleObjMap.put(codeMainCodeMap.get(code), obj.getBooleanValue("match"));
// llmTotalScore += codeScoreMap.get(code);
// }
// }
//
//
// // 不匹配选项
// List<String> notMathList = new ArrayList<>();
// // 不匹配分值
// double difSumScore = 0;
//
// StringBuffer exampleBuff = new StringBuffer();
// Set<Map.Entry<String, Double>> entries = expectedMap.entrySet();
// for (Map.Entry<String, Double> entry :entries) {
// String ruleCode = entry.getKey();
// Double artValue = entry.getValue();
//
// // 人工评分
// artTotalScore += artValue;
//
// Boolean match = ruleObjMap.get(ruleCode);
// if (((match == null || match.booleanValue() == false ) && artValue == 0)) {
//// System.out.println(ruleCode + "匹配");
// } else if (((match == null || match.booleanValue() == false ) && artValue > 0)) {
//// System.out.println(ruleCode + "不匹配");
// notMathList.add(ruleCode);
// difSumScore += mainCodeScoreMap.get(ruleCode);
// } else if (match.booleanValue() == true && artValue > 0) {
//// System.out.println(ruleCode + "匹配");
// } else {
//// System.out.println(ruleCode + "不匹配");
// notMathList.add(ruleCode);
// difSumScore += mainCodeScoreMap.get(ruleCode);
// }
//
// // 结果对比输出
// Boolean artResult = artValue>0 ? true:false;
// Boolean llmResult = match == null ? false : match.booleanValue()==true?true:false;
// exampleBuff.append(String.format("%s,%s,%s,", artResult, llmResult, artResult.booleanValue()==llmResult.booleanValue()?"匹配":"不匹配"));
// }
//
// if (trade.equals("战败"))
// trade = "战败";
// else if(trade.equals("未知"))
// trade = "不确定";
//
// String tradeStr = "";
// if (realTrade.equals(trade)) {
// tradeStr = "匹配";
// } else {
// tradeStr = "不匹配(人工:" + realTrade + ";质检:" + trade + ")";
// }
//
// exampleBuff.append(tradeStr);
// exampleBuff.append("\n");
// writer.write(dataNo + "," + exampleBuff.toString());
// writer.flush();
//
// System.out.println(String.format("%s不匹配选项:%s,不匹配分值累计:%f,成交(战败)情况:%s,模型总分:%f,人工总分:%f,总分差异:%f", caseNo, notMathList.toString(), difSumScore,tradeStr,llmTotalScore,artTotalScore,Math.abs(llmTotalScore-artTotalScore)));
// totalWriter.write(String.format("%s不匹配选项:%s,不匹配分值累计:%f,成交(战败)情况:%s,模型总分:%f,人工总分:%f,总分差异:%f\n", caseNo, notMathList.toString(), difSumScore,tradeStr, llmTotalScore,artTotalScore,Math.abs(llmTotalScore-artTotalScore)));
// totalWriter.flush();
// }
//
// totalWriter.close();
// writer.close();
//
// System.out.println("本次任务运行耗时:" + (System.currentTimeMillis()-bgnTime)/1000 + "秒");
// }
//
// private static Map<String, String> getNameMap() {
// Map<String, String> nameMap = new HashMap<>();
// nameMap.put("尊称敬语", "尊称");
// nameMap.put("自我介绍_名字", "介绍姓名");
// nameMap.put("自我介绍_职务", "职务介绍");
// nameMap.put("讲解大纲", "讲解大纲");
// nameMap.put("恭喜车主", "恭喜车主");
// nameMap.put("新车使用注意事项-时速", "油门、车速、120、加速、电瓶");
// nameMap.put("新车使用注意事项-空调", "空调");
// nameMap.put("新车使用注意事项-充电", "充电");
// nameMap.put("新车使用注意事项-方向盘", "方向盘");
// nameMap.put("新车使用注意事项-暴力驾驶", "急加速、太快、暴力驾驶");
// nameMap.put("保养事项-首保", "首保");
// nameMap.put("保养事项-基础保养", "基础保养");
// nameMap.put("保养事项-四年中保", "四年中保");
// nameMap.put("保修质保-整车质保", "整车质保");
// nameMap.put("保修质保-三电", "三电");
// nameMap.put("保修质保-易损件", "易损、损耗");
// nameMap.put("保修质保-保修", "保修、免费换新");
// nameMap.put("延保升级_提及延保", "提及延保");
// nameMap.put("延保介绍_延保年限和里程", "延保年限和里程");
// nameMap.put("延保升级_延保的补贴政策", "延保的补贴政策");
// nameMap.put("延保介绍_延保节省的费用", "延保节省的费用");
// nameMap.put("延保结论", "延保结论");
// nameMap.put("转介客户", "转介客户");
//
//
// return nameMap;
// }
//}