Commit 333130e4 authored by alex yao's avatar alex yao

style: Text In Client

parent c0df8f2d
......@@ -8,7 +8,7 @@ import cn.com.poc.thirdparty.resource.demand.ai.function.entity.FunctionLLMConfi
import cn.com.poc.thirdparty.resource.demand.ai.function.entity.Parameters;
import cn.com.poc.thirdparty.resource.demand.ai.function.entity.Properties;
import cn.com.poc.thirdparty.resource.demand.ai.function.extraction.entity.KeyInfo;
import cn.com.poc.thirdparty.resource.demand.ai.function.text_in_pdf2md.api.TextInClient;
import cn.com.poc.thirdparty.resource.textin.api.TextInClient;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.json.JSONException;
import com.alibaba.fastjson.JSONArray;
......@@ -19,13 +19,17 @@ import java.util.ArrayList;
import java.util.List;
/**
* 合同关键信息抽取-要素提取
*
* @author alex.yao
* @date 2025/5/12
*/
@Component
public class ContractExtractionFunction extends AbstractLargeModelFunction {
private String DESC = "合同关键信息抽取";
private final String DESC = "合同关键信息抽取";
private final TextInClient textInClient = new TextInClient();
private final FunctionLLMConfig functionLLMConfig = new FunctionLLMConfig.FunctionLLMConfigBuilder()
.name("contract_extraction")
......@@ -85,8 +89,6 @@ public class ContractExtractionFunction extends AbstractLargeModelFunction {
}
keyInfos.add(keyInfo);
}
TextInClient textInClient = new TextInClient();
String extraction = textInClient.extraction(fileUrl, keyInfos);
result.setFunctionResult(extraction);
result.setPromptContent(extraction);
......
......@@ -7,7 +7,7 @@ import cn.com.poc.thirdparty.resource.demand.ai.function.AbstractLargeModelFunct
import cn.com.poc.thirdparty.resource.demand.ai.function.entity.FunctionLLMConfig;
import cn.com.poc.thirdparty.resource.demand.ai.function.entity.Parameters;
import cn.com.poc.thirdparty.resource.demand.ai.function.entity.Properties;
import cn.com.poc.thirdparty.resource.demand.ai.function.text_in_pdf2md.api.TextInClient;
import cn.com.poc.thirdparty.resource.textin.api.TextInClient;
import cn.hutool.core.collection.ListUtil;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
......@@ -64,7 +64,8 @@ public class PdfToMDFunction extends AbstractLargeModelFunction {
options.put("parse_mode", "auto");
options.put("table_flavor", "md");
try {
String response = TextInClient.recognize(fileContent, options);
TextInClient textInClient = new TextInClient();
String response = textInClient.OCR(fileContent, options);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(response);
if (jsonNode.has("result") && jsonNode.get("result").has("markdown")) {
......
package cn.com.poc.thirdparty.resource.demand.ai.function.text_in_pdf2md.api;
package cn.com.poc.thirdparty.resource.textin.api;
/**
* @author alex.yao
......@@ -32,20 +32,27 @@ import java.util.Map;
public class TextInClient {
final private static Logger logger = LoggerFactory.getLogger(TextInClient.class);
private static final String appId = "dafd04a574230c00ccba61132160de0c";
private static final String secretCode = "3bc03c7e6f9402963e6e71d16d786a9c";
final private Logger logger = LoggerFactory.getLogger(TextInClient.class);
private String appId = "dafd04a574230c00ccba61132160de0c";
private String secretCode = "3bc03c7e6f9402963e6e71d16d786a9c";
public TextInClient() {
}
public TextInClient(String appId, String secretCode) {
this.appId = appId;
this.secretCode = secretCode;
}
/**
* ocr
*
* @param fileContent
* @param options
* @return
* @throws IOException
*/
public static String recognize(byte[] fileContent, HashMap<String, Object> options) throws IOException {
public String OCR(byte[] fileContent, HashMap<String, Object> options) throws IOException {
StringBuilder queryParams = new StringBuilder();
for (Map.Entry<String, Object> entry : options.entrySet()) {
if (queryParams.length() > 0) {
......@@ -55,7 +62,7 @@ public class TextInClient {
.append("=")
.append(URLEncoder.encode(entry.getValue().toString(), "UTF-8"));
}
HttpURLConnection connection = getRecoGinzeHttpURLConnection(queryParams);
HttpURLConnection connection = getOCRHttpURLConnection(queryParams);
try (OutputStream os = connection.getOutputStream()) {
os.write(fileContent);
os.flush();
......@@ -79,7 +86,7 @@ public class TextInClient {
}
private static HttpURLConnection getRecoGinzeHttpURLConnection(StringBuilder queryParams) throws IOException {
private HttpURLConnection getOCRHttpURLConnection(StringBuilder queryParams) throws IOException {
String baseUrl = "https://api.textin.com/ai/service/v1/pdf_to_markdown";
String fullUrl = baseUrl + (queryParams.length() > 0 ? "?" + queryParams : "");
URL url = new URL(fullUrl);
......@@ -102,7 +109,7 @@ public class TextInClient {
* @return
*/
public static String extraction(String fileUrl, List<KeyInfo> keyInfoList) {
public String extraction(String fileUrl, List<KeyInfo> keyInfoList) {
try {
// 读取文件并将其转换为Base64编码
File file = DocumentLoad.downloadURLDocument(fileUrl);
......@@ -166,7 +173,7 @@ public class TextInClient {
* @param taskId
* @return
*/
private static String extractedResults(String taskId) {
private String extractedResults(String taskId) {
String baseUrl = "https://doc-compare.intsig.com/doc_extraction/keyinfo/extracted_results?format=json&task_id=" + taskId;
HttpUriRequest httpUriRequest = RequestBuilder.post()
.setUri(baseUrl)
......
package cn.com.poc.thirdparty.resource.demand.ai.function.text_in_pdf2md.entity;
package cn.com.poc.thirdparty.resource.textin.entity;
/**
* @author alex.yao
......
package cn.com.poc.thirdparty.resource.demand.ai.function.text_in_pdf2md.entity;
package cn.com.poc.thirdparty.resource.textin.entity;
/**
* @author alex.yao
......
package cn.com.poc.thirdparty.resource.demand.ai.function;
import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.thirdparty.resource.demand.ai.function.extraction.ContractExtractionFunction;
import cn.com.poc.thirdparty.resource.demand.ai.function.text_in_pdf2md.api.TextInClient;
import cn.com.poc.thirdparty.resource.textin.api.TextInClient;
import cn.com.yict.framemax.core.spring.SingleContextInitializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -44,7 +43,8 @@ public class PdfToMdFunctionTest {
options.put("parse_mode", "auto");
options.put("table_flavor", "md");
try {
String response = TextInClient.recognize(fileContent, options);
TextInClient textInClient = new TextInClient();
String response = textInClient.OCR(fileContent, options);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(response);
if (jsonNode.has("result") && jsonNode.get("result").has("markdown")) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment