|
|
|
@ -3,6 +3,7 @@ package com.inspect.simulator.service.impl; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonInclude; |
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.inspect.simulator.domain.algorithm.in.AnalyseRequest; |
|
|
|
@ -32,7 +33,9 @@ import javax.imageio.ImageIO; |
|
|
|
import java.awt.*; |
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
import java.io.*; |
|
|
|
import java.net.HttpURLConnection; |
|
|
|
import java.net.SocketTimeoutException; |
|
|
|
import java.net.URL; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.nio.file.Paths; |
|
|
|
@ -58,8 +61,8 @@ public class ModelServiceImpl implements ModelService { |
|
|
|
private String hrFtpUrl = "ftp://ftpuser:atia2018@192.168.4.129:10012/"; |
|
|
|
|
|
|
|
// @Value("${file.ftpUrlAddress:test}") |
|
|
|
private String ftpUrlAddress = "192.168.4.129"; |
|
|
|
// private String ftpUrlAddress = "192.168.1.116"; |
|
|
|
// private String ftpUrlAddress = "192.168.4.129"; |
|
|
|
private String ftpUrlAddress = "192.168.1.116"; |
|
|
|
|
|
|
|
// @Value("${file.ftpUrlAccount:test}") |
|
|
|
private String ftpUrlAccount = "ftpuser"; |
|
|
|
@ -68,8 +71,8 @@ public class ModelServiceImpl implements ModelService { |
|
|
|
private String ftpUrlPwd = "atia2018"; |
|
|
|
|
|
|
|
// @Value("${file.ftpUrlPort:10000}") |
|
|
|
private Integer ftpUrlPort = 10012; |
|
|
|
// private Integer ftpUrlPort = 10990; |
|
|
|
// private Integer ftpUrlPort = 10012; |
|
|
|
private Integer ftpUrlPort = 10990; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private AnalysisRemoteService analysisRemoteService; |
|
|
|
@ -464,6 +467,25 @@ public class ModelServiceImpl implements ModelService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//inputStream转base64 |
|
|
|
public String downloadAndConvertToBase64(InputStream inputStream) { |
|
|
|
try ( ByteArrayOutputStream buffer = new ByteArrayOutputStream()) { |
|
|
|
|
|
|
|
byte[] data = new byte[4096]; |
|
|
|
int nRead; |
|
|
|
|
|
|
|
while ((nRead = inputStream.read(data, 0, data.length)) != -1) { |
|
|
|
buffer.write(data, 0, nRead); |
|
|
|
} |
|
|
|
|
|
|
|
buffer.flush(); |
|
|
|
return Base64.getEncoder().encodeToString(buffer.toByteArray()); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
private ChatCompletionResponse sendRequest(ChatCompletionRequest request) throws IOException { |
|
|
|
log.info("多模态搭模型请求路径信息:路径" + dmtModelUrl + ",请求头key: " + dmtModelHeader); |
|
|
|
|
|
|
|
@ -496,7 +518,7 @@ public class ModelServiceImpl implements ModelService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//设置规范调用视觉大模型 |
|
|
|
//设置规范调用1.9b视觉大模型 |
|
|
|
public int protractImgVisualization(String analyseRequestStr) { |
|
|
|
int j=-1; |
|
|
|
String visualization = null; |
|
|
|
@ -702,7 +724,7 @@ public class ModelServiceImpl implements ModelService { |
|
|
|
return inputStream; |
|
|
|
} |
|
|
|
|
|
|
|
//视觉大模型 |
|
|
|
//1.9B视觉大模型 |
|
|
|
@Override |
|
|
|
public String Visualization(ImageData imageData) { |
|
|
|
|
|
|
|
@ -752,4 +774,402 @@ public class ModelServiceImpl implements ModelService { |
|
|
|
return responseJson; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @Override |
|
|
|
// public String VisualizationBase64(ApiVisualRequest request) { |
|
|
|
// String responseJson = null; |
|
|
|
// ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
// try { |
|
|
|
// // 1. 处理图像数据 |
|
|
|
// String imagePath = request.getData().getImage_data(); |
|
|
|
// String base64String = convertToBase64(imagePath); |
|
|
|
// if (base64String == null) { |
|
|
|
// throw new RuntimeException("图片Base64转换失败: " + imagePath); |
|
|
|
// } |
|
|
|
// // 2. 构建请求体(根据实际需求选择数组或对象格式) |
|
|
|
// Map<String, Object> requestBody = new HashMap<>(); |
|
|
|
// requestBody.put("model", request.getModel()); |
|
|
|
// |
|
|
|
// List<Map<String, String>> dataList = new ArrayList<>(); |
|
|
|
// Map<String, String> imageData = new HashMap<>(); |
|
|
|
// imageData.put("image_name", request.getData().getImage_name()); |
|
|
|
// imageData.put("image_type", "base64"); |
|
|
|
// imageData.put("image_data", "data:image/jpg;base64," + base64String); |
|
|
|
// dataList.add(imageData); |
|
|
|
// requestBody.put("data", dataList); |
|
|
|
// |
|
|
|
// // 3. 构建HTTP请求 |
|
|
|
// String requestBodyJson = objectMapper.writeValueAsString(requestBody); |
|
|
|
// log.debug("请求体内容: {}", requestBodyJson); |
|
|
|
// |
|
|
|
// Request httpRequest = new Request.Builder() |
|
|
|
// .url("http://25.80.45.92:18063/imageTechnology/lswcv/detect") |
|
|
|
// .post(RequestBody.create(MediaType.parse("application/json"), requestBodyJson)) |
|
|
|
// .addHeader("Content-Type", "application/json") |
|
|
|
// .build(); |
|
|
|
// |
|
|
|
// // 4. 执行请求并处理响应 |
|
|
|
// try (Response response = httpClient.newCall(httpRequest).execute()) { |
|
|
|
// if (!response.isSuccessful()) { |
|
|
|
// String errorBody = response.body() != null ? response.body().string() : "无响应体"; |
|
|
|
// throw new IOException("API请求失败: " + response.code() + ", " + errorBody); |
|
|
|
// } |
|
|
|
// |
|
|
|
// responseJson = response.body().string(); |
|
|
|
// log.info("API响应: {}", responseJson); |
|
|
|
// } |
|
|
|
// } catch (Exception e) { |
|
|
|
// log.error("处理0.45B视觉请求时发生异常", e); |
|
|
|
// throw new RuntimeException("0.45B视觉处理服务异常: " + e.getMessage(), e); |
|
|
|
// } |
|
|
|
// return responseJson; |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置规范调用0.45Bb视觉大模型 |
|
|
|
public int protractImgVisualizationFf(String analyseRequestStr) { |
|
|
|
int j=-1; |
|
|
|
String visualization = null; |
|
|
|
ApiVisualResponse apiVisualResponse = new ApiVisualResponse(); |
|
|
|
|
|
|
|
log.info(Color.MAGENTA + "[ Visualization] bigModelPicAnalyse: analyseRequestStr={}", analyseRequestStr); |
|
|
|
AnalyseRequest analyseRequest = new Gson().fromJson(analyseRequestStr, AnalyseRequest.class); |
|
|
|
String imgUrl = analyseRequest.getObjectList().get(0).getImageUrlList()[0]; |
|
|
|
|
|
|
|
String lineId = patrolResultMapper.selectPatrolResultByTaskPatrolledId(analyseRequest.getTaskPatrolId(), analyseRequest.getObjectList().get(0).getObjectId()); |
|
|
|
String[] typeList = analyseRequest.getObjectList().get(0).getTypeList(); |
|
|
|
List<VisualJson> visualJsonList = new ArrayList<>(); |
|
|
|
|
|
|
|
String imageName = imgUrl.substring(imgUrl.lastIndexOf("/") + 1);//图片名称 |
|
|
|
Path path = Paths.get(imgUrl); |
|
|
|
String directoryPath = path.getParent().toString().replace("\\", "/") + "/"; // 获取图片所在目录并统一使用正斜杠 |
|
|
|
|
|
|
|
// 新文件路径 |
|
|
|
Date date = new Date(); |
|
|
|
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); |
|
|
|
String markPicName = sf.format(date); |
|
|
|
String pureName = imageName.substring(0, imageName.lastIndexOf('.')); |
|
|
|
String outputPath = directoryPath + pureName + "_" + markPicName + ".jpg"; |
|
|
|
|
|
|
|
ImageData imageData = new ImageData(); |
|
|
|
imageData.setImage_name(imageName); |
|
|
|
imageData.setImage_data(analyseRequest.getObjectList().get(0).getImageUrlList()[0]); |
|
|
|
|
|
|
|
//下载图片 |
|
|
|
InputStream inputStream = downloadFtp(imgUrl); |
|
|
|
//调用视觉大模型 |
|
|
|
visualization = this.Visualization_045b(imageData); |
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(visualization)) { |
|
|
|
try { |
|
|
|
apiVisualResponse = objectMapper.readValue(visualization, ApiVisualResponse.class); |
|
|
|
} catch (JsonProcessingException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} else { |
|
|
|
log.info(imageName + "图片,0.45b视觉大模型无返回,使用默认数据"); |
|
|
|
// visualization = "{\"traceId\":\"88e754a8-1d07-4bbd-9d43-98ac40bdb7ad\",\"success\":true,\"data\":[{\"error_code\":0,\"image_name\":\"1613_20250711173000_2081817_02160558348850500131.jpg\",\"image_height\":720,\"image_width\":1280,\"infer_results\":[{\"bbox\":[533.7729,583.49506,773.02124,718.8728],\"category\":\"箱门闭合异常-箱门闭合正常\",\"score\":0.96470034},{\"bbox\":[795.3903,536.1146,1043.0077,718.15497],\"category\":\"箱门闭合异常-箱门闭合正常\",\"score\":0.9343145},{\"bbox\":[1057.7261,638.2431,1223.5446,719.07074],\"category\":\"箱门闭合异常-箱门闭合正常\",\"score\":0.8148986},{\"bbox\":[318.5776,0.34692764,566.56915,592.8563],\"category\":\"设备积污-表面污秽\",\"score\":0.064688765}]}],\"timeUsed\":411}\n"; |
|
|
|
visualization="{\"data\":[{\"image_height\":720,\"image_name\":\"21.jpg\",\"image_width\":1280,\"infer_results\":[{\"bbox\":[4,230,944,715],\"category\":\"\\u57fa\\u7840\\u7c7b-\\u7acb\\u67f1\\u6df9\\u6ca1\",\"score\":0.74},{\"bbox\":[0,224,962,721],\"category\":\"\\u6e17\\u6f0f\\u6cb9-\\u5730\\u9762\\u6cb9\\u6c61\",\"score\":0.88}]}],\"success\":true,\"traceId\":\"0c9aabf5-4b6f-413c-b5f1-6636b071368a\"}"; |
|
|
|
try { |
|
|
|
apiVisualResponse = objectMapper.readValue(visualization, ApiVisualResponse.class); |
|
|
|
} catch (JsonProcessingException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
InputStream outputImageStream = null; |
|
|
|
try { |
|
|
|
outputImageStream = drawBoundingBoxesAndSave(apiVisualResponse, inputStream); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
if (outputImageStream != null) { |
|
|
|
log.info("视觉大模型复筛图片" + imageName + "已上传到:" + outputPath); |
|
|
|
this.picFtp(outputPath, outputImageStream, ftpUrlAddress, ftpUrlPort, ftpUrlAccount, ftpUrlPwd); |
|
|
|
|
|
|
|
for (int i = 0; i < typeList.length; i++) { |
|
|
|
VisualJson visualJson =new VisualJson(); |
|
|
|
//存入数据库 |
|
|
|
String objectId = analyseRequest.getObjectList().get(0).getObjectId(); |
|
|
|
visualJson.setDefectType(apiVisualResponse.getData().get(0).getInfer_results().get(0).getCategory()); |
|
|
|
visualJson.setObjectId(objectId); |
|
|
|
visualJson.setFilter("2"); |
|
|
|
visualJson.setTaskPatrolId(analyseRequest.getTaskPatrolId()); |
|
|
|
visualJson.setBusinessId(lineId); |
|
|
|
visualJson.setImgUrl(outputPath); |
|
|
|
visualJson.setUseType(typeList[i]); |
|
|
|
visualJsonList.add(visualJson); |
|
|
|
} |
|
|
|
j = resultAnalysisMapper.addVisualModelInfo(visualJsonList); |
|
|
|
} |
|
|
|
return j; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//0.45B视觉请求调用 |
|
|
|
@Override |
|
|
|
public String Visualization_045b(ImageData data) { |
|
|
|
String responseJson = null; |
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
try { |
|
|
|
// 1. 处理图像数据 |
|
|
|
// String base64String = convertToBase64(imagePath); |
|
|
|
//连接ftp下载图片转BASE64 |
|
|
|
InputStream inputStream = downloadFtp(data.getImage_data()); |
|
|
|
String base64String = downloadAndConvertToBase64(inputStream); |
|
|
|
if (base64String == null) { |
|
|
|
throw new RuntimeException("图片Base64转换失败: " + data.getImage_data()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Path path = Paths.get(data.getImage_data()); |
|
|
|
String imgName = path.getFileName().toString();// 直接获取带后缀的文件名 |
|
|
|
|
|
|
|
// 2. 构建请求体(根据curl示例格式) |
|
|
|
Map<String, Object> requestBody = new HashMap<>(); |
|
|
|
requestBody.put("model", "eprim"); |
|
|
|
|
|
|
|
List<Map<String, String>> dataList = new ArrayList<>(); |
|
|
|
Map<String, String> imageData = new HashMap<>(); |
|
|
|
imageData.put("image_name", imgName); |
|
|
|
imageData.put("image_type", "base64"); |
|
|
|
imageData.put("image_data", "data:image/jpeg;base64," + base64String); |
|
|
|
dataList.add(imageData); |
|
|
|
requestBody.put("data", dataList); |
|
|
|
|
|
|
|
// 3. 构建HTTP请求 |
|
|
|
String requestBodyJson = objectMapper.writeValueAsString(requestBody); |
|
|
|
log.debug("请求体内容: {}", requestBodyJson); |
|
|
|
|
|
|
|
Request httpRequest = new Request.Builder() |
|
|
|
.url("http://25.80.45.92:18063/imageTechnology/cvlsw/api") // 更新URL |
|
|
|
.post(RequestBody.create(MediaType.parse("application/json"), requestBodyJson)) |
|
|
|
.addHeader("Content-Type", "application/json") |
|
|
|
.addHeader("Accept", "*/*") |
|
|
|
.addHeader("Accept-Encoding", "gzip, deflate") |
|
|
|
.addHeader("Cache-Control", "no-cache") |
|
|
|
.addHeader("Connection", "keep-alive") |
|
|
|
.addHeader("Host", "25.80.45.92:18063") |
|
|
|
.addHeader("User-Agent", "PostmanRuntime/7.18.0") |
|
|
|
.addHeader("cache-control", "no-cache") |
|
|
|
.build(); |
|
|
|
|
|
|
|
// 4. 执行请求并处理响应 |
|
|
|
try (Response response = httpClient.newCall(httpRequest).execute()) { |
|
|
|
if (!response.isSuccessful()) { |
|
|
|
String errorBody = response.body() != null ? response.body().string() : "无响应体"; |
|
|
|
throw new IOException("API请求失败: " + response.code() + ", " + errorBody); |
|
|
|
} |
|
|
|
responseJson = response.body().string(); |
|
|
|
log.info("API响应: {}", responseJson); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("处理0.45B视觉请求时发生异常", e); |
|
|
|
return null; |
|
|
|
} |
|
|
|
return responseJson; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//绍兴智能体 |
|
|
|
//绍兴智能体 sessionId-获取 |
|
|
|
public String createSession() throws Exception { |
|
|
|
// 请求URL |
|
|
|
URL url = new URL("http://25.90.210.236/lmp-cloud-ias-server/api/session/create"); |
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
|
|
|
try { |
|
|
|
// 设置请求参数 |
|
|
|
connection.setRequestMethod("POST"); |
|
|
|
connection.setRequestProperty("Content-Type", "application/json"); |
|
|
|
connection.setRequestProperty("Authorization", "1c01eb546de442a09a16db21c564802c"); |
|
|
|
connection.setDoOutput(true); |
|
|
|
connection.setConnectTimeout(10000); |
|
|
|
connection.setReadTimeout(10000); |
|
|
|
|
|
|
|
// 请求体 |
|
|
|
String requestBody = "{\"agentId\":\"1fd10e55-0a30-447d-95a8-a0de5423ab57\",\"agentVersion\":\"1754557192722\"}"; |
|
|
|
|
|
|
|
// 发送请求体 |
|
|
|
try (OutputStream os = connection.getOutputStream()) { |
|
|
|
byte[] input = requestBody.getBytes("utf-8"); |
|
|
|
os.write(input, 0, input.length); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取响应 |
|
|
|
int responseCode = connection.getResponseCode(); |
|
|
|
if (responseCode == HttpURLConnection.HTTP_OK) { |
|
|
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"))) { |
|
|
|
StringBuilder response = new StringBuilder(); |
|
|
|
String responseLine; |
|
|
|
while ((responseLine = br.readLine()) != null) { |
|
|
|
response.append(responseLine.trim()); |
|
|
|
} |
|
|
|
|
|
|
|
// 解析sessionId(简单字符串处理) |
|
|
|
String responseBody = response.toString(); |
|
|
|
if (responseBody.contains("\"sessionId\"")) { |
|
|
|
String sessionId = responseBody.split("\"sessionId\":\"")[1].split("\"")[0]; |
|
|
|
return sessionId; |
|
|
|
} else { |
|
|
|
throw new RuntimeException("获取sessionId失败: " + responseBody); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
throw new RuntimeException("HTTP请求失败,状态码: " + responseCode); |
|
|
|
} |
|
|
|
} finally { |
|
|
|
connection.disconnect(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 运行会话 |
|
|
|
public String runSession(String sessionId, String query, String imageBase64) throws Exception { |
|
|
|
String textContent = String.format( |
|
|
|
"{\"model\":\"rsv-sh58jisx\",\"query\":\"%s\",\"imagebase\":\"%s\"}", |
|
|
|
escapeJsonString(query), |
|
|
|
imageBase64 != null ? imageBase64 : "" |
|
|
|
); |
|
|
|
|
|
|
|
String requestBody = String.format( |
|
|
|
"{\"agentId\":\"1fd10e55-0a30-447d-95a8-a0de5423ab57\",\"agentVersion\":\"1754557192722\",\"sessionId\":\"%s\",\"stream\":false,\"text\":\"%s\"}", |
|
|
|
sessionId, |
|
|
|
escapeJsonString(textContent) |
|
|
|
); |
|
|
|
|
|
|
|
URL url = new URL("http://25.90.210.236/lmp-cloud-ias-server/api/session/run"); |
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
|
|
|
|
|
|
|
try { |
|
|
|
connection.setRequestMethod("POST"); |
|
|
|
connection.setRequestProperty("Content-Type", "application/json"); |
|
|
|
connection.setRequestProperty("Authorization", "1c01eb546de442a09a16db21c564802c"); |
|
|
|
connection.setDoOutput(true); |
|
|
|
connection.setConnectTimeout(10000); |
|
|
|
connection.setReadTimeout(30000); |
|
|
|
|
|
|
|
try (OutputStream os = connection.getOutputStream()) { |
|
|
|
byte[] input = requestBody.getBytes("utf-8"); |
|
|
|
os.write(input, 0, input.length); |
|
|
|
} |
|
|
|
|
|
|
|
int responseCode = connection.getResponseCode(); |
|
|
|
if (responseCode == HttpURLConnection.HTTP_OK) { |
|
|
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"))) { |
|
|
|
StringBuilder response = new StringBuilder(); |
|
|
|
String responseLine; |
|
|
|
while ((responseLine = br.readLine()) != null) { |
|
|
|
response.append(responseLine.trim()); |
|
|
|
} |
|
|
|
return parseAnswer(response.toString()); |
|
|
|
} |
|
|
|
} else { |
|
|
|
throw new RuntimeException("运行会话失败,状态码: " + responseCode); |
|
|
|
} |
|
|
|
} finally { |
|
|
|
connection.disconnect(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private String parseAnswer(String responseBody) { |
|
|
|
if (responseBody.contains("\"answer\"")) { |
|
|
|
String answer = responseBody.split("\"answer\":\"")[1].split("\"")[0]; |
|
|
|
return answer.replace("\\\"", "\"").replace("\\\\", "\\"); |
|
|
|
} else { |
|
|
|
throw new RuntimeException("获取answer失败: " + responseBody); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//转义 |
|
|
|
private String escapeJsonString(String input) { |
|
|
|
return input.replace("\\", "\\\\") |
|
|
|
.replace("\"", "\\\"") |
|
|
|
.replace("\n", "\\n") |
|
|
|
.replace("\r", "\\r") |
|
|
|
.replace("\t", "\\t"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String sessionAnswer(String imgUrl) { |
|
|
|
String answer=""; |
|
|
|
// 1. 创建会话 |
|
|
|
log.info("正在创建会话..."); |
|
|
|
String sessionId = null; |
|
|
|
try { |
|
|
|
sessionId = createSession(); |
|
|
|
|
|
|
|
log.info("会话创建成功,sessionId: " + sessionId); |
|
|
|
|
|
|
|
// 2. 运行会话 |
|
|
|
log.info("正在向大模型提问..."); |
|
|
|
//String query = "#角色 你是电力缺陷识别专家,擅长识别并框选设备缺陷、环境异常等。#功能 根据我发送给你的图像,识别一下图像中的信息,给出缺陷或异常的描述。"; |
|
|
|
String query ="这张图片里有什么?"; |
|
|
|
// String base64String = convertToBase64(imgUrl); |
|
|
|
|
|
|
|
// 转换图片为base64 |
|
|
|
InputStream inputStream = downloadFtp(imgUrl); |
|
|
|
byte[] fileBytes = IOUtils.toByteArray(inputStream); |
|
|
|
String base64String = Base64.getEncoder().encodeToString(fileBytes); |
|
|
|
if (base64String != null) { |
|
|
|
answer = runSession(sessionId, query, base64String); |
|
|
|
log.info("大模型回答: " + answer); |
|
|
|
} else { |
|
|
|
log.info(imgUrl + "图片转base64未成功!"); |
|
|
|
} |
|
|
|
return answer; |
|
|
|
} catch (Exception e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public int agentInquiry(String analyseRequestStr) { |
|
|
|
String answer=""; |
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
List<VisualJson> visualJsonList = new ArrayList<>(); |
|
|
|
log.info(Color.MAGENTA + "[Agent Inquiry ShaoXing] agentInquiry: analyseRequestStr={}", analyseRequestStr); |
|
|
|
AnalyseRequest analyseRequest = new Gson().fromJson(analyseRequestStr, AnalyseRequest.class); |
|
|
|
String imgUrl = analyseRequest.getObjectList().get(0).getImageUrlList()[0]; |
|
|
|
String lineId = patrolResultMapper.selectPatrolResultByTaskPatrolledId(analyseRequest.getTaskPatrolId(), analyseRequest.getObjectList().get(0).getObjectId()); |
|
|
|
|
|
|
|
//调用绍兴-智能体 |
|
|
|
String answerResult = this.sessionAnswer(imgUrl); |
|
|
|
log.info("调用绍兴智能体响应结果:" + answerResult); |
|
|
|
if (StringUtils.isNotEmpty(answerResult)){ |
|
|
|
JsonNode jsonNode = null; |
|
|
|
try { |
|
|
|
//获取answer-大模型回答 |
|
|
|
jsonNode = objectMapper.readTree(answerResult); |
|
|
|
answer = jsonNode.get("data").get("answer").asText(); |
|
|
|
} catch (JsonProcessingException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
//返回结构体 |
|
|
|
String[] typeList = analyseRequest.getObjectList().get(0).getTypeList(); |
|
|
|
for (int i = 0; i < typeList.length; i++) { |
|
|
|
VisualJson visualJson =new VisualJson(); |
|
|
|
//存入数据库 |
|
|
|
String objectId = analyseRequest.getObjectList().get(0).getObjectId(); |
|
|
|
visualJson.setObjectId(objectId); |
|
|
|
visualJson.setFilter("2"); |
|
|
|
visualJson.setTaskPatrolId(analyseRequest.getTaskPatrolId()); |
|
|
|
visualJson.setBusinessId(lineId); |
|
|
|
visualJson.setUseType(typeList[i]); |
|
|
|
//answer |
|
|
|
visualJson.setDescription(answer); |
|
|
|
visualJsonList.add(visualJson); |
|
|
|
} |
|
|
|
return resultAnalysisMapper.addVisualModelInfo(visualJsonList); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |