|
|
|
@ -588,7 +588,7 @@ public class AliOcrUtil { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 处理数据 |
|
|
|
* 图像识别处理数据 |
|
|
|
* |
|
|
|
* @param productService |
|
|
|
* @param orderId |
|
|
|
@ -818,7 +818,7 @@ public class AliOcrUtil { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* AI开单 |
|
|
|
* 语音-AI开单 |
|
|
|
* |
|
|
|
* @param questionMsg |
|
|
|
* @return JSONObject |
|
|
|
@ -918,23 +918,6 @@ public class AliOcrUtil { |
|
|
|
return jsonObject; |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
String aa = "请帮我把所有内容封装为JSON,json格式为:[{ \"productSn\": \"货号\", \"productName\": \"名称\" , \"attributeList\": [{\"color\":\"颜色\",\"size\":\"尺码\",\"productCount\": \"数量\"}], \"price\":\"单价\" }],\n" + |
|
|
|
"1.如果没有识别到\"price\"的内容,则\"price\"赋值\"0\",\n" + |
|
|
|
"2.如果没有识别到\"color\"的内容,则\"color\"赋值“均色”,\n" + |
|
|
|
"3.如果没有识别到\"size\"的内容,则\"size\"赋值“均码”,\n" + |
|
|
|
"4.如果没有识别到\"productName\"的内容,则\"productName\"使用\"productSn\"的值填充。\n" + |
|
|
|
"5.如果没有识别到\"productSn\"的内容,则\"productSn\"赋值\"\",\n" + |
|
|
|
"6.只输出JSON数据即可,不用返回字段描述。"; |
|
|
|
String bb = "请帮我把所有内容封装为JSON,json格式为:[{ \"productSn\": \"货号\", \"attributeList\": [{\"color\":\"颜色\",\"size\":\"尺码\",\"productCount\": \"数量\"}] }],\n" + |
|
|
|
"1.productSn的返回值中去掉颜色,尺码等信息,\n" + |
|
|
|
"2.如果指令内容中有\"SYYS色\"则\"color\"字段返回“SYYS色”,\n" + |
|
|
|
"3.如果指令内容中有\"SYCM码\"则\"size\"字段返回“SYCM码”,\n" + |
|
|
|
"4.如果没有识别到\"color\"的内容,则\"color\"赋值“均色”。如果没有识别到\"size\"的内容,则\"size\"赋值“均码”,\n" + |
|
|
|
"5.只输出JSON数据即可,不用返回字段描述。"; |
|
|
|
|
|
|
|
System.out.println(aa+"\n"+bb); |
|
|
|
} |
|
|
|
public static JSONObject callWithMessageSync(String questionMsg, String saleId, String shopId, String createBy, ProductService productService, ProductCategoryService productCategoryService, SaleService saleService, SaleDetailService saleDetailService) |
|
|
|
throws NoApiKeyException, ApiException, InputRequiredException { |
|
|
|
final JSONObject jsonObject = new JSONObject(); |
|
|
|
@ -1212,4 +1195,45 @@ public class AliOcrUtil { |
|
|
|
sale.setAiNotRecognition(newAiNotRecognition); |
|
|
|
saleService.saveOrUpdate(sale); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 语音-物流开单 |
|
|
|
* |
|
|
|
* @param questionMsg |
|
|
|
* @return JSONObject |
|
|
|
* @author 王富康 |
|
|
|
* @date 2024/3/31 |
|
|
|
*/ |
|
|
|
public static JSONObject callWithMessageOfLogistics (String questionMsg) |
|
|
|
throws NoApiKeyException, ApiException, InputRequiredException { |
|
|
|
final JSONObject jsonObject = new JSONObject(); |
|
|
|
Constants.apiKey = "sk-bcfa4865b89548acb8225f910f13d682"; |
|
|
|
final StopWatch stopWatch = new StopWatch("Ai回答计时"); |
|
|
|
final Generation gen = new Generation(); |
|
|
|
final MessageManager msgManager = new MessageManager(10); |
|
|
|
final Message systemMsg = |
|
|
|
Message.builder().role(Role.SYSTEM.getValue()).content("You are a helpful assistant.").build(); |
|
|
|
questionMsg += "请帮我把所有内容封装为JSON,json格式为:[{ \"senderName\": \"发货人\", \"senderPhone\": \"发货人电话\" , \"receiverName\": \"收货人\", \"receiverPhone\": \"收货人电话\" , \"arrivalStation\":\"\"到达站,\"weight\":\"重量\",\"count\":\"件数\",\"methodOfSettlement\":\"结算方式\",\"tips\":\"小费\" }]。没有识别到的信息JSON字段返回\"\"。"; |
|
|
|
final Message userMsg = Message.builder().role(Role.USER.getValue()).content(questionMsg).build(); |
|
|
|
msgManager.add(systemMsg); |
|
|
|
msgManager.add(userMsg); |
|
|
|
stopWatch.start("开始回答"); |
|
|
|
final QwenParam param = |
|
|
|
QwenParam.builder().model("qwen2-72b-instruct").messages(msgManager.get()) |
|
|
|
.resultFormat(QwenParam.ResultFormat.MESSAGE) |
|
|
|
.build(); |
|
|
|
final GenerationResult result = gen.call(param); |
|
|
|
log.info(result.toString()); |
|
|
|
// 解析结果
|
|
|
|
final String text = result.getOutput().getChoices().get(0).getMessage().getContent(); |
|
|
|
// 根据{}截取数据
|
|
|
|
final int startIndex = text.indexOf('{'); |
|
|
|
final int endIndex = text.lastIndexOf('}'); |
|
|
|
final String jsonStr = '[' + text.substring(startIndex, endIndex + 1) + ']'; |
|
|
|
stopWatch.stop(); |
|
|
|
log.info(stopWatch.prettyPrint()); |
|
|
|
jsonObject.put("resultContent", jsonStr); |
|
|
|
jsonObject.put("msg", result.getOutput().getChoices().get(0).getMessage().getContent()); |
|
|
|
return jsonObject; |
|
|
|
} |
|
|
|
} |