Commit 3f3b2975 authored by alex yao's avatar alex yao

feat:合同信息提取插件

parent dfec90e9
......@@ -10,6 +10,7 @@ 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.hutool.core.collection.ListUtil;
import cn.hutool.json.JSONException;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
......@@ -41,12 +42,14 @@ public class ContractExtractionFunction extends AbstractLargeModelFunction {
@Override
public AbstractFunctionResult<String> doFunction(String content, String identifier) {
AbstractFunctionResult<String> result = new AbstractFunctionResult<>();
String fileUrl;
List<KeyInfo> keyInfos = new ArrayList<>();
if (isJsonArray(content)) {
JSONArray jsonArray = JSONArray.parseArray(content);
if (jsonArray.isEmpty()) {
return result;
}
String fileUrl = jsonArray.getJSONObject(0).getString("file_url");
List<KeyInfo> keyInfos = new ArrayList<>();
fileUrl = jsonArray.getJSONObject(0).getString("file_url");
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
KeyInfo keyInfo = new KeyInfo();
......@@ -64,6 +67,24 @@ public class ContractExtractionFunction extends AbstractLargeModelFunction {
}
keyInfos.add(keyInfo);
}
} else {
JSONObject jsonObject = JSONObject.parseObject(content);
fileUrl = jsonObject.getString("file_url");
KeyInfo keyInfo = new KeyInfo();
if (jsonObject.containsKey("field_type")) {
keyInfo.setField_type(jsonObject.getString("file_type"));
}
if (jsonObject.containsKey("key_info")) {
keyInfo.setKey_info(jsonObject.getString("key_info"));
}
if (jsonObject.containsKey("paraphrase_names")) {
keyInfo.setParaphrase_names(jsonObject.getJSONArray("paraphrase_names").toArray(new String[0]));
}
if (jsonObject.containsKey("keywords")) {
keyInfo.setKeywords(jsonObject.getJSONArray("keywords").toArray(new String[0]));
}
keyInfos.add(keyInfo);
}
TextInClient textInClient = new TextInClient();
String extraction = textInClient.extraction(fileUrl, keyInfos);
......@@ -86,4 +107,13 @@ public class ContractExtractionFunction extends AbstractLargeModelFunction {
public List<String> getLLMConfig(List<Variable> variableStructure) {
return this.getLLMConfig();
}
private boolean isJsonArray(String json) {
try {
new cn.hutool.json.JSONArray(json);
return true;
} catch (JSONException e) {
return false;
}
}
}
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