Commit d13fe95e authored by R10's avatar R10

智写-文书写作模板-模板对话结果放回

parent aa0fda4b
package cn.com.poc.law.ExtractEntityStrategy.ExtractEntityType; package cn.com.poc.law.ExtractEntityStrategy.ExtractEntityType;
import cn.com.poc.agent_application.entity.BizAgentApplicationDialoguesRecordEntity;
import cn.com.poc.agent_application.entity.BizAgentApplicationGcConfigEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationGcConfigEntity;
import cn.com.poc.agent_application.entity.KnowledgeContentResult;
import cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService; import cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService;
import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.utils.DocumentLoad; import cn.com.poc.common.utils.DocumentLoad;
import cn.com.poc.common.utils.JsonUtils; import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.law.ExtractEntityStrategy.ExtractEntityStrategy; import cn.com.poc.law.ExtractEntityStrategy.ExtractEntityStrategy;
...@@ -12,12 +9,11 @@ import cn.com.poc.law.dto.LegalTemplateDto; ...@@ -12,12 +9,11 @@ import cn.com.poc.law.dto.LegalTemplateDto;
import cn.com.poc.law.entity.*; import cn.com.poc.law.entity.*;
import cn.com.poc.thirdparty.resource.demand.ai.constants.LLMRoleEnum; import cn.com.poc.thirdparty.resource.demand.ai.constants.LLMRoleEnum;
import cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Message; import cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Message;
import cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.ToolFunction; import cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelDemandResult;
import cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelResponse; import cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelResponse;
import cn.com.poc.thirdparty.service.LLMService; import cn.com.poc.thirdparty.service.LLMService;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -53,11 +49,17 @@ public class MotorVehicleDrivingComplaint implements ExtractEntityStrategy { ...@@ -53,11 +49,17 @@ public class MotorVehicleDrivingComplaint implements ExtractEntityStrategy {
@Override @Override
public LegalTemplateDto extractEntity(String input) throws ExecutionException, InterruptedException { public LegalTemplateDto extractEntity(String input) throws ExecutionException, InterruptedException {
// CompletableFuture<Plaintiff> extractPlaintiffFuture = CompletableFuture CompletableFuture<Plaintiff> extractPlaintiffFuture = CompletableFuture
// .supplyAsync(() -> extractPlaintiff(input), executor) .supplyAsync(() -> {
// .exceptionally(ex -> { try {
// return new Plaintiff(); return extractPlaintiff(input);
// }); } catch (Exception e) {
throw new RuntimeException(e);
}
}, executor)
.exceptionally(ex -> {
return new Plaintiff();
});
// //
CompletableFuture<PlaintiffOrg> extractPlaintiffOrgFuture = CompletableFuture CompletableFuture<PlaintiffOrg> extractPlaintiffOrgFuture = CompletableFuture
.supplyAsync(() -> { .supplyAsync(() -> {
...@@ -71,164 +73,476 @@ public class MotorVehicleDrivingComplaint implements ExtractEntityStrategy { ...@@ -71,164 +73,476 @@ public class MotorVehicleDrivingComplaint implements ExtractEntityStrategy {
return new PlaintiffOrg(); return new PlaintiffOrg();
}); });
// //
// CompletableFuture<Agent> extractAgentFuture = CompletableFuture CompletableFuture<Agent> extractAgentFuture = CompletableFuture
// .supplyAsync(() -> extractAgent(input), executor) .supplyAsync(() -> {
// .exceptionally(ex -> { try {
// return new Agent(); return extractAgent(input);
// }); } catch (Exception e) {
// throw new RuntimeException(e);
// CompletableFuture<Defendant> extractDefendantFuture = CompletableFuture }
// .supplyAsync(() -> extractDefendant(input), executor) }, executor)
// .exceptionally(ex -> { .exceptionally(ex -> {
// return new Defendant(); return new Agent();
// }); });
// CompletableFuture<DefendantOrg> extractDefendantOrgFuture = CompletableFuture CompletableFuture<Defendant> extractDefendantFuture = CompletableFuture
// .supplyAsync(() -> { .supplyAsync(() -> {
// try { try {
// return extractDefendantOrg(input); return extractDefendant(input);
// } catch (Exception e) { } catch (Exception e) {
// throw new RuntimeException(e); throw new RuntimeException(e);
// } }
// }, executor) }, executor)
// .exceptionally(ex -> { .exceptionally(ex -> {
// return new DefendantOrg(); return new Defendant();
// }); });
// CompletableFuture<ThirdParty> extractThirdPartyFuture = CompletableFuture CompletableFuture<DefendantOrg> extractDefendantOrgFuture = CompletableFuture
// .supplyAsync(() -> extractThirdParty(input), executor)
// .exceptionally(ex -> { .supplyAsync(() -> {
// return new ThirdParty(); try {
// }); return extractDefendantOrg(input);
// } catch (Exception e) {
// CompletableFuture<ThirdPartyOrg> extractThirdPartyOrgFuture = CompletableFuture throw new RuntimeException(e);
// .supplyAsync(() -> extractThirdPartyOrg(input), executor) }
// .exceptionally(ex -> { }, executor)
// return new ThirdPartyOrg(); .exceptionally(ex -> {
// }); return new DefendantOrg();
// });
// CompletableFuture<Claim> extractClaimFuture = CompletableFuture
// .supplyAsync(() -> extractClaim(input), executor)
// .exceptionally(ex -> { CompletableFuture<ThirdParty> extractThirdPartyFuture = CompletableFuture
// return new Claim(); .supplyAsync(() -> {
// }); try {
// return extractThirdParty(input);
// CompletableFuture<Preservation> extractPreservationFuture = CompletableFuture } catch (Exception e) {
// .supplyAsync(() -> extractPreservation(input), executor) throw new RuntimeException(e);
// .exceptionally(ex -> { }
// return new Preservation(); }, executor)
// }); .exceptionally(ex -> {
// return new ThirdParty();
// CompletableFuture<FactsAndReasons> extractFactsAndReasonsFuture = CompletableFuture });
// .supplyAsync(() -> extractFactsAndReasons(input), executor)
// .exceptionally(ex -> { CompletableFuture<ThirdPartyOrg> extractThirdPartyOrgFuture = CompletableFuture
// return new FactsAndReasons(); .supplyAsync(() -> {
// }); try {
// return extractThirdPartyOrg(input);
// CompletableFuture<UnderstandsMediationBenefit> extractUnderstandsMediationBenefitFuture = CompletableFuture } catch (Exception e) {
// .supplyAsync(() -> extractUnderstandsMediationBenefit(input), executor) throw new RuntimeException(e);
// .exceptionally(ex -> { }
// return new UnderstandsMediationBenefit(); }, executor)
// }); .exceptionally(ex -> {
return new ThirdPartyOrg();
});
CompletableFuture<Claim> extractClaimFuture = CompletableFuture
.supplyAsync(() -> {
try {
return extractClaim(input);
} catch (Exception e) {
throw new RuntimeException(e);
}
}, executor)
.exceptionally(ex -> {
return new Claim();
});
CompletableFuture<Preservation> extractPreservationFuture = CompletableFuture
.supplyAsync(() -> {
try {
return extractPreservation(input);
} catch (Exception e) {
throw new RuntimeException(e);
}
}, executor)
.exceptionally(ex -> {
return new Preservation();
});
CompletableFuture<FactsAndReasons> extractFactsAndReasonsFuture = CompletableFuture
.supplyAsync(() -> {
try {
return extractFactsAndReasons(input);
} catch (Exception e) {
throw new RuntimeException(e);
}
}, executor)
.exceptionally(ex -> {
return new FactsAndReasons();
});
CompletableFuture<UnderstandsMediationBenefit> extractUnderstandsMediationBenefitFuture = CompletableFuture
.supplyAsync(() -> {
try {
return extractUnderstandsMediationBenefit(input);
} catch (Exception e) {
throw new RuntimeException(e);
}
}, executor)
.exceptionally(ex -> {
return new UnderstandsMediationBenefit();
});
// 等待所有任务完成并获取结果 // 等待所有任务完成并获取结果
// CompletableFuture.allOf(extractPlaintiffFuture, extractPlaintiffOrgFuture, extractAgentFuture, extractDefendantFuture, extractDefendantOrgFuture, CompletableFuture.allOf(extractPlaintiffFuture, extractPlaintiffOrgFuture, extractAgentFuture, extractDefendantFuture, extractDefendantOrgFuture,
// extractThirdPartyFuture, extractThirdPartyOrgFuture, extractClaimFuture, extractPreservationFuture, extractFactsAndReasonsFuture, extractUnderstandsMediationBenefitFuture).join(); extractThirdPartyFuture, extractThirdPartyOrgFuture, extractClaimFuture, extractPreservationFuture, extractFactsAndReasonsFuture, extractUnderstandsMediationBenefitFuture).join();
// //
// Plaintiff extractPlaintiffResults = extractPlaintiffFuture.get(); Plaintiff extractPlaintiffResults = extractPlaintiffFuture.get();
PlaintiffOrg extractPlaintiffOrgResults = extractPlaintiffOrgFuture.get(); PlaintiffOrg extractPlaintiffOrgResults = extractPlaintiffOrgFuture.get();
// Agent extractAgentResults = extractAgentFuture.get(); Agent extractAgentResults = extractAgentFuture.get();
// Defendant extractDefendantResult = extractDefendantFuture.get(); Defendant extractDefendantResult = extractDefendantFuture.get();
// DefendantOrg extractDefendantOrgResult = extractDefendantOrgFuture.get(); DefendantOrg extractDefendantOrgResult = extractDefendantOrgFuture.get();
// ThirdParty extractThirdPartyResult = extractThirdPartyFuture.get(); ThirdParty extractThirdPartyResult = extractThirdPartyFuture.get();
// ThirdPartyOrg extractThirdPartyOrgResult = extractThirdPartyOrgFuture.get(); ThirdPartyOrg extractThirdPartyOrgResult = extractThirdPartyOrgFuture.get();
// Claim extractClaimResult = extractClaimFuture.get(); Claim extractClaimResult = extractClaimFuture.get();
// Preservation preservationResult = extractPreservationFuture.get(); Preservation preservationResult = extractPreservationFuture.get();
// FactsAndReasons FactsAndReasonsResult = extractFactsAndReasonsFuture.get(); FactsAndReasons factsAndReasonsResult = extractFactsAndReasonsFuture.get();
// UnderstandsMediationBenefit UnderstandsMediationBenefitResult = extractUnderstandsMediationBenefitFuture.get(); UnderstandsMediationBenefit UnderstandsMediationBenefitResult = extractUnderstandsMediationBenefitFuture.get();
MotorVehicleDrivingComplaintEntity motorVehicleDrivingComplaintEntity = new MotorVehicleDrivingComplaintEntity(); MotorVehicleDrivingComplaintEntity motorVehicleDrivingComplaintEntity = new MotorVehicleDrivingComplaintEntity();
motorVehicleDrivingComplaintEntity.setPlaintiff(extractPlaintiffResults);
motorVehicleDrivingComplaintEntity.setPlaintiffOrg(extractPlaintiffOrgResults); motorVehicleDrivingComplaintEntity.setPlaintiffOrg(extractPlaintiffOrgResults);
motorVehicleDrivingComplaintEntity.setAgent(extractAgentResults);
motorVehicleDrivingComplaintEntity.setDefendant(extractDefendantResult);
motorVehicleDrivingComplaintEntity.setDefendantOrg(extractDefendantOrgResult);
motorVehicleDrivingComplaintEntity.setThirdParty(extractThirdPartyResult);
motorVehicleDrivingComplaintEntity.setThirdPartyOrg(extractThirdPartyOrgResult);
motorVehicleDrivingComplaintEntity.setClaim(extractClaimResult);
motorVehicleDrivingComplaintEntity.setPreservation(preservationResult);
motorVehicleDrivingComplaintEntity.setFactsAndReasons(factsAndReasonsResult);
motorVehicleDrivingComplaintEntity.setUnderstandsMediationBenefit(UnderstandsMediationBenefitResult);
return motorVehicleDrivingComplaintEntity; return motorVehicleDrivingComplaintEntity;
} }
private Plaintiff extractPlaintiff(String input) throws Exception {
// 获取对话提示词
String promptCode = "AILawyerWritingPromptPlaintiff";
BizAgentApplicationGcConfigEntity documentDialoguePrompt = bizAgentApplicationGcConfigService.getByConfigCode(promptCode);
if (documentDialoguePrompt == null || StringUtils.isBlank(documentDialoguePrompt.getConfigSystem())) {
throw new BusinessException("获取对话提示词失败");
}
String prompt = documentDialoguePrompt.getConfigSystem().replace("${input}", input);
//组装请求参数
List<Message> messages = buildMessages(input, null, prompt);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel("deepseek-v3");//获取模型);
largeModelResponse.setMessages(messages.toArray(new Message[0]));
largeModelResponse.setStream(false);
LargeModelDemandResult chat = llmService.chat(largeModelResponse);
Plaintiff plaintiff = new Plaintiff();
if (ObjectUtil.isEmpty(chat) || !chat.getCode().equals("0")) {
throw new BusinessException("获取失败");
}
String message = chat.getMessage().replaceAll("```json",StringUtils.EMPTY).replaceAll("```",StringUtils.EMPTY);
plaintiff = JsonUtils.deSerialize(message, Plaintiff.class);
if (ObjectUtil.isEmpty(plaintiff)) {
throw new BusinessException("提取失败");
}
return plaintiff;
}
private PlaintiffOrg extractPlaintiffOrg(String input) throws Exception { private PlaintiffOrg extractPlaintiffOrg(String input) throws Exception {
// 获取对话提示词
String promptCode = "AILawyerWritingPromptPlaintiffOrg";
BizAgentApplicationGcConfigEntity documentDialoguePrompt = bizAgentApplicationGcConfigService.getByConfigCode(promptCode);
if (documentDialoguePrompt == null || StringUtils.isBlank(documentDialoguePrompt.getConfigSystem())) {
throw new BusinessException("获取对话提示词失败");
}
String prompt = documentDialoguePrompt.getConfigSystem().replace("${input}", input);
//组装请求参数 //组装请求参数
List<Message> messages = buildMessages(null, null, input, null, null, null); List<Message> messages = buildMessages(input, null, prompt);
LargeModelResponse largeModelResponse = new LargeModelResponse(); LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel("deepseek-v3");//获取模型); largeModelResponse.setModel("deepseek-v3");//获取模型);
largeModelResponse.setMessages(messages.toArray(new Message[0])); largeModelResponse.setMessages(messages.toArray(new Message[0]));
largeModelResponse.setStream(true); largeModelResponse.setStream(false);
BufferedReader bufferedReader = llmService.chatChunk(largeModelResponse); LargeModelDemandResult chat = llmService.chat(largeModelResponse);
String res; PlaintiffOrg plaintiffOrg = new PlaintiffOrg();
PlaintiffOrg result = null; if (ObjectUtil.isEmpty(chat) || !chat.getCode().equals("0")) {
while ((res = bufferedReader.readLine()) != null) { throw new BusinessException("获取失败");
if (StringUtils.isEmpty(res)) { }
continue; String message = chat.getMessage().replaceAll("```json",StringUtils.EMPTY).replaceAll("```",StringUtils.EMPTY);
} plaintiffOrg = JsonUtils.deSerialize(message, PlaintiffOrg.class);
res = res.replace("data: ", StringUtils.EMPTY); if (ObjectUtil.isEmpty(plaintiffOrg)) {
result = JsonUtils.deSerialize(res, PlaintiffOrg.class);
if (ObjectUtil.isEmpty(result)) {
throw new BusinessException("提取失败"); throw new BusinessException("提取失败");
} }
return plaintiffOrg;
} }
bufferedReader.close();
return result;
private Agent extractAgent(String input) throws Exception {
// 获取对话提示词
String promptCode = "AILawyerWritingPromptAgent";
BizAgentApplicationGcConfigEntity documentDialoguePrompt = bizAgentApplicationGcConfigService.getByConfigCode(promptCode);
if (documentDialoguePrompt == null || StringUtils.isBlank(documentDialoguePrompt.getConfigSystem())) {
throw new BusinessException("获取对话提示词失败");
} }
private Defendant extractDefendant(String input) { String prompt = documentDialoguePrompt.getConfigSystem().replace("${input}", input);
return null;
//组装请求参数
List<Message> messages = buildMessages(input, null, prompt);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel("deepseek-v3");//获取模型);
largeModelResponse.setMessages(messages.toArray(new Message[0]));
largeModelResponse.setStream(false);
LargeModelDemandResult chat = llmService.chat(largeModelResponse);
Agent agent = new Agent();
if (ObjectUtil.isEmpty(chat) || !chat.getCode().equals("0")) {
throw new BusinessException("获取失败");
}
String message = chat.getMessage().replaceAll("```json",StringUtils.EMPTY).replaceAll("```",StringUtils.EMPTY);
agent = JsonUtils.deSerialize(message, Agent.class);
if (ObjectUtil.isEmpty(agent)) {
throw new BusinessException("提取失败");
}
return agent;
} }
private ThirdParty extractThirdParty(String input) {
return null;
private Defendant extractDefendant(String input) throws Exception {
// 获取对话提示词
String promptCode = "AILawyerWritingPromptDefendant";
BizAgentApplicationGcConfigEntity documentDialoguePrompt = bizAgentApplicationGcConfigService.getByConfigCode(promptCode);
if (documentDialoguePrompt == null || StringUtils.isBlank(documentDialoguePrompt.getConfigSystem())) {
throw new BusinessException("获取对话提示词失败");
} }
private ThirdPartyOrg extractThirdPartyOrg(String input) { String prompt = documentDialoguePrompt.getConfigSystem().replace("${input}", input);
return null;
//组装请求参数
List<Message> messages = buildMessages(input, null, prompt);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel("deepseek-v3");//获取模型);
largeModelResponse.setMessages(messages.toArray(new Message[0]));
largeModelResponse.setStream(false);
LargeModelDemandResult chat = llmService.chat(largeModelResponse);
Defendant defendant = new Defendant();
if (ObjectUtil.isEmpty(chat) || !chat.getCode().equals("0")) {
throw new BusinessException("获取失败");
} }
String message = chat.getMessage().replaceAll("```json",StringUtils.EMPTY).replaceAll("```",StringUtils.EMPTY);
defendant = JsonUtils.deSerialize(message, Defendant.class);
if (ObjectUtil.isEmpty(defendant)) {
throw new BusinessException("提取失败");
}
return defendant;
}
private Claim extractClaim(String input) { private DefendantOrg extractDefendantOrg(String input) throws Exception {
return null; // 获取对话提示词
String promptCode = "AILawyerWritingPromptDefendantOrg";
BizAgentApplicationGcConfigEntity documentDialoguePrompt = bizAgentApplicationGcConfigService.getByConfigCode(promptCode);
if (documentDialoguePrompt == null || StringUtils.isBlank(documentDialoguePrompt.getConfigSystem())) {
throw new BusinessException("获取对话提示词失败");
}
String prompt = documentDialoguePrompt.getConfigSystem().replace("${input}", input);
//组装请求参数
List<Message> messages = buildMessages(input, null, prompt);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel("deepseek-v3");//获取模型);
largeModelResponse.setMessages(messages.toArray(new Message[0]));
largeModelResponse.setStream(false);
LargeModelDemandResult chat = llmService.chat(largeModelResponse);
DefendantOrg defendantOrg = new DefendantOrg();
if (ObjectUtil.isEmpty(chat) || !chat.getCode().equals("0")) {
throw new BusinessException("获取失败");
}
String message = chat.getMessage().replaceAll("```json",StringUtils.EMPTY).replaceAll("```",StringUtils.EMPTY);
defendantOrg = JsonUtils.deSerialize(message, DefendantOrg.class);
if (ObjectUtil.isEmpty(defendantOrg)) {
throw new BusinessException("提取失败");
}
return defendantOrg;
}
private ThirdParty extractThirdParty(String input) throws Exception {
// 获取对话提示词
String promptCode = "AILawyerWritingPromptThirdParty";
BizAgentApplicationGcConfigEntity documentDialoguePrompt = bizAgentApplicationGcConfigService.getByConfigCode(promptCode);
if (documentDialoguePrompt == null || StringUtils.isBlank(documentDialoguePrompt.getConfigSystem())) {
throw new BusinessException("获取对话提示词失败");
}
String prompt = documentDialoguePrompt.getConfigSystem().replace("${input}", input);
//组装请求参数
List<Message> messages = buildMessages(input, null, prompt);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel("deepseek-v3");//获取模型);
largeModelResponse.setMessages(messages.toArray(new Message[0]));
largeModelResponse.setStream(false);
LargeModelDemandResult chat = llmService.chat(largeModelResponse);
ThirdParty thirdParty = new ThirdParty();
if (ObjectUtil.isEmpty(chat) || !chat.getCode().equals("0")) {
throw new BusinessException("获取失败");
}
String message = chat.getMessage().replaceAll("```json",StringUtils.EMPTY).replaceAll("```",StringUtils.EMPTY);
thirdParty = JsonUtils.deSerialize(message, ThirdParty.class);
if (ObjectUtil.isEmpty(thirdParty)) {
throw new BusinessException("提取失败");
}
return thirdParty;
}
private ThirdPartyOrg extractThirdPartyOrg(String input) throws Exception {
// 获取对话提示词
String promptCode = "AILawyerWritingPromptThirdPartyOrg";
BizAgentApplicationGcConfigEntity documentDialoguePrompt = bizAgentApplicationGcConfigService.getByConfigCode(promptCode);
if (documentDialoguePrompt == null || StringUtils.isBlank(documentDialoguePrompt.getConfigSystem())) {
throw new BusinessException("获取对话提示词失败");
} }
private Preservation extractPreservation(String input) { String prompt = documentDialoguePrompt.getConfigSystem().replace("${input}", input);
return null;
//组装请求参数
List<Message> messages = buildMessages(input, null, prompt);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel("deepseek-v3");//获取模型);
largeModelResponse.setMessages(messages.toArray(new Message[0]));
largeModelResponse.setStream(false);
LargeModelDemandResult chat = llmService.chat(largeModelResponse);
ThirdPartyOrg thirdPartyOrg = new ThirdPartyOrg();
if (ObjectUtil.isEmpty(chat) || !chat.getCode().equals("0")) {
throw new BusinessException("获取失败");
}
String message = chat.getMessage().replaceAll("```json",StringUtils.EMPTY).replaceAll("```",StringUtils.EMPTY);
thirdPartyOrg = JsonUtils.deSerialize(message, ThirdPartyOrg.class);
if (ObjectUtil.isEmpty(thirdPartyOrg)) {
throw new BusinessException("提取失败");
}
return thirdPartyOrg;
} }
private FactsAndReasons extractFactsAndReasons(String input) { private Claim extractClaim(String input) throws Exception {
return null; // 获取对话提示词
String promptCode = "AILawyerWritingPromptClaim";
BizAgentApplicationGcConfigEntity documentDialoguePrompt = bizAgentApplicationGcConfigService.getByConfigCode(promptCode);
if (documentDialoguePrompt == null || StringUtils.isBlank(documentDialoguePrompt.getConfigSystem())) {
throw new BusinessException("获取对话提示词失败");
} }
private UnderstandsMediationBenefit extractUnderstandsMediationBenefit(String input) { String prompt = documentDialoguePrompt.getConfigSystem().replace("${input}", input);
return null;
//组装请求参数
List<Message> messages = buildMessages(input, null, prompt);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel("deepseek-v3");//获取模型);
largeModelResponse.setMessages(messages.toArray(new Message[0]));
largeModelResponse.setStream(false);
LargeModelDemandResult chat = llmService.chat(largeModelResponse);
Claim claim = new Claim();
if (ObjectUtil.isEmpty(chat) || !chat.getCode().equals("0")) {
throw new BusinessException("获取失败");
}
String message = chat.getMessage().replaceAll("```json",StringUtils.EMPTY).replaceAll("```",StringUtils.EMPTY);
claim = JsonUtils.deSerialize(message, Claim.class);
if (ObjectUtil.isEmpty(claim)) {
throw new BusinessException("提取失败");
}
return claim;
} }
private Agent extractAgent(String input) { private Preservation extractPreservation(String input) throws Exception {
return null; // 获取对话提示词
String promptCode = "AILawyerWritingPromptPreservation";
BizAgentApplicationGcConfigEntity documentDialoguePrompt = bizAgentApplicationGcConfigService.getByConfigCode(promptCode);
if (documentDialoguePrompt == null || StringUtils.isBlank(documentDialoguePrompt.getConfigSystem())) {
throw new BusinessException("获取对话提示词失败");
} }
String prompt = documentDialoguePrompt.getConfigSystem().replace("${input}", input);
private Plaintiff extractPlaintiff(String input) { //组装请求参数
return null; List<Message> messages = buildMessages(input, null, prompt);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel("deepseek-v3");//获取模型);
largeModelResponse.setMessages(messages.toArray(new Message[0]));
largeModelResponse.setStream(false);
LargeModelDemandResult chat = llmService.chat(largeModelResponse);
Preservation preservation = new Preservation();
if (ObjectUtil.isEmpty(chat) || !chat.getCode().equals("0")) {
throw new BusinessException("获取失败");
}
String message = chat.getMessage().replaceAll("```json",StringUtils.EMPTY).replaceAll("```",StringUtils.EMPTY);
preservation = JsonUtils.deSerialize(message, Preservation.class);
if (ObjectUtil.isEmpty(preservation)) {
throw new BusinessException("提取失败");
}
return preservation;
}
private FactsAndReasons extractFactsAndReasons(String input) throws Exception {
// 获取对话提示词
String promptCode = "AILawyerWritingPromptFactsAndReasons";
BizAgentApplicationGcConfigEntity documentDialoguePrompt = bizAgentApplicationGcConfigService.getByConfigCode(promptCode);
if (documentDialoguePrompt == null || StringUtils.isBlank(documentDialoguePrompt.getConfigSystem())) {
throw new BusinessException("获取对话提示词失败");
} }
String prompt = documentDialoguePrompt.getConfigSystem().replace("${input}", input);
private List<Message> buildMessages(String dialogsId, Long userId, String input, String fileUrl, List<KnowledgeContentResult> knowledgeContentResults, ToolFunction toolFunction) throws Exception { //组装请求参数
List<Message> messages = buildMessages(input, null, prompt);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel("deepseek-v3");//获取模型);
largeModelResponse.setMessages(messages.toArray(new Message[0]));
largeModelResponse.setStream(false);
LargeModelDemandResult chat = llmService.chat(largeModelResponse);
FactsAndReasons factsAndReasons = new FactsAndReasons();
if (ObjectUtil.isEmpty(chat) || !chat.getCode().equals("0")) {
throw new BusinessException("获取失败");
}
String message = chat.getMessage().replaceAll("```json",StringUtils.EMPTY).replaceAll("```",StringUtils.EMPTY);
factsAndReasons = JsonUtils.deSerialize(message, FactsAndReasons.class);
if (ObjectUtil.isEmpty(factsAndReasons)) {
throw new BusinessException("提取失败");
}
return factsAndReasons;
}
private UnderstandsMediationBenefit extractUnderstandsMediationBenefit(String input) throws Exception {
// 获取对话提示词 // 获取对话提示词
String promptCode = "ExtractDefendantOrgPrompt"; String promptCode = "AILawyerWritingPromptUnderstandsMediationBenefit";
BizAgentApplicationGcConfigEntity documentDialoguePrompt = bizAgentApplicationGcConfigService.getByConfigCode(promptCode); BizAgentApplicationGcConfigEntity documentDialoguePrompt = bizAgentApplicationGcConfigService.getByConfigCode(promptCode);
if (documentDialoguePrompt == null || StringUtils.isBlank(documentDialoguePrompt.getConfigSystem())) { if (documentDialoguePrompt == null || StringUtils.isBlank(documentDialoguePrompt.getConfigSystem())) {
// logger.error("获取对话提示词失败 , configCode:{}", promptCode);
throw new BusinessException("获取对话提示词失败"); throw new BusinessException("获取对话提示词失败");
} }
String prompt = documentDialoguePrompt.getConfigSystem().replace("${input}", input); String prompt = documentDialoguePrompt.getConfigSystem().replace("${input}", input);
//组装请求参数
List<Message> messages = buildMessages(input, null, prompt);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel("deepseek-v3");//获取模型);
largeModelResponse.setMessages(messages.toArray(new Message[0]));
largeModelResponse.setStream(false);
LargeModelDemandResult chat = llmService.chat(largeModelResponse);
UnderstandsMediationBenefit understandsMediationBenefit = new UnderstandsMediationBenefit();
if (ObjectUtil.isEmpty(chat) || !chat.getCode().equals("0")) {
throw new BusinessException("获取失败");
}
String message = chat.getMessage().replaceAll("```json",StringUtils.EMPTY).replaceAll("```",StringUtils.EMPTY);
understandsMediationBenefit = JsonUtils.deSerialize(message, UnderstandsMediationBenefit.class);
if (ObjectUtil.isEmpty(understandsMediationBenefit)) {
throw new BusinessException("提取失败");
}
return understandsMediationBenefit;
}
private List<Message> buildMessages(String input, String fileUrl, String prompt) throws Exception {
// 加载文件 // 加载文件
String fileContent = StringUtils.EMPTY; String fileContent = StringUtils.EMPTY;
if (StringUtils.isNoneBlank(fileUrl)) { if (StringUtils.isNoneBlank(fileUrl)) {
...@@ -260,7 +574,7 @@ public class MotorVehicleDrivingComplaint implements ExtractEntityStrategy { ...@@ -260,7 +574,7 @@ public class MotorVehicleDrivingComplaint implements ExtractEntityStrategy {
// 用户输入 // 用户输入
Message message = new Message(); Message message = new Message();
message.setContent(input); message.setContent("请根据要求提取");
message.setRole(LLMRoleEnum.USER.getRole()); message.setRole(LLMRoleEnum.USER.getRole());
messages.add(message); messages.add(message);
// logger.info("--------- Build Messages dialogsId:{},messages:{}--------------", dialogsId, messages); // logger.info("--------- Build Messages dialogsId:{},messages:{}--------------", dialogsId, messages);
......
...@@ -241,9 +241,6 @@ public class AiLawServiceImpl implements AiLawService { ...@@ -241,9 +241,6 @@ public class AiLawServiceImpl implements AiLawService {
ExtractEntityStrategy extractEntityStrategy = LawyerTemplateExtractServiceBuilder.getService(LawyerExtractTypeEnum.valueOf(templateCode)); ExtractEntityStrategy extractEntityStrategy = LawyerTemplateExtractServiceBuilder.getService(LawyerExtractTypeEnum.valueOf(templateCode));
//解析文件
LegalTemplateDto legalTemplateDto = extractEntityStrategy.extractEntity(input + fileContent); LegalTemplateDto legalTemplateDto = extractEntityStrategy.extractEntity(input + fileContent);
return legalTemplateDto; return legalTemplateDto;
......
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