Commit aa0fda4b authored by R10's avatar R10

智写-文书写作模板-模板对话

parent f26c7626
package cn.com.poc.law.ExtractEntityStrategy;
import cn.com.poc.law.dto.LegalTemplateDto;
import java.util.concurrent.ExecutionException;
/**
* @Author:Roger Wu
* @name:LegalTemplateSerivce
* @Date:2025-08-07 18:53
*/
public interface ExtractEntityStrategy {
/**
* 提取实体
* @return
*/
LegalTemplateDto extractEntity(String input) throws ExecutionException, InterruptedException;
}
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.KnowledgeContentResult;
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.JsonUtils;
import cn.com.poc.law.ExtractEntityStrategy.ExtractEntityStrategy;
import cn.com.poc.law.dto.LegalTemplateDto;
import cn.com.poc.law.entity.*;
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.ToolFunction;
import cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelResponse;
import cn.com.poc.thirdparty.service.LLMService;
import cn.com.yict.framemax.core.exception.BusinessException;
import cn.hutool.core.util.ObjectUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
/**
* @Author:Roger Wu
* @name:NonMotorVehicleDriving
* @Date:2025-08-08 10:56
*/
@Service
public class MotorVehicleDrivingComplaint implements ExtractEntityStrategy {
final private ThreadPoolExecutor executor = new ThreadPoolExecutor(16, 64, 10, TimeUnit.SECONDS, new LinkedBlockingDeque<>(100));
@Resource
BizAgentApplicationGcConfigService bizAgentApplicationGcConfigService;
@Resource
LLMService llmService;
/**
* 提取实体
*
* @return
*/
@Override
public LegalTemplateDto extractEntity(String input) throws ExecutionException, InterruptedException {
// CompletableFuture<Plaintiff> extractPlaintiffFuture = CompletableFuture
// .supplyAsync(() -> extractPlaintiff(input), executor)
// .exceptionally(ex -> {
// return new Plaintiff();
// });
//
CompletableFuture<PlaintiffOrg> extractPlaintiffOrgFuture = CompletableFuture
.supplyAsync(() -> {
try {
return extractPlaintiffOrg(input);
} catch (Exception e) {
throw new RuntimeException(e);
}
}, executor)
.exceptionally(ex -> {
return new PlaintiffOrg();
});
//
// CompletableFuture<Agent> extractAgentFuture = CompletableFuture
// .supplyAsync(() -> extractAgent(input), executor)
// .exceptionally(ex -> {
// return new Agent();
// });
//
// CompletableFuture<Defendant> extractDefendantFuture = CompletableFuture
// .supplyAsync(() -> extractDefendant(input), executor)
// .exceptionally(ex -> {
// return new Defendant();
// });
// CompletableFuture<DefendantOrg> extractDefendantOrgFuture = CompletableFuture
// .supplyAsync(() -> {
// try {
// return extractDefendantOrg(input);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// }, executor)
// .exceptionally(ex -> {
// return new DefendantOrg();
// });
// CompletableFuture<ThirdParty> extractThirdPartyFuture = CompletableFuture
// .supplyAsync(() -> extractThirdParty(input), executor)
// .exceptionally(ex -> {
// return new ThirdParty();
// });
//
// CompletableFuture<ThirdPartyOrg> extractThirdPartyOrgFuture = CompletableFuture
// .supplyAsync(() -> extractThirdPartyOrg(input), executor)
// .exceptionally(ex -> {
// return new ThirdPartyOrg();
// });
//
// CompletableFuture<Claim> extractClaimFuture = CompletableFuture
// .supplyAsync(() -> extractClaim(input), executor)
// .exceptionally(ex -> {
// return new Claim();
// });
//
// CompletableFuture<Preservation> extractPreservationFuture = CompletableFuture
// .supplyAsync(() -> extractPreservation(input), executor)
// .exceptionally(ex -> {
// return new Preservation();
// });
//
// CompletableFuture<FactsAndReasons> extractFactsAndReasonsFuture = CompletableFuture
// .supplyAsync(() -> extractFactsAndReasons(input), executor)
// .exceptionally(ex -> {
// return new FactsAndReasons();
// });
//
// CompletableFuture<UnderstandsMediationBenefit> extractUnderstandsMediationBenefitFuture = CompletableFuture
// .supplyAsync(() -> extractUnderstandsMediationBenefit(input), executor)
// .exceptionally(ex -> {
// return new UnderstandsMediationBenefit();
// });
// 等待所有任务完成并获取结果
// CompletableFuture.allOf(extractPlaintiffFuture, extractPlaintiffOrgFuture, extractAgentFuture, extractDefendantFuture, extractDefendantOrgFuture,
// extractThirdPartyFuture, extractThirdPartyOrgFuture, extractClaimFuture, extractPreservationFuture, extractFactsAndReasonsFuture, extractUnderstandsMediationBenefitFuture).join();
//
// Plaintiff extractPlaintiffResults = extractPlaintiffFuture.get();
PlaintiffOrg extractPlaintiffOrgResults = extractPlaintiffOrgFuture.get();
// Agent extractAgentResults = extractAgentFuture.get();
// Defendant extractDefendantResult = extractDefendantFuture.get();
// DefendantOrg extractDefendantOrgResult = extractDefendantOrgFuture.get();
// ThirdParty extractThirdPartyResult = extractThirdPartyFuture.get();
// ThirdPartyOrg extractThirdPartyOrgResult = extractThirdPartyOrgFuture.get();
// Claim extractClaimResult = extractClaimFuture.get();
// Preservation preservationResult = extractPreservationFuture.get();
// FactsAndReasons FactsAndReasonsResult = extractFactsAndReasonsFuture.get();
// UnderstandsMediationBenefit UnderstandsMediationBenefitResult = extractUnderstandsMediationBenefitFuture.get();
MotorVehicleDrivingComplaintEntity motorVehicleDrivingComplaintEntity = new MotorVehicleDrivingComplaintEntity();
motorVehicleDrivingComplaintEntity.setPlaintiffOrg(extractPlaintiffOrgResults);
return motorVehicleDrivingComplaintEntity;
}
private PlaintiffOrg extractPlaintiffOrg(String input) throws Exception {
//组装请求参数
List<Message> messages = buildMessages(null, null, input, null, null, null);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel("deepseek-v3");//获取模型);
largeModelResponse.setMessages(messages.toArray(new Message[0]));
largeModelResponse.setStream(true);
BufferedReader bufferedReader = llmService.chatChunk(largeModelResponse);
String res;
PlaintiffOrg result = null;
while ((res = bufferedReader.readLine()) != null) {
if (StringUtils.isEmpty(res)) {
continue;
}
res = res.replace("data: ", StringUtils.EMPTY);
result = JsonUtils.deSerialize(res, PlaintiffOrg.class);
if (ObjectUtil.isEmpty(result)) {
throw new BusinessException("提取失败");
}
}
bufferedReader.close();
return result;
}
private Defendant extractDefendant(String input) {
return null;
}
private ThirdParty extractThirdParty(String input) {
return null;
}
private ThirdPartyOrg extractThirdPartyOrg(String input) {
return null;
}
private Claim extractClaim(String input) {
return null;
}
private Preservation extractPreservation(String input) {
return null;
}
private FactsAndReasons extractFactsAndReasons(String input) {
return null;
}
private UnderstandsMediationBenefit extractUnderstandsMediationBenefit(String input) {
return null;
}
private Agent extractAgent(String input) {
return null;
}
private Plaintiff extractPlaintiff(String input) {
return null;
}
private List<Message> buildMessages(String dialogsId, Long userId, String input, String fileUrl, List<KnowledgeContentResult> knowledgeContentResults, ToolFunction toolFunction) throws Exception {
// 获取对话提示词
String promptCode = "ExtractDefendantOrgPrompt";
BizAgentApplicationGcConfigEntity documentDialoguePrompt = bizAgentApplicationGcConfigService.getByConfigCode(promptCode);
if (documentDialoguePrompt == null || StringUtils.isBlank(documentDialoguePrompt.getConfigSystem())) {
// logger.error("获取对话提示词失败 , configCode:{}", promptCode);
throw new BusinessException("获取对话提示词失败");
}
String prompt = documentDialoguePrompt.getConfigSystem().replace("${input}", input);
// 加载文件
String fileContent = StringUtils.EMPTY;
if (StringUtils.isNoneBlank(fileUrl)) {
File file = DocumentLoad.downloadURLDocument(fileUrl);
fileContent = DocumentLoad.documentToText(file);
}
// 加载对话提示词
// String prompt = documentDialoguePrompt.getConfigSystem();
// if (CollectionUtils.isNotEmpty(knowledgeContentResults)) {
// String knowledgeContent = JsonUtils.serialize(knowledgeContentResults);
// prompt = prompt.replace("${knowledgeContent}", knowledgeContent);
// } else {
// prompt = prompt.replace("${knowledgeContent}", StringUtils.EMPTY);
// }
// if (toolFunction != null) {
// prompt = prompt.replace("${toolFunction}", JsonUtils.serialize(toolFunction));
// }
//
// prompt = prompt.replace("${question}", input).replace("${fileContent}", fileContent);
// 配置message
List<Message> messages = new ArrayList<>();
Message systemMessage = new Message();
systemMessage.setContent(prompt);
systemMessage.setRole(LLMRoleEnum.SYSTEM.getRole());
messages.add(systemMessage);
// 用户输入
Message message = new Message();
message.setContent(input);
message.setRole(LLMRoleEnum.USER.getRole());
messages.add(message);
// logger.info("--------- Build Messages dialogsId:{},messages:{}--------------", dialogsId, messages);
return messages;
}
}
package cn.com.poc.law.ExtractEntityStrategy;
/**
* @Author:Roger Wu
* @name:LawyerExtractType
* @Date:2025-08-08 11:09
*/
public enum LawyerExtractTypeEnum {
motorVehicleDrivingComplaint;
}
package cn.com.poc.law.ExtractEntityStrategy;
import cn.com.poc.law.ExtractEntityStrategy.ExtractEntityType.MotorVehicleDrivingComplaint;
import cn.com.yict.framemax.core.exception.BusinessException;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class LawyerTemplateExtractServiceBuilder implements ApplicationContextAware {
private ApplicationContext applicationContext;
public ExtractEntityStrategy getService(LawyerExtractTypeEnum type) throws Exception {
if (LawyerExtractTypeEnum.motorVehicleDrivingComplaint.equals(type)) {
return applicationContext.getBean(MotorVehicleDrivingComplaint.class);
}
throw new BusinessException("选择模板异常!");
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
...@@ -43,6 +43,12 @@ public class AiLawDialoguesDto { ...@@ -43,6 +43,12 @@ public class AiLawDialoguesDto {
*/ */
private boolean enableDeepThinking; private boolean enableDeepThinking;
/**
*
* @return
*/
private String templateCode;
public String getDialoguesId() { public String getDialoguesId() {
return dialoguesId; return dialoguesId;
} }
...@@ -98,4 +104,20 @@ public class AiLawDialoguesDto { ...@@ -98,4 +104,20 @@ public class AiLawDialoguesDto {
public void setEnableDeepThinking(boolean enableDeepThinking) { public void setEnableDeepThinking(boolean enableDeepThinking) {
this.enableDeepThinking = enableDeepThinking; this.enableDeepThinking = enableDeepThinking;
} }
public boolean isEnableSearchEngine() {
return enableSearchEngine;
}
public boolean isEnableDeepThinking() {
return enableDeepThinking;
}
public String getTemplateCode() {
return templateCode;
}
public void setTemplateCode(String templateCode) {
this.templateCode = templateCode;
}
} }
package cn.com.poc.law.dto;
/**
* @Author:Roger Wu
* @name:LegalTemplateDto
* @Date:2025-08-07 18:22
*/
public class LegalTemplateDto {
}
package cn.com.poc.law.entity;
import cn.com.poc.law.dto.LegalTemplateDto;
/**
* @Author:Roger Wu
* @name:MotorVehicleDrivingComplaint
* @Date:2025-08-08 11:39
*/
public class MotorVehicleDrivingComplaintEntity extends LegalTemplateDto {
Plaintiff plaintiff;
PlaintiffOrg plaintiffOrg;
Defendant defendant;
DefendantOrg defendantOrg;
Agent agent;
ThirdParty thirdParty;
ThirdPartyOrg thirdPartyOrg;
Claim claim;
FactsAndReasons factsAndReasons;
Preservation preservation;
UnderstandsMediationBenefit understandsMediationBenefit;
public Plaintiff getPlaintiff() {
return plaintiff;
}
public void setPlaintiff(Plaintiff plaintiff) {
this.plaintiff = plaintiff;
}
public PlaintiffOrg getPlaintiffOrg() {
return plaintiffOrg;
}
public void setPlaintiffOrg(PlaintiffOrg plaintiffOrg) {
this.plaintiffOrg = plaintiffOrg;
}
public Defendant getDefendant() {
return defendant;
}
public void setDefendant(Defendant defendant) {
this.defendant = defendant;
}
public DefendantOrg getDefendantOrg() {
return defendantOrg;
}
public void setDefendantOrg(DefendantOrg defendantOrg) {
this.defendantOrg = defendantOrg;
}
public Agent getAgent() {
return agent;
}
public void setAgent(Agent agent) {
this.agent = agent;
}
public ThirdParty getThirdParty() {
return thirdParty;
}
public void setThirdParty(ThirdParty thirdParty) {
this.thirdParty = thirdParty;
}
public ThirdPartyOrg getThirdPartyOrg() {
return thirdPartyOrg;
}
public void setThirdPartyOrg(ThirdPartyOrg thirdPartyOrg) {
this.thirdPartyOrg = thirdPartyOrg;
}
public Claim getClaim() {
return claim;
}
public void setClaim(Claim claim) {
this.claim = claim;
}
public FactsAndReasons getFactsAndReasons() {
return factsAndReasons;
}
public void setFactsAndReasons(FactsAndReasons factsAndReasons) {
this.factsAndReasons = factsAndReasons;
}
public Preservation getPreservation() {
return preservation;
}
public void setPreservation(Preservation preservation) {
this.preservation = preservation;
}
public UnderstandsMediationBenefit getUnderstandsMediationBenefit() {
return understandsMediationBenefit;
}
public void setUnderstandsMediationBenefit(UnderstandsMediationBenefit understandsMediationBenefit) {
this.understandsMediationBenefit = understandsMediationBenefit;
}
}
...@@ -3,6 +3,7 @@ package cn.com.poc.law.rest; ...@@ -3,6 +3,7 @@ package cn.com.poc.law.rest;
import cn.com.poc.ai_finance.dto.AiFinanceDialoguesDto; import cn.com.poc.ai_finance.dto.AiFinanceDialoguesDto;
import cn.com.poc.law.dto.AiLawDialoguesDto; import cn.com.poc.law.dto.AiLawDialoguesDto;
import cn.com.poc.law.dto.LegalFileDto; import cn.com.poc.law.dto.LegalFileDto;
import cn.com.poc.law.dto.LegalTemplateDto;
import cn.com.yict.framemax.core.rest.BaseRest; import cn.com.yict.framemax.core.rest.BaseRest;
import cn.com.yict.framemax.web.permission.Access; import cn.com.yict.framemax.web.permission.Access;
import cn.com.yict.framemax.web.permission.Permission; import cn.com.yict.framemax.web.permission.Permission;
...@@ -31,7 +32,7 @@ public interface LegalRest extends BaseRest { ...@@ -31,7 +32,7 @@ public interface LegalRest extends BaseRest {
/** /**
* templateAi对话 * templateAi对话
*/ */
void templateCall(@RequestBody AiLawDialoguesDto dto) throws Exception; LegalTemplateDto templateCall(@RequestBody AiLawDialoguesDto dto) throws Exception;
} }
...@@ -6,6 +6,7 @@ import cn.com.poc.common.utils.Assert; ...@@ -6,6 +6,7 @@ import cn.com.poc.common.utils.Assert;
import cn.com.poc.common.utils.BlContext; import cn.com.poc.common.utils.BlContext;
import cn.com.poc.law.dto.AiLawDialoguesDto; import cn.com.poc.law.dto.AiLawDialoguesDto;
import cn.com.poc.law.dto.LegalFileDto; import cn.com.poc.law.dto.LegalFileDto;
import cn.com.poc.law.dto.LegalTemplateDto;
import cn.com.poc.law.rest.LegalRest; import cn.com.poc.law.rest.LegalRest;
import cn.com.poc.law.service.AiLawService; import cn.com.poc.law.service.AiLawService;
import cn.com.poc.support.security.oauth.entity.UserBaseEntity; import cn.com.poc.support.security.oauth.entity.UserBaseEntity;
...@@ -65,11 +66,11 @@ public class LegalRestImpl implements LegalRest { ...@@ -65,11 +66,11 @@ public class LegalRestImpl implements LegalRest {
* @param dto * @param dto
*/ */
@Override @Override
public void templateCall(AiLawDialoguesDto dto) throws Exception { public LegalTemplateDto templateCall(AiLawDialoguesDto dto) throws Exception {
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException(); UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
if (userBaseEntity == null) { if (userBaseEntity == null) {
throw new BusinessException("用户未登录"); throw new BusinessException("用户未登录");
} }
aiLawService.templateCall(dto.getDialoguesId(), dto.getInput(), dto.getFileUrl(), userBaseEntity.getUserId()); return aiLawService.templateCall(dto.getDialoguesId(), dto.getTemplateCode(),dto.getInput(), dto.getFileUrl(), userBaseEntity.getUserId());
} }
} }
package cn.com.poc.law.service; package cn.com.poc.law.service;
import cn.com.poc.law.dto.LegalTemplateDto;
/** /**
* AI财务 * AI财务
* *
...@@ -25,5 +27,5 @@ public interface AiLawService { ...@@ -25,5 +27,5 @@ public interface AiLawService {
/** /**
* @throws Exception * @throws Exception
*/ */
void templateCall(String dialoguesId, String input, String fileUrl, Long userId) throws Exception; LegalTemplateDto templateCall(String dialoguesId, String templateCode, String input, String fileUrl, Long userId) throws Exception;
} }
...@@ -18,9 +18,14 @@ import cn.com.poc.knowledge.aggregate.KnowledgeService; ...@@ -18,9 +18,14 @@ import cn.com.poc.knowledge.aggregate.KnowledgeService;
import cn.com.poc.knowledge.constant.KnowledgeConstant; import cn.com.poc.knowledge.constant.KnowledgeConstant;
import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity; import cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity;
import cn.com.poc.knowledge.query.KnowledgeDocumentRelationQueryItem; import cn.com.poc.knowledge.query.KnowledgeDocumentRelationQueryItem;
import cn.com.poc.law.ExtractEntityStrategy.ExtractEntityStrategy;
import cn.com.poc.law.ExtractEntityStrategy.LawyerExtractTypeEnum;
import cn.com.poc.law.ExtractEntityStrategy.LawyerTemplateExtractServiceBuilder;
import cn.com.poc.law.dto.LegalTemplateDto;
import cn.com.poc.law.entity.*; import cn.com.poc.law.entity.*;
import cn.com.poc.law.service.AiLawService; import cn.com.poc.law.service.AiLawService;
import cn.com.poc.long_document.domain.LongtextDialoguesResult; import cn.com.poc.long_document.domain.LongtextDialoguesResult;
import cn.com.poc.support.login.ThirdPlatformAuthServiceBuilder;
import cn.com.poc.thirdparty.resource.demand.ai.constants.KnowledgeSearchTypeEnum; import cn.com.poc.thirdparty.resource.demand.ai.constants.KnowledgeSearchTypeEnum;
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.dbchain.DBChainResult; import cn.com.poc.thirdparty.resource.demand.ai.entity.dbchain.DBChainResult;
...@@ -67,13 +72,6 @@ public class AiLawServiceImpl implements AiLawService { ...@@ -67,13 +72,6 @@ public class AiLawServiceImpl implements AiLawService {
private final Logger logger = LoggerFactory.getLogger(AiLawServiceImpl.class); private final Logger logger = LoggerFactory.getLogger(AiLawServiceImpl.class);
final private ThreadPoolExecutor executor = new ThreadPoolExecutor(16, 64, 10, TimeUnit.SECONDS, new LinkedBlockingDeque<>(100));
private final String FMX_PARAM_AGENT_ID_CODE = "ai_legal_document_writing.agent_id";
@Resource
private FmxParamConfigService fmxParamConfigService;
@Resource @Resource
private BizAiDialoguesService bizAiDialoguesService; private BizAiDialoguesService bizAiDialoguesService;
...@@ -96,6 +94,8 @@ public class AiLawServiceImpl implements AiLawService { ...@@ -96,6 +94,8 @@ public class AiLawServiceImpl implements AiLawService {
@Resource @Resource
private BizAgentApplicationGcConfigService bizAgentApplicationGcConfigService; private BizAgentApplicationGcConfigService bizAgentApplicationGcConfigService;
@Resource
LawyerTemplateExtractServiceBuilder LawyerTemplateExtractServiceBuilder;
@Override @Override
public void aiWritingCall(String dialoguesId, String input, boolean enableSearchEngine, boolean enableDeepThinking, String fileUrl, Integer[] knowledgeIds, Integer[] databaseIds, Long userId) throws Exception { public void aiWritingCall(String dialoguesId, String input, boolean enableSearchEngine, boolean enableDeepThinking, String fileUrl, Integer[] knowledgeIds, Integer[] databaseIds, Long userId) throws Exception {
...@@ -208,13 +208,16 @@ public class AiLawServiceImpl implements AiLawService { ...@@ -208,13 +208,16 @@ public class AiLawServiceImpl implements AiLawService {
/** /**
* @param dialoguesId * @param dialoguesId
* @param templateCode
* @param input * @param input
* @param fileUrl * @param fileUrl
* @param userId * @param userId
* @throws Exception * @throws Exception
*/ */
@Override @Override
public void templateCall(String dialoguesId, String input, String fileUrl, Long userId) throws Exception { public LegalTemplateDto templateCall(String dialoguesId, String templateCode, String input, String fileUrl, Long userId) throws Exception {
//基础
BizAiDialoguesEntity bizAiDialoguesEntity = new BizAiDialoguesEntity(); BizAiDialoguesEntity bizAiDialoguesEntity = new BizAiDialoguesEntity();
bizAiDialoguesEntity.setDialoguesId(dialoguesId); bizAiDialoguesEntity.setDialoguesId(dialoguesId);
bizAiDialoguesEntity.setMemberId(userId); bizAiDialoguesEntity.setMemberId(userId);
...@@ -225,11 +228,10 @@ public class AiLawServiceImpl implements AiLawService { ...@@ -225,11 +228,10 @@ public class AiLawServiceImpl implements AiLawService {
} }
BizAiDialoguesEntity aiDialoguesEntity = bizAiDialoguesEntities.get(0); BizAiDialoguesEntity aiDialoguesEntity = bizAiDialoguesEntities.get(0);
if (StringUtils.isBlank(aiDialoguesEntity.getTitle())) { if (StringUtils.isBlank(aiDialoguesEntity.getTitle())) {
aiDialoguesEntity.setDialoguesType(AiDialoguesTypeEnum.TEMPLATE_LEGAL_DOCUMENT_WRITING.getType());
aiDialoguesEntity.setTitle(input); aiDialoguesEntity.setTitle(input);
bizAiDialoguesService.update(aiDialoguesEntity); bizAiDialoguesService.update(aiDialoguesEntity);
} }
//1.
// 加载文件 // 加载文件
String fileContent = StringUtils.EMPTY; String fileContent = StringUtils.EMPTY;
if (StringUtils.isNoneBlank(fileUrl)) { if (StringUtils.isNoneBlank(fileUrl)) {
...@@ -237,185 +239,13 @@ public class AiLawServiceImpl implements AiLawService { ...@@ -237,185 +239,13 @@ public class AiLawServiceImpl implements AiLawService {
fileContent = DocumentLoad.documentToText(file); fileContent = DocumentLoad.documentToText(file);
} }
//记录提问时间
long inputTimestamp = System.currentTimeMillis();
extractLawyerInfo(input + fileContent);
}
private void extractLawyerInfo(String input) throws ExecutionException, InterruptedException {
CompletableFuture<Plaintiff> extractPlaintiffFuture = CompletableFuture
.supplyAsync(() -> extractPlaintiff(input), executor)
.exceptionally(ex -> {
return new Plaintiff();
});
CompletableFuture<PlaintiffOrg> extractPlaintiffOrgFuture = CompletableFuture
.supplyAsync(() -> extractPlaintiffOrg(input), executor)
.exceptionally(ex -> {
return new PlaintiffOrg();
});
CompletableFuture<Agent> extractAgentFuture = CompletableFuture
.supplyAsync(() -> extractAgent(input), executor)
.exceptionally(ex -> {
return new Agent();
});
CompletableFuture<Defendant> extractDefendantFuture = CompletableFuture
.supplyAsync(() -> extractDefendant(input), executor)
.exceptionally(ex -> {
return new Defendant();
});
CompletableFuture<DefendantOrg> extractDefendantOrgFuture = CompletableFuture
.supplyAsync(() -> {
try {
return extractDefendantOrg(input);
} catch (Exception e) {
throw new RuntimeException(e);
}
}, executor)
.exceptionally(ex -> {
return new DefendantOrg();
});
CompletableFuture<ThirdParty> extractThirdPartyFuture = CompletableFuture
.supplyAsync(() -> extractThirdParty(input), executor)
.exceptionally(ex -> {
return new ThirdParty();
});
CompletableFuture<ThirdPartyOrg> extractThirdPartyOrgFuture = CompletableFuture
.supplyAsync(() -> extractThirdPartyOrg(input), executor)
.exceptionally(ex -> {
logger.error("knowledge chain error", ex);
return new ThirdPartyOrg();
});
CompletableFuture<Claim> extractClaimFuture = CompletableFuture
.supplyAsync(() -> extractClaim(input), executor)
.exceptionally(ex -> {
logger.error("knowledge chain error", ex);
return new Claim();
});
CompletableFuture<Preservation> extractPreservationFuture = CompletableFuture
.supplyAsync(() -> extractPreservation(input), executor)
.exceptionally(ex -> {
logger.error("knowledge chain error", ex);
return new Preservation();
});
CompletableFuture<FactsAndReasons> extractFactsAndReasonsFuture = CompletableFuture
.supplyAsync(() -> extractFactsAndReasons(input), executor)
.exceptionally(ex -> {
return new FactsAndReasons();
});
CompletableFuture<UnderstandsMediationBenefit> extractUnderstandsMediationBenefitFuture = CompletableFuture
.supplyAsync(() -> extractUnderstandsMediationBenefit(input), executor)
.exceptionally(ex -> {
return new UnderstandsMediationBenefit();
});
// 等待所有任务完成并获取结果
CompletableFuture.allOf(extractPlaintiffFuture, extractPlaintiffOrgFuture, extractAgentFuture, extractDefendantFuture, extractDefendantOrgFuture,
extractThirdPartyFuture, extractThirdPartyOrgFuture, extractClaimFuture, extractPreservationFuture, extractFactsAndReasonsFuture, extractUnderstandsMediationBenefitFuture).join();
Plaintiff extractPlaintiffResults = extractPlaintiffFuture.get();
PlaintiffOrg extractPlaintiffOrgResults = extractPlaintiffOrgFuture.get();
Agent extractAgentResults = extractAgentFuture.get();
Defendant extractDefendantResult = extractDefendantFuture.get();
DefendantOrg extractDefendantOrgResult = extractDefendantOrgFuture.get();
ThirdParty extractThirdPartyResult = extractThirdPartyFuture.get();
ThirdPartyOrg extractThirdPartyOrgResult = extractThirdPartyOrgFuture.get();
Claim extractClaimResult = extractClaimFuture.get();
Preservation preservationResult = extractPreservationFuture.get();
FactsAndReasons FactsAndReasonsResult = extractFactsAndReasonsFuture.get();
UnderstandsMediationBenefit UnderstandsMediationBenefitResult = extractUnderstandsMediationBenefitFuture.get();
}
private DefendantOrg extractDefendantOrg(String input) throws Exception {
// 获取对话提示词
String promptCode = "ExtractDefendantOrgPrompt";
BizAgentApplicationGcConfigEntity documentDialoguePrompt = bizAgentApplicationGcConfigService.getByConfigCode(promptCode);
if (documentDialoguePrompt == null || StringUtils.isBlank(documentDialoguePrompt.getConfigSystem())) {
logger.error("获取对话提示词失败 , configCode:{}", promptCode);
throw new BusinessException("获取对话提示词失败");
}
documentDialoguePrompt.getConfigSystem().replaceAll("$\\{input\\}", input); ExtractEntityStrategy extractEntityStrategy = LawyerTemplateExtractServiceBuilder.getService(LawyerExtractTypeEnum.valueOf(templateCode));
//组装请求参数 //解析文件
List<Message> messages = buildMessages(null, null, input, null, null, null);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel("deepseek-v3");//获取模型);
largeModelResponse.setMessages(messages.toArray(new Message[0]));
largeModelResponse.setStream(true);
BufferedReader bufferedReader = llmService.chatChunk(largeModelResponse);
String res;
DefendantOrg result = null;
while ((res = bufferedReader.readLine()) != null) {
if (StringUtils.isEmpty(res)) {
continue;
}
res = res.replace("data: ", StringUtils.EMPTY);
result = JsonUtils.deSerialize(res, DefendantOrg.class);
if (ObjectUtil.isEmpty(result)) {
throw new BusinessException("提取失败");
}
}
bufferedReader.close();
return result;
}
private Defendant extractDefendant(String input) {
return null;
}
private ThirdParty extractThirdParty(String input) {
return null;
}
private ThirdPartyOrg extractThirdPartyOrg(String input) {
return null;
}
private Claim extractClaim(String input) {
return null;
}
private Preservation extractPreservation(String input) {
return null;
}
private FactsAndReasons extractFactsAndReasons(String input) {
return null;
}
private UnderstandsMediationBenefit extractUnderstandsMediationBenefit(String input) {
return null;
}
private Agent extractAgent(String input) {
return null;
}
private Plaintiff extractPlaintiff(String input) {
return null;
}
private PlaintiffOrg extractPlaintiffOrg(String input) { LegalTemplateDto legalTemplateDto = extractEntityStrategy.extractEntity(input + fileContent);
return null; 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