md
This commit is contained in:
parent
2143f13d51
commit
86af5e9744
@ -1,36 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.xdadan</groupId>
|
||||
<artifactId>emis</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<artifactId>emis-ai-web</artifactId>
|
||||
<version>1.0.2</version>
|
||||
|
||||
<description>ai web服务入口</description>
|
||||
|
||||
<properties>
|
||||
<java.version>8</java.version>
|
||||
<target.dir>pub</target.dir>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.xdadan</groupId>
|
||||
<artifactId>emis-ai</artifactId>
|
||||
<version>1.0.2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@ -1,170 +0,0 @@
|
||||
|
||||
package com.xdadan.erp.web.ai;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.xdadan.erp.ai.service.OCRService;
|
||||
import com.xdadan.erp.common.config.PayConfig;
|
||||
import com.xdadan.erp.common.core.controller.BaseController;
|
||||
import com.xdadan.erp.common.core.domain.AjaxResult;
|
||||
import com.xdadan.erp.common.core.redis.RedissonService;
|
||||
import com.xdadan.erp.common.utils.file.FileUploadUtils;
|
||||
import com.xdadan.erp.common.utils.file.FileUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* AI 公共 Controller
|
||||
*
|
||||
* @author linfso
|
||||
* @date 2023-12-14 13:02:48
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/ai/common")
|
||||
public class AICommonController extends BaseController
|
||||
{
|
||||
|
||||
@Autowired
|
||||
RedissonService redissonService;
|
||||
|
||||
@Autowired
|
||||
OCRService ocrService;
|
||||
|
||||
|
||||
private static final String API_URL = "https://chat.deepseek.com";
|
||||
private static final String API_KEY = "sk-408990000f9c4c349c4d69df7630bc75";
|
||||
|
||||
private final ExecutorService executorService = Executors.newCachedThreadPool();
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@PostMapping(value = "/aiChat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
public SseEmitter aiChat(@RequestBody String question) {
|
||||
SseEmitter emitter = new SseEmitter(-1L);
|
||||
executorService.execute(() -> {
|
||||
try {
|
||||
log.info("流式回答开始,问题:{}", question);
|
||||
try (CloseableHttpClient client = HttpClients.createDefault()) {
|
||||
HttpPost request = new HttpPost(API_URL);
|
||||
request.setHeader("Content-Type", "application/json");
|
||||
request.setHeader("Authorization", "Bearer " + API_KEY);
|
||||
|
||||
Map<String, Object> message = new HashMap<>();
|
||||
message.put("role", "user");
|
||||
message.put("content", question);
|
||||
|
||||
Map<String, Object> requestMap = new HashMap<>();
|
||||
requestMap.put("model", "deepseek-chat");
|
||||
requestMap.put("messages", Collections.singletonList(message));
|
||||
requestMap.put("stream", true);
|
||||
|
||||
String requestBody = objectMapper.writeValueAsString(requestMap);
|
||||
request.setEntity(new StringEntity(requestBody, StandardCharsets.UTF_8));
|
||||
|
||||
try (CloseableHttpResponse response = client.execute(request);
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.startsWith("data: ")) {
|
||||
String jsonData = line.substring(6);
|
||||
if ("[DONE]".equals(jsonData)) {
|
||||
break;
|
||||
}
|
||||
JsonNode node = objectMapper.readTree(jsonData);
|
||||
String content = node.path("choices")
|
||||
.path(0)
|
||||
.path("delta")
|
||||
.path("content")
|
||||
.asText("");
|
||||
if (!content.isEmpty()) {
|
||||
emitter.send(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info("流式回答结束,{}",question);
|
||||
emitter.complete();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("处理 Deepseek 请求时发生错误", e);
|
||||
emitter.completeWithError(e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("处理 Deepseek 请求时发生错误", e);
|
||||
emitter.completeWithError(e);
|
||||
}
|
||||
});
|
||||
return emitter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通用上传请求(单个)
|
||||
*/
|
||||
@PostMapping("/ocrRecognizeByUpload")
|
||||
public AjaxResult ocrRecognizeByUpload(MultipartFile file) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
// 上传文件路径
|
||||
String filePath = PayConfig.getUploadPath();
|
||||
// 上传并返回新文件名称
|
||||
String fileName = FileUploadUtils.upload(filePath, file);
|
||||
AjaxResult rst=ocrService.recognize(fileName);
|
||||
return rst;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ocr识别
|
||||
* @param appId
|
||||
* @param sign
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/ocrRecognizeByBase64")
|
||||
public AjaxResult ocrRecognizeByBase64(String appId, String base64Data, String sign)
|
||||
{
|
||||
if(StringUtils.isAnyEmpty(base64Data,appId,sign)){
|
||||
return AjaxResult.error("appId,sign,mainNo required!");
|
||||
}
|
||||
|
||||
if(!"xdadan20240614".equals(appId)){
|
||||
return AjaxResult.error("appId error!");
|
||||
}
|
||||
|
||||
// base64写入文件
|
||||
String filePath="";
|
||||
|
||||
AjaxResult rst=ocrService.recognize(filePath);
|
||||
return rst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@ -1,2 +0,0 @@
|
||||
mvn install:install-file -DgroupId=com.aspose -DartifactId=aspose-words -Dversion=19.1.0 -Dpackaging=jar -Dfile=./aspose-words-19.1-jdk16.jar
|
||||
#mvn install:install-file -DgroupId=com.mascloud -DartifactId=massdk -Dversion=1.0.3 -Dpackaging=jar -Dfile=./masmgc.sdk.sms-1.0.3-SNAPSHOT.jar
|
||||
169
emis-ai/pom.xml
169
emis-ai/pom.xml
@ -1,169 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.xdadan</groupId>
|
||||
<artifactId>emis</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>emis-ai</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<description>AI模块</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- 通用工具-->
|
||||
<dependency>
|
||||
<groupId>com.xdadan</groupId>
|
||||
<artifactId>emis-common</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 核心模块-->
|
||||
<dependency>
|
||||
<groupId>com.xdadan</groupId>
|
||||
<artifactId>emis-framework</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.xdadan</groupId>
|
||||
<artifactId>emis-system</artifactId>
|
||||
<version>1.0.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.googlecode.aviator</groupId>
|
||||
<artifactId>aviator</artifactId>
|
||||
<version>5.2.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- pdf核心包 -->
|
||||
<dependency>
|
||||
<groupId>com.itextpdf</groupId>
|
||||
<artifactId>itextpdf</artifactId>
|
||||
<version>5.5.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itextpdf</groupId>
|
||||
<artifactId>itext-asian</artifactId>
|
||||
<version>5.2.0</version>
|
||||
</dependency>
|
||||
<!-- html转pdf -->
|
||||
<dependency>
|
||||
<groupId>com.itextpdf.tool</groupId>
|
||||
<artifactId>xmlworker</artifactId>
|
||||
<version>5.5.6</version>
|
||||
</dependency>
|
||||
<!-- pdf转图片 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.pdfbox</groupId>
|
||||
<artifactId>pdfbox</artifactId>
|
||||
<version>2.0.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.pdfbox</groupId>
|
||||
<artifactId>fontbox</artifactId>
|
||||
<version>2.0.9</version>
|
||||
</dependency>
|
||||
<!--缩略图-->
|
||||
<dependency>
|
||||
<groupId>net.coobird</groupId>
|
||||
<artifactId>thumbnailator</artifactId>
|
||||
<version>0.4.11</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- 阿里云短信服务 -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>dysmsapi20170525</artifactId>
|
||||
<version>2.0.22</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-openapi</artifactId>
|
||||
<version>0.2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-console</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-util</artifactId>
|
||||
<version>0.2.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea</artifactId>
|
||||
<version>1.1.14</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 移动云-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.mascloud</groupId>-->
|
||||
<!-- <artifactId>massdk</artifactId>-->
|
||||
<!-- <version>1.0.3</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
<version>4.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-scratchpad</artifactId>
|
||||
<version>4.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>ooxml-schemas</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- alibaba/easyexcel 使用高版本,低版本string接收数字丢小数位的bug -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel</artifactId>
|
||||
<version>3.3.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.deepoove</groupId>
|
||||
<artifactId>poi-tl</artifactId>
|
||||
<version>1.10.6</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 先执行本地 lib -->
|
||||
<dependency>
|
||||
<groupId>com.aspose</groupId>
|
||||
<artifactId>aspose-words</artifactId>
|
||||
<version>19.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- apache commons-text-->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-text</artifactId>
|
||||
<version>1.10.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -1,31 +0,0 @@
|
||||
package com.xdadan.erp.ai.service;
|
||||
|
||||
import com.xdadan.erp.common.core.domain.AjaxResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class OCRService {
|
||||
|
||||
public AjaxResult recognize(String filePath){
|
||||
// ParamConfig paramConfig = ParamConfig.getDefaultConfig();
|
||||
// paramConfig.setDoAngle(true);
|
||||
// paramConfig.setMostAngle(true);
|
||||
// InferenceEngine engine = InferenceEngine.getInstance(Model.ONNX_PPOCR_V4);
|
||||
// // 开始识别
|
||||
// OcrResult ocrResult = engine.runOcr(filePath, paramConfig);
|
||||
return AjaxResult.success("成功");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// String temPath = "/Users/alan/Downloads/工作台1.png";
|
||||
// ParamConfig paramConfig = ParamConfig.getDefaultConfig();
|
||||
// paramConfig.setDoAngle(true);
|
||||
// paramConfig.setMostAngle(true);
|
||||
// InferenceEngine engine = InferenceEngine.getInstance(Model.ONNX_PPOCR_V4);
|
||||
// // 开始识别
|
||||
// OcrResult ocrResult = engine.runOcr(temPath, paramConfig);
|
||||
// System.out.println("识别内容"+ocrResult.getStrRes().replace("\n", " "));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user