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; ...@@ -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.extraction.entity.KeyInfo;
import cn.com.poc.thirdparty.resource.demand.ai.function.text_in_pdf2md.api.TextInClient; import cn.com.poc.thirdparty.resource.demand.ai.function.text_in_pdf2md.api.TextInClient;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import cn.hutool.json.JSONException;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -41,14 +42,34 @@ public class ContractExtractionFunction extends AbstractLargeModelFunction { ...@@ -41,14 +42,34 @@ public class ContractExtractionFunction extends AbstractLargeModelFunction {
@Override @Override
public AbstractFunctionResult<String> doFunction(String content, String identifier) { public AbstractFunctionResult<String> doFunction(String content, String identifier) {
AbstractFunctionResult<String> result = new AbstractFunctionResult<>(); AbstractFunctionResult<String> result = new AbstractFunctionResult<>();
JSONArray jsonArray = JSONArray.parseArray(content); String fileUrl;
if (jsonArray.isEmpty()) {
return result;
}
String fileUrl = jsonArray.getJSONObject(0).getString("file_url");
List<KeyInfo> keyInfos = new ArrayList<>(); List<KeyInfo> keyInfos = new ArrayList<>();
for (int i = 0; i < jsonArray.size(); i++) { if (isJsonArray(content)) {
JSONObject jsonObject = jsonArray.getJSONObject(i); JSONArray jsonArray = JSONArray.parseArray(content);
if (jsonArray.isEmpty()) {
return result;
}
fileUrl = jsonArray.getJSONObject(0).getString("file_url");
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
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);
}
} else {
JSONObject jsonObject = JSONObject.parseObject(content);
fileUrl = jsonObject.getString("file_url");
KeyInfo keyInfo = new KeyInfo(); KeyInfo keyInfo = new KeyInfo();
if (jsonObject.containsKey("field_type")) { if (jsonObject.containsKey("field_type")) {
keyInfo.setField_type(jsonObject.getString("file_type")); keyInfo.setField_type(jsonObject.getString("file_type"));
...@@ -86,4 +107,13 @@ public class ContractExtractionFunction extends AbstractLargeModelFunction { ...@@ -86,4 +107,13 @@ public class ContractExtractionFunction extends AbstractLargeModelFunction {
public List<String> getLLMConfig(List<Variable> variableStructure) { public List<String> getLLMConfig(List<Variable> variableStructure) {
return this.getLLMConfig(); 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