|
|
|
@ -18,7 +18,9 @@ import com.inspect.simulator.utils.HttpClientUtils; |
|
|
|
import com.inspect.simulator.utils.redis.RedisService; |
|
|
|
import lombok.Value; |
|
|
|
import okhttp3.*; |
|
|
|
import org.apache.commons.compress.utils.IOUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.net.ftp.FTPSClient; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -26,8 +28,10 @@ import org.springframework.stereotype.Service; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.awt.*; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.net.SocketTimeoutException; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.nio.file.Paths; |
|
|
|
import java.util.*; |
|
|
|
import java.util.List; |
|
|
|
@ -45,6 +49,21 @@ public class ModelServiceImpl implements ModelService { |
|
|
|
// @Value("${file.dmtModelHeader:test}") |
|
|
|
private String dmtModelHeader = "54c1ae2c5fd54afe85e74d6fe9161f7f"; |
|
|
|
|
|
|
|
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"; |
|
|
|
|
|
|
|
// @Value("${file.ftpUrlAccount:test}") |
|
|
|
private String ftpUrlAccount = "ftpuser"; |
|
|
|
|
|
|
|
// @Value("${file.ftpUrlPwd:test}") |
|
|
|
private String ftpUrlPwd = "atia2018"; |
|
|
|
|
|
|
|
// @Value("${file.ftpUrlPort:10000}") |
|
|
|
private Integer ftpUrlPort = 10012; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private AnalysisRemoteService analysisRemoteService; |
|
|
|
|
|
|
|
@ -254,13 +273,14 @@ public class ModelServiceImpl implements ModelService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public int bigModelPicAnalyse(String analyseRequestStr) { |
|
|
|
int i=0; |
|
|
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
log.info(Color.MAGENTA + "[BIG MODEL] bigModelPicAnalyse: analyseRequestStr={}", analyseRequestStr); |
|
|
|
log.info(Color.RED + "[dmt bigModel] bigModel: analyseRequestStr={}", analyseRequestStr); |
|
|
|
AnalyseRequest analyseRequest = new Gson().fromJson(analyseRequestStr, AnalyseRequest.class); |
|
|
|
|
|
|
|
Multimodal multimodal=new Multimodal(); |
|
|
|
multimodal.setImageData("/home/atia/docker-deploy-encrypt/data/vsftpd/ftpuser"+analyseRequest.getObjectList().get(0).getImageUrlList()[0]); |
|
|
|
multimodal.setImageData(analyseRequest.getObjectList().get(0).getImageUrlList()[0]); |
|
|
|
|
|
|
|
//调用多模态大模型, |
|
|
|
String multimodalResult = this.Multimodal(multimodal); |
|
|
|
log.info("调用多模态响应结果:"+multimodalResult); |
|
|
|
@ -281,11 +301,13 @@ public class ModelServiceImpl implements ModelService { |
|
|
|
contentJson.setIsDefectValue("0"); |
|
|
|
} |
|
|
|
//存入数据库 |
|
|
|
String objectId = analyseRequest.getObjectList().get(0).getObjectId(); |
|
|
|
contentJson.setObjectId(objectId); |
|
|
|
contentJson.setFilter("2"); |
|
|
|
log.info("返回json"+new Gson().toJson(contentJson)); |
|
|
|
if(contentJson != null) { |
|
|
|
i = resultAnalysisMapper.addDmtModelInfo(contentJson); |
|
|
|
} |
|
|
|
|
|
|
|
int i = resultAnalysisMapper.addDmtModelInfo(contentJson); |
|
|
|
|
|
|
|
return i; |
|
|
|
|
|
|
|
} |
|
|
|
@ -302,6 +324,8 @@ public class ModelServiceImpl implements ModelService { |
|
|
|
try { |
|
|
|
attempt++; |
|
|
|
ChatCompletionRequest request = buildCorrectRequest(multimodal); |
|
|
|
// System.out.println("请求多模态json"+ new Gson().toJson(request)); |
|
|
|
|
|
|
|
ChatCompletionResponse response = sendRequest(request); |
|
|
|
System.out.println("响应ID: " + response.getId()); |
|
|
|
Gson gson = new Gson(); |
|
|
|
@ -361,10 +385,14 @@ public class ModelServiceImpl implements ModelService { |
|
|
|
fileExtension = multimodal.getImageName().substring(lastDot + 1).toLowerCase(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// log.info("图片请求"+multimodal.getImageData()); |
|
|
|
// 转换图片为base64 |
|
|
|
String base64String = convertToBase64(multimodal.getImageData()); |
|
|
|
imageContent.setImage("data:image/" + fileExtension + ";base64," + base64String); |
|
|
|
String base64String = downloadFtp(multimodal.getImageData()); |
|
|
|
if (base64String!=null) { |
|
|
|
imageContent.setImage("data:image/" + fileExtension + ";base64," + base64String); |
|
|
|
}else{ |
|
|
|
log.info(multimodal.getImageData()+"图片转base64未成功!"); |
|
|
|
} |
|
|
|
// imageUrl.setUrl("data:image/" + fileExtension + ";base64," + base64String); |
|
|
|
// imageContent.setImageUrl(imageUrl); |
|
|
|
contents.add(imageContent); |
|
|
|
@ -378,10 +406,34 @@ public class ModelServiceImpl implements ModelService { |
|
|
|
request.setMaxTokens(multimodal.getMaxTokens() > 0 ? multimodal.getMaxTokens() : 300); |
|
|
|
request.setMessages(Collections.singletonList(message)); |
|
|
|
|
|
|
|
|
|
|
|
return request; |
|
|
|
} |
|
|
|
|
|
|
|
public String downloadFtp(String downloadPath) { |
|
|
|
InputStream inputStream=null; |
|
|
|
FTPSClient ftps; |
|
|
|
try { |
|
|
|
ftps = new FTPSClient(true); |
|
|
|
ftps.connect(ftpUrlAddress, ftpUrlPort); |
|
|
|
boolean loginRes = ftps.login(ftpUrlAccount, ftpUrlPwd); |
|
|
|
System.out.println(loginRes); |
|
|
|
ftps.setFileType(2); |
|
|
|
ftps.enterLocalPassiveMode(); |
|
|
|
ftps.setControlEncoding("UTF-8"); |
|
|
|
ftps.setFileTransferMode(10); |
|
|
|
ftps.execPROT("P"); |
|
|
|
inputStream = ftps.retrieveFileStream(downloadPath); |
|
|
|
if (inputStream == null) { |
|
|
|
System.out.println("[FTP] DOWNLOAD FAIL, EMPTY STREAM:" + downloadPath); |
|
|
|
} |
|
|
|
byte[] fileBytes = IOUtils.toByteArray(inputStream); |
|
|
|
return Base64.getEncoder().encodeToString(fileBytes); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("error" + e); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
//图片路径转base64 |
|
|
|
public String convertToBase64(String imagePath) { |
|
|
|
try { |
|
|
|
|