Commit c4b4ee9b authored by alex yao's avatar alex yao

feat:优化agent调用流程

parent 964a0b97
......@@ -79,6 +79,8 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
final private Logger logger = LoggerFactory.getLogger(AgentApplicationService.class);
final private ThreadPoolExecutor executor = new ThreadPoolExecutor(16, 64, 10, TimeUnit.SECONDS, new LinkedBlockingDeque<>(100));
@Resource
private BizKnowledgeDocumentService bizKnowledgeDocumentService;
......@@ -139,8 +141,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
// 保存或更新
return StringUtils.isEmpty(entity.getAgentId()) ?
bizAgentApplicationInfoService.save(entity) : bizAgentApplicationInfoService.update(entity);
return StringUtils.isEmpty(entity.getAgentId()) ? bizAgentApplicationInfoService.save(entity) : bizAgentApplicationInfoService.update(entity);
}
@Override
......@@ -201,41 +202,45 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
}
@Override
public AgentResultEntity callAgentApplication(String agentId, String dialogueId, String largeModel, String agentSystem, Integer[] kdIds, Integer[] databaseIds,
Integer communicationTurn, Float topP, Float temperature, List<Message> messages, List<Tool> tools, FunctionCallResult functionCallResult, boolean stream,
Double score, Integer topK, KnowledgeSearchTypeEnum knowledgeSearchType, KnowledgeSuperclassProblemConfig superclassProblemConfig, HttpServletResponse httpServletResponse) throws Exception {
String model = modelConvert(largeModel);
Tool[] toolArray = tools.toArray(new Tool[0]);
ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 2, 10, TimeUnit.SECONDS, new LinkedBlockingDeque<>(2));
try {
// 使用 CompletableFuture 来异步执行任务并处理可能的异常
CompletableFuture<List<DBChainResult>> dbChainResultsFuture = CompletableFuture.supplyAsync(() -> database(messages, databaseIds), executor);
CompletableFuture<List<KnowledgeContentResult>> knowledgeResultFuture = CompletableFuture.supplyAsync(() -> knowledge(kdIds, messages, topK, score, knowledgeSearchType), executor);
// 等待所有任务完成并获取结果
CompletableFuture.allOf(dbChainResultsFuture, knowledgeResultFuture).join();
List<DBChainResult> dbChainResults = dbChainResultsFuture.join();
List<KnowledgeContentResult> knowledgeResult = knowledgeResultFuture.join();
public AgentResultEntity callAgentApplication(String agentId, String dialogueId, String largeModel, String agentSystem, Integer[] kdIds, Integer[] databaseIds, Integer communicationTurn, Float topP, Float temperature, List<Message> messages, List<Tool> tools, FunctionCallResult functionCallResult, boolean stream, Double score, Integer topK, KnowledgeSearchTypeEnum knowledgeSearchType, KnowledgeSuperclassProblemConfig superclassProblemConfig, HttpServletResponse httpServletResponse) throws Exception {
// 使用 CompletableFuture 来异步执行任务并处理可能的异常
CompletableFuture<FunctionResult> functionResultFuture = CompletableFuture.
supplyAsync(() -> functionCall(dialogueId, functionCallResult, agentId), executor)
.exceptionally(ex -> {
logger.error("functionCall error", ex);
return new FunctionResult();
});
CompletableFuture<List<DBChainResult>> dbChainResultsFuture = CompletableFuture
.supplyAsync(() -> database(messages, databaseIds), executor)
.exceptionally(ex -> {
logger.error("database chain error", ex);
return (List<DBChainResult>) CollectionUtils.EMPTY_COLLECTION;
});
CompletableFuture<List<KnowledgeContentResult>> knowledgeResultFuture = CompletableFuture
.supplyAsync(() -> knowledge(kdIds, messages, topK, score, knowledgeSearchType), executor)
.exceptionally(ex -> {
logger.error("knowledge chain error", ex);
return (List<KnowledgeContentResult>) CollectionUtils.EMPTY_COLLECTION;
});
// 等待所有任务完成并获取结果
CompletableFuture.allOf(functionResultFuture, dbChainResultsFuture, knowledgeResultFuture).join();
FunctionResult functionResult = functionResultFuture.join();
List<DBChainResult> dbChainResults = dbChainResultsFuture.join();
List<KnowledgeContentResult> knowledgeResult = knowledgeResultFuture.join();
if (superclassProblem(superclassProblemConfig, kdIds, knowledgeResult)) {
return sendProblemMess(stream, superclassProblemConfig, httpServletResponse);
if (superclassProblem(superclassProblemConfig, kdIds, knowledgeResult)) {
return sendProblemMess(stream, superclassProblemConfig, httpServletResponse);
} else {
FunctionResult functionResult = functionCall(dialogueId, functionCallResult, agentId);
} else {
String promptTemplate = buildDialogsPrompt(functionResult, agentSystem, toolArray, dialogueId, agentId, knowledgeResult, dbChainResults);
String promptTemplate = buildDialogsPrompt(functionResult, agentSystem, tools.toArray(new Tool[0]), dialogueId, agentId, knowledgeResult, dbChainResults);
Message[] messageArray = buildMessages(messages, communicationTurn, promptTemplate);
Message[] messageArray = buildMessages(messages, communicationTurn, promptTemplate);
return llmExecutorAndOutput(topP, stream, model, messageArray, functionResult, knowledgeResult, dbChainResults, httpServletResponse);
}
} finally {
executor.shutdown();
return llmExecutorAndOutput(topP, stream, modelConvert(largeModel), messageArray, functionResult, knowledgeResult, dbChainResults, httpServletResponse);
}
}
......@@ -424,9 +429,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
baiduAISailsText2ImageRequest.setAcctId(null);
BaiduAISailsText2ImageResult baiduAISailsText2ImageResult = aiCreateImageService.executeSailsText2Image(baiduAISailsText2ImageRequest);
if (baiduAISailsText2ImageResult == null
|| CollectionUtils.isEmpty(baiduAISailsText2ImageResult.getData())
|| StringUtils.isEmpty(baiduAISailsText2ImageResult.getData().get(0).getUrl())) {
if (baiduAISailsText2ImageResult == null || CollectionUtils.isEmpty(baiduAISailsText2ImageResult.getData()) || StringUtils.isEmpty(baiduAISailsText2ImageResult.getData().get(0).getUrl())) {
logger.error("create agent icon error, baiduAISailsText2ImageRequest:{} ", baiduAISailsText2ImageRequest);
throw new I18nMessageException("exception/failed.to.create.[avatar].please.try.again.later");
}
......@@ -644,9 +647,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
* @return 输出结果
* @throws Exception
*/
private AgentResultEntity llmExecutorAndOutput(Float topP, boolean stream, String model, Message[] messageArray,
FunctionResult functionResult, List<KnowledgeContentResult> knowledgeResult, List<DBChainResult> dbChainResults,
HttpServletResponse httpServletResponse) throws Exception {
private AgentResultEntity llmExecutorAndOutput(Float topP, boolean stream, String model, Message[] messageArray, FunctionResult functionResult, List<KnowledgeContentResult> knowledgeResult, List<DBChainResult> dbChainResults, HttpServletResponse httpServletResponse) throws Exception {
if (stream) {
SSEUtil sseUtil = new SSEUtil(httpServletResponse);
if (ObjectUtil.isNotNull(functionResult) && StringUtils.isNotBlank(functionResult.getFunctionName())) {
......@@ -703,8 +704,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
}
//若 name desc 其中一项不为空则入参 不传入prompt
if (StringUtils.isNotBlank(agentTitle) || (StringUtils.isNotBlank(agentDesc))) {
return configSystem.replace("${agent_title}", StringUtils.isNotBlank(agentTitle) ? agentTitle : StringUtils.EMPTY)
.replace("${agent_desc}", StringUtils.isNotBlank(agentDesc) ? agentDesc : StringUtils.EMPTY);
return configSystem.replace("${agent_title}", StringUtils.isNotBlank(agentTitle) ? agentTitle : StringUtils.EMPTY).replace("${agent_desc}", StringUtils.isNotBlank(agentDesc) ? agentDesc : StringUtils.EMPTY);
}
// 若 name desc 都空 prompt 有内容,则把prompt 传入desc
......@@ -726,9 +726,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
* @param dbChainResults 数据库链结果
* @return
*/
private String buildDialogsPrompt(FunctionResult functionResult, String agentSystem,
Tool[] tools, String dialogueId, String agentId,
List<KnowledgeContentResult> knowledgeContentResults, List<DBChainResult> dbChainResults) {
private String buildDialogsPrompt(FunctionResult functionResult, String agentSystem, Tool[] tools, String dialogueId, String agentId, List<KnowledgeContentResult> knowledgeContentResults, List<DBChainResult> dbChainResults) {
String promptTemplate = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_BASE_SYSTEM).getConfigSystem();
// 系统语言
String language = "";
......@@ -757,10 +755,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
StringBuilder dbChainPromptBuilder = new StringBuilder("");
if (CollectionUtils.isNotEmpty(dbChainResults)) {
for (int i = 1; i <= dbChainResults.size(); i++) {
dbChainPromptBuilder.append("### DBChain Result ").append(i).append(":")
.append(StringUtils.LF)
.append(dbChainResults.get(i - 1).getResult())
.append(StringUtils.LF);
dbChainPromptBuilder.append("### DBChain Result ").append(i).append(":").append(StringUtils.LF).append(dbChainResults.get(i - 1).getResult()).append(StringUtils.LF);
}
}
promptTemplate = promptTemplate.replace("${databaseResult}", dbChainPromptBuilder.toString());
......@@ -777,10 +772,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
StringBuilder knowledgePromptBuilder = new StringBuilder("");
if (CollectionUtils.isNotEmpty(knowledgeContentResults)) {
for (int i = 1; i <= knowledgeContentResults.size(); i++) {
knowledgePromptBuilder.append("### Chunk ").append(i).append(":")
.append(StringUtils.LF)
.append(knowledgeContentResults.get(i - 1).getContent())
.append(StringUtils.LF);
knowledgePromptBuilder.append("### Chunk ").append(i).append(":").append(StringUtils.LF).append(knowledgeContentResults.get(i - 1).getContent()).append(StringUtils.LF);
}
}
promptTemplate = promptTemplate.replace("${knowledgeResults}", knowledgePromptBuilder.toString());
......@@ -808,11 +800,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
if (CollectionUtils.isNotEmpty(longMemoryEntities)) {
StringBuilder stringBuilder = new StringBuilder("");
for (AgentLongMemoryEntity agentLongMemoryEntity : longMemoryEntities) {
stringBuilder
.append("Time").append(":").append(agentLongMemoryEntity.getTimestamp())
.append(StringUtils.SPACE)
.append("Content").append(":").append(agentLongMemoryEntity.getContent())
.append(StringUtils.LF);
stringBuilder.append("Time").append(":").append(agentLongMemoryEntity.getTimestamp()).append(StringUtils.SPACE).append("Content").append(":").append(agentLongMemoryEntity.getContent()).append(StringUtils.LF);
}
longMemoryContent = stringBuilder.toString();
}
......@@ -844,10 +832,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
*/
private String buildFunctionPrompt(FunctionResult functionResult, String promptTemplate) {
if (functionResult != null) {
promptTemplate = promptTemplate.replace("${functionName}", StringUtils.isNotBlank(functionResult.getFunctionName()) ? functionResult.getFunctionName() : StringUtils.EMPTY)
.replace("${functionArg}", StringUtils.isNotBlank(functionResult.getFunctionArg()) ? functionResult.getFunctionArg() : StringUtils.EMPTY)
.replace("${functionDesc}", StringUtils.isNotBlank(functionResult.getFunctionDesc()) ? functionResult.getFunctionDesc() : StringUtils.EMPTY)
.replace("${functionResult}", StringUtils.isNotBlank(functionResult.getPromptContent()) ? functionResult.getPromptContent() : StringUtils.EMPTY);
promptTemplate = promptTemplate.replace("${functionName}", StringUtils.isNotBlank(functionResult.getFunctionName()) ? functionResult.getFunctionName() : StringUtils.EMPTY).replace("${functionArg}", StringUtils.isNotBlank(functionResult.getFunctionArg()) ? functionResult.getFunctionArg() : StringUtils.EMPTY).replace("${functionDesc}", StringUtils.isNotBlank(functionResult.getFunctionDesc()) ? functionResult.getFunctionDesc() : StringUtils.EMPTY).replace("${functionResult}", StringUtils.isNotBlank(functionResult.getPromptContent()) ? functionResult.getPromptContent() : StringUtils.EMPTY);
}
return promptTemplate;
}
......@@ -897,9 +882,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
* @param httpServletResponse
* @throws IOException
*/
private AgentResultEntity textOutput(HttpServletResponse httpServletResponse, LargeModelDemandResult
largeModelDemandResult) throws
IOException {
private AgentResultEntity textOutput(HttpServletResponse httpServletResponse, LargeModelDemandResult largeModelDemandResult) throws IOException {
PrintWriter writer = httpServletResponse.getWriter();
writer.write(JsonUtils.serialize(largeModelDemandResult));
writer.flush();
......@@ -1076,7 +1059,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
/**
* 获取模型
*
* @param largeModel
* @param largeModel 模型名称
* @return
*/
private String modelConvert(String largeModel) {
......@@ -1090,51 +1073,10 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
/**
* 判断是否需要FunctionCall
*
* @param dialogueId
* @param messages
* @param tools
* @param agentId
* @param fileUrls
* @param imageUrls
* @param dialogueId 对话id
* @param functionCallResult 函数调用结果
* @param agentId 应用id
*/
private FunctionResult functionCall(String dialogueId, List<Message> messages, Tool[] tools, String
agentId, List<String> fileUrls, List<String> imageUrls) {
FunctionResult result = new FunctionResult();
if (ArrayUtils.isEmpty(tools)) {
return result;
}
Object content = messages.get(messages.size() - 1).getContent();
String query;
if (content instanceof List) {
query = ((List<HashMap>) content).get(0).get("text").toString();
} else {
query = content.toString();
}
query = "用户输入:" + query + "\n";
if (CollectionUtils.isNotEmpty(fileUrls)) {
query = query + "用户上传文件地址:" + JsonUtils.serialize(fileUrls) + "\n";
}
if (CollectionUtils.isNotEmpty(imageUrls)) {
query = query + "用户上传图片地址:" + JsonUtils.serialize(imageUrls);
}
FunctionCallResult functionCallResult = llmService.functionCall(query, tools);
if (functionCallResult != null && functionCallResult.isNeed()) {
// 执行函数返回结果
LargeModelFunctionEnum functionEnum = LargeModelFunctionEnum.valueOf(functionCallResult.getFunctionCall().getName());
AbstractFunctionResult abstractFunctionResult = functionEnum.getFunction().doFunction(functionCallResult.getFunctionCall().getArguments(), AgentApplicationTools.identifier(dialogueId, agentId));
//构造返回结果
result.setFunctionName(functionCallResult.getFunctionCall().getName());
result.setFunctionArg(functionCallResult.getFunctionCall().getArguments());
result.setFunctionDesc(functionEnum.getFunction().getDesc());
result.setFunctionResult(abstractFunctionResult.getFunctionResult());
result.setPromptContent(abstractFunctionResult.getPromptContent());
}
return result;
}
private FunctionResult functionCall(String dialogueId, FunctionCallResult functionCallResult, String agentId) {
FunctionResult result = new FunctionResult();
if (functionCallResult != null && functionCallResult.isNeed()) {
......@@ -1328,9 +1270,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
private boolean superclassProblem(KnowledgeSuperclassProblemConfig superclassProblemConfig, Integer[] kdIds, List<KnowledgeContentResult> knowledgeContentResult) {
if (ArrayUtils.isNotEmpty(kdIds) && CollectionUtils.isEmpty(knowledgeContentResult)) {
String knowledgeResponseType = superclassProblemConfig.getKnowledgeResponseType();
if (AgentApplicationKnowledgeConstants.SUPER_CLASS_PROBLEM_TYPE.CUSTOM.equals(knowledgeResponseType)
&& ArrayUtils.isNotEmpty(superclassProblemConfig.getKnowledgeCustomResponse())
&& StringUtils.isNotBlank(superclassProblemConfig.getKnowledgeCustomResponse()[0])) {
if (AgentApplicationKnowledgeConstants.SUPER_CLASS_PROBLEM_TYPE.CUSTOM.equals(knowledgeResponseType) && ArrayUtils.isNotEmpty(superclassProblemConfig.getKnowledgeCustomResponse()) && StringUtils.isNotBlank(superclassProblemConfig.getKnowledgeCustomResponse()[0])) {
return true;
}
}
......
......@@ -5,6 +5,7 @@ package cn.com.poc.thirdparty.resource.demand.ai.function.extraction.entity;
* @date 2025/5/12
*/
public class RequestData {
public Integer token_mode;
public String creator;
public Config config;
public String filedata;
......@@ -12,6 +13,7 @@ public class RequestData {
public KeyInfo[] key_info_list;
public RequestData(String creator, Config config, String filedata, String filename, KeyInfo[] key_info_list) {
token_mode = 1;
this.creator = creator;
this.config = config;
this.filedata = filedata;
......
......@@ -63,9 +63,8 @@ public class PdfToMDFunction extends AbstractLargeModelFunction {
options.put("paratext_mode", "annotation");
options.put("parse_mode", "auto");
options.put("table_flavor", "md");
TextInClient client = new TextInClient();
try {
String response = client.recognize(fileContent, options);
String response = TextInClient.recognize(fileContent, options);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(response);
if (jsonNode.has("result") && jsonNode.get("result").has("markdown")) {
......
......@@ -6,12 +6,16 @@ package cn.com.poc.thirdparty.resource.demand.ai.function.text_in_pdf2md.api;
*/
import cn.com.poc.common.utils.DocumentLoad;
import cn.com.poc.common.utils.http.LocalHttpClient;
import cn.com.poc.thirdparty.resource.demand.ai.function.extraction.entity.Config;
import cn.com.poc.thirdparty.resource.demand.ai.function.extraction.entity.KeyInfo;
import cn.com.poc.thirdparty.resource.demand.ai.function.extraction.entity.RequestData;
import cn.com.yict.framemax.core.exception.BusinessException;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.jetbrains.annotations.NotNull;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -21,8 +25,6 @@ import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
......@@ -30,14 +32,20 @@ import java.util.Map;
public class TextInClient {
private Logger logger = LoggerFactory.getLogger(TextInClient.class);
private final String appId = "a595e68578ff9a853c3d60a879157547";
private final String secretCode = "d723d69522c92ff59a3e48b37ac3df79";
final private static Logger logger = LoggerFactory.getLogger(TextInClient.class);
final private static String appId = "a595e68578ff9a853c3d60a879157547";
final private static String secretCode = "d723d69522c92ff59a3e48b37ac3df79";
public TextInClient() {
}
public String recognize(byte[] fileContent, HashMap<String, Object> options) throws IOException {
/**
* @param fileContent
* @param options
* @return
* @throws IOException
*/
public static String recognize(byte[] fileContent, HashMap<String, Object> options) throws IOException {
StringBuilder queryParams = new StringBuilder();
for (Map.Entry<String, Object> entry : options.entrySet()) {
if (queryParams.length() > 0) {
......@@ -70,7 +78,31 @@ public class TextInClient {
}
}
public String extraction(String fileUrl, List<KeyInfo> keyInfoList) {
private static HttpURLConnection getRecoGinzeHttpURLConnection(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);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("x-ti-app-id", appId);
connection.setRequestProperty("x-ti-secret-code", secretCode);
connection.setRequestProperty("Content-Type", "text/plain;charset=utf-8");
connection.setDoOutput(true);
return connection;
}
/**
* 【合同抽取】-创建抽取
* https://www.textin.com/document/doc_extraction_create
*
* @param fileUrl
* @param keyInfoList
* @return
*/
public static String extraction(String fileUrl, List<KeyInfo> keyInfoList) {
try {
// 读取文件并将其转换为Base64编码
File file = DocumentLoad.downloadURLDocument(fileUrl);
......@@ -96,7 +128,7 @@ public class TextInClient {
connection.setRequestMethod("POST");
connection.setRequestProperty("x-ti-app-id", appId);
connection.setRequestProperty("x-ti-secret-code", secretCode);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Content-Type", "application/json;charset=utf-8");
connection.setDoOutput(true); // 开启输出流
// 发送请求数据
......@@ -117,26 +149,40 @@ public class TextInClient {
response.append(inputLine);
}
// 输出响应内容
return response.toString();
logger.info("Response: {}", response);
JSONObject jsonResponse = JSONObject.parseObject(response.toString());
String taskId = jsonResponse.getJSONObject("result").getString("task_id");
return extractedResults(taskId);
}
} catch (IOException e) {
throw new BusinessException(e);
}
}
private HttpURLConnection getRecoGinzeHttpURLConnection(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);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("x-ti-app-id", appId);
connection.setRequestProperty("x-ti-secret-code", secretCode);
connection.setRequestProperty("Content-Type", "text/plain;charset=utf-8");
connection.setDoOutput(true);
return connection;
/**
* 【合同抽取】 -获取抽取结果
* https://www.textin.com/document/doc_extraction_result
*
* @param taskId
* @return
*/
private static 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)
.addHeader("x-ti-app-id", appId)
.addHeader("x-ti-secret-code", secretCode)
.addHeader("Content-Type", "application/json;charset=utf-8")
.build();
String result = LocalHttpClient.executeJsonResult(httpUriRequest, String.class);
JSONObject resultJson = JSONObject.parseObject(result);
Integer code = resultJson.getInteger("code");
if (code.equals(200)) {
return resultJson.getJSONObject("result").toJSONString();
} else {
logger.error("获取token失败,错误码:{}", code);
return StringUtils.EMPTY;
}
}
}
\ No newline at end of file
......@@ -43,19 +43,18 @@ public class PdfToMdFunctionTest {
options.put("paratext_mode", "annotation");
options.put("parse_mode", "auto");
options.put("table_flavor", "md");
TextInClient client = new TextInClient();
try {
String response = client.recognize(fileContent, options);
String response = TextInClient.recognize(fileContent, options);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(response);
if (jsonNode.has("result") && jsonNode.get("result").has("markdown")) {
String markdown = jsonNode.get("result").get("markdown").asText();
System.out.println(markdown);
}else{
} else {
System.out.println(response);
}
} catch (Exception e) {
System.out.println("1111111");
e.printStackTrace();
}
}
......
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