|
|
@ -61,6 +61,7 @@ public class AliOcrUtil { |
|
|
*/ |
|
|
*/ |
|
|
public static JSONObject multiRoundConversationCall(PurchaseOcrPicture purchaseOcrPicture, PurchaseOcrExample purchaseOcrExample, ProductService productService, PurchaseDetailService purchaseDetailService) throws ApiException, NoApiKeyException, UploadFileException { |
|
|
public static JSONObject multiRoundConversationCall(PurchaseOcrPicture purchaseOcrPicture, PurchaseOcrExample purchaseOcrExample, ProductService productService, PurchaseDetailService purchaseDetailService) throws ApiException, NoApiKeyException, UploadFileException { |
|
|
final JSONObject jsonObject = new JSONObject(); |
|
|
final JSONObject jsonObject = new JSONObject(); |
|
|
|
|
|
final String ocrPictureId = purchaseOcrPicture.getId(); |
|
|
final String picturePath = purchaseOcrPicture.getOcrPicture(); |
|
|
final String picturePath = purchaseOcrPicture.getOcrPicture(); |
|
|
final Integer count = purchaseOcrPicture.getCount(); |
|
|
final Integer count = purchaseOcrPicture.getCount(); |
|
|
final String orderId = purchaseOcrPicture.getOrderId(); |
|
|
final String orderId = purchaseOcrPicture.getOrderId(); |
|
|
@ -76,7 +77,7 @@ public class AliOcrUtil { |
|
|
productSnExample += indexStr; |
|
|
productSnExample += indexStr; |
|
|
productNameExample += indexStr; |
|
|
productNameExample += indexStr; |
|
|
} |
|
|
} |
|
|
final StopWatch stopWatch = new StopWatch("Ai回答计时"); |
|
|
final StopWatch stopWatch = new StopWatch(ocrPictureId+"Ai回答计时"); |
|
|
Constants.apiKey = "sk-bcfa4865b89548acb8225f910f13d682"; |
|
|
Constants.apiKey = "sk-bcfa4865b89548acb8225f910f13d682"; |
|
|
final CopyOnWriteArrayList<MultiModalConversationResult> multiModalConversationResults = new CopyOnWriteArrayList<>(); |
|
|
final CopyOnWriteArrayList<MultiModalConversationResult> multiModalConversationResults = new CopyOnWriteArrayList<>(); |
|
|
final MultiModalConversation conv = new MultiModalConversation(); |
|
|
final MultiModalConversation conv = new MultiModalConversation(); |
|
|
@ -86,13 +87,13 @@ public class AliOcrUtil { |
|
|
|
|
|
|
|
|
final MultiModalMessageItemImage userImage = new MultiModalMessageItemImage(picturePath); |
|
|
final MultiModalMessageItemImage userImage = new MultiModalMessageItemImage(picturePath); |
|
|
final String firstQuestionMsg = "请把图片中的内容按照商品的不同规格拆分,返回" + count + "条JSON数据。\n" + |
|
|
final String firstQuestionMsg = "请把图片中的内容按照商品的不同规格拆分,返回" + count + "条JSON数据。\n" + |
|
|
" JSON示例:[{ \"productSn\": \"" + productSnExample + "\", \"productName\":\"" + productNameExample + "\", \"price\": \"" + purchaseOcrExample.getPrice() + "\", \"productCount\": \"" + purchaseOcrExample.getProductCount() + "\", \"attributeList\": \"{'color':'" + purchaseOcrExample.getColor() + "','size':'" + purchaseOcrExample.getSize() + "'}\" }]。" + |
|
|
" JSON示例:[{ \"productSn\": \"" + productSnExample + "\", \"productName\":\"" + productNameExample + "\", \"attributeList\": \"{'color':'" + purchaseOcrExample.getColor() + "','size':'" + purchaseOcrExample.getSize() + "'}\", \"productCount\": \"" + purchaseOcrExample.getProductCount() + "\", \"price\": \"" + purchaseOcrExample.getPrice() + "\" }]。" + |
|
|
"以下是几点要求: " + |
|
|
"以下是几点要求: " + |
|
|
"1.JSON中“productSn”字段可能由字母或数字或特殊符号组成,“color”字段如果图片中没有内容,则赋值“均色”,“size”字段如果图片中没有内容,则赋值“均码”。" + |
|
|
"1.JSON中“productSn”字段可能由字母或数字或特殊符号组成,“color”字段如果图片中没有内容,则赋值“均色”,“size”字段如果图片中没有内容,则赋值“均码”。" + |
|
|
"2.严格按照JSON示例的格式和字段名返回! " + |
|
|
"2.严格按照JSON示例的格式和字段名返回! " + |
|
|
"3.严格按照图中内容值返回! " + |
|
|
"3.严格按照图中内容值返回! " + |
|
|
"4.每个JSON对象必须包含这7个字段。" + |
|
|
"4.每个JSON对象必须包含这7个字段。" + |
|
|
"5.如果图中内容没有productSn和productName信息,则使用JSON示例中的值填充。 " + |
|
|
"5.如果按照你的理解在图中找到了productSn和productName字段对应的信息,则productSn和productName字段的值以图中内容为准。如果按照你的理解在图中没有找到productSn和productName字段对应的信息,则productSn和productName字段的值使用JSON示例中productSn和productName的值填充。 " + |
|
|
"6.请注意返回JSON符号解析格式正确 ,确保java程序能够正确解析。" + |
|
|
"6.请注意返回JSON符号解析格式正确 ,确保java程序能够正确解析。" + |
|
|
"7.严格返回" + count + "条JSON数据,如果数量有偏差按照实际条数返回,不能自动省略!"; |
|
|
"7.严格返回" + count + "条JSON数据,如果数量有偏差按照实际条数返回,不能自动省略!"; |
|
|
log.info("AI提问内容:"+firstQuestionMsg); |
|
|
log.info("AI提问内容:"+firstQuestionMsg); |
|
|
@ -106,10 +107,6 @@ public class AliOcrUtil { |
|
|
final MultiModalConversationParam param = MultiModalConversationParam.builder() |
|
|
final MultiModalConversationParam param = MultiModalConversationParam.builder() |
|
|
.model("qwen-vl-max") |
|
|
.model("qwen-vl-max") |
|
|
.messages(messages) |
|
|
.messages(messages) |
|
|
.temperature(1F) |
|
|
|
|
|
.topP(0.1) |
|
|
|
|
|
.topK(1) |
|
|
|
|
|
.seed(500) |
|
|
|
|
|
.build(); |
|
|
.build(); |
|
|
stopWatch.start("一轮会话"); |
|
|
stopWatch.start("一轮会话"); |
|
|
MultiModalConversationResult result = conv.call(param); |
|
|
MultiModalConversationResult result = conv.call(param); |
|
|
@ -614,7 +611,16 @@ public class AliOcrUtil { |
|
|
purchaseOcrVo.setProductSn(jsonObject.getString("productSn")); |
|
|
purchaseOcrVo.setProductSn(jsonObject.getString("productSn")); |
|
|
purchaseOcrVo.setProductName(jsonObject.getString("productName")); |
|
|
purchaseOcrVo.setProductName(jsonObject.getString("productName")); |
|
|
purchaseOcrVo.setPrice(jsonObject.getBigDecimal("price")); |
|
|
purchaseOcrVo.setPrice(jsonObject.getBigDecimal("price")); |
|
|
purchaseOcrVo.setProductCount(jsonObject.getInteger("productCount")); |
|
|
final String productCount = jsonObject.getString("productCount"); |
|
|
|
|
|
// 有时候数量不对,这里替换一次啊
|
|
|
|
|
|
try { |
|
|
|
|
|
final int intValue = (int) Double.parseDouble(productCount); |
|
|
|
|
|
purchaseOcrVo.setProductCount(intValue); |
|
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
|
System.out.println("数量转换有问题,这里设置为0"); |
|
|
|
|
|
purchaseOcrVo.setProductCount(0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
final String attributeListStr = jsonObject.getString("attributeList"); |
|
|
final String attributeListStr = jsonObject.getString("attributeList"); |
|
|
final JSONObject attributeListJson = JSON.parseObject(attributeListStr); |
|
|
final JSONObject attributeListJson = JSON.parseObject(attributeListStr); |
|
|
|
|
|
|
|
|
|