Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
poc-api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
poc
poc-api
Commits
aa0fda4b
Commit
aa0fda4b
authored
Aug 08, 2025
by
R10
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
智写-文书写作模板-模板对话
parent
f26c7626
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
501 additions
and
190 deletions
+501
-190
ExtractEntityStrategy.java
.../poc/law/ExtractEntityStrategy/ExtractEntityStrategy.java
+20
-0
MotorVehicleDrivingComplaint.java
...ategy/ExtractEntityType/MotorVehicleDrivingComplaint.java
+270
-0
LawyerExtractTypeEnum.java
.../poc/law/ExtractEntityStrategy/LawyerExtractTypeEnum.java
+15
-0
LawyerTemplateExtractServiceBuilder.java
...ctEntityStrategy/LawyerTemplateExtractServiceBuilder.java
+27
-0
AiLawDialoguesDto.java
src/main/java/cn/com/poc/law/dto/AiLawDialoguesDto.java
+22
-0
LegalTemplateDto.java
src/main/java/cn/com/poc/law/dto/LegalTemplateDto.java
+12
-0
MotorVehicleDrivingComplaintEntity.java
...om/poc/law/entity/MotorVehicleDrivingComplaintEntity.java
+111
-0
LegalRest.java
src/main/java/cn/com/poc/law/rest/LegalRest.java
+2
-1
LegalRestImpl.java
src/main/java/cn/com/poc/law/rest/impl/LegalRestImpl.java
+3
-2
AiLawService.java
src/main/java/cn/com/poc/law/service/AiLawService.java
+3
-1
AiLawServiceImpl.java
...in/java/cn/com/poc/law/service/impl/AiLawServiceImpl.java
+16
-186
No files found.
src/main/java/cn/com/poc/law/ExtractEntityStrategy/ExtractEntityStrategy.java
0 → 100644
View file @
aa0fda4b
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
;
}
src/main/java/cn/com/poc/law/ExtractEntityStrategy/ExtractEntityType/MotorVehicleDrivingComplaint.java
0 → 100644
View file @
aa0fda4b
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
;
}
}
src/main/java/cn/com/poc/law/ExtractEntityStrategy/LawyerExtractTypeEnum.java
0 → 100644
View file @
aa0fda4b
package
cn
.
com
.
poc
.
law
.
ExtractEntityStrategy
;
/**
* @Author:Roger Wu
* @name:LawyerExtractType
* @Date:2025-08-08 11:09
*/
public
enum
LawyerExtractTypeEnum
{
motorVehicleDrivingComplaint
;
}
src/main/java/cn/com/poc/law/ExtractEntityStrategy/LawyerTemplateExtractServiceBuilder.java
0 → 100644
View file @
aa0fda4b
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
;
}
}
src/main/java/cn/com/poc/law/dto/AiLawDialoguesDto.java
View file @
aa0fda4b
...
...
@@ -43,6 +43,12 @@ public class AiLawDialoguesDto {
*/
private
boolean
enableDeepThinking
;
/**
*
* @return
*/
private
String
templateCode
;
public
String
getDialoguesId
()
{
return
dialoguesId
;
}
...
...
@@ -98,4 +104,20 @@ public class AiLawDialoguesDto {
public
void
setEnableDeepThinking
(
boolean
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
;
}
}
src/main/java/cn/com/poc/law/dto/LegalTemplateDto.java
0 → 100644
View file @
aa0fda4b
package
cn
.
com
.
poc
.
law
.
dto
;
/**
* @Author:Roger Wu
* @name:LegalTemplateDto
* @Date:2025-08-07 18:22
*/
public
class
LegalTemplateDto
{
}
src/main/java/cn/com/poc/law/entity/MotorVehicleDrivingComplaintEntity.java
0 → 100644
View file @
aa0fda4b
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
;
}
}
src/main/java/cn/com/poc/law/rest/LegalRest.java
View file @
aa0fda4b
...
...
@@ -3,6 +3,7 @@ package cn.com.poc.law.rest;
import
cn.com.poc.ai_finance.dto.AiFinanceDialoguesDto
;
import
cn.com.poc.law.dto.AiLawDialoguesDto
;
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.web.permission.Access
;
import
cn.com.yict.framemax.web.permission.Permission
;
...
...
@@ -31,7 +32,7 @@ public interface LegalRest extends BaseRest {
/**
* templateAi对话
*/
void
templateCall
(
@RequestBody
AiLawDialoguesDto
dto
)
throws
Exception
;
LegalTemplateDto
templateCall
(
@RequestBody
AiLawDialoguesDto
dto
)
throws
Exception
;
}
src/main/java/cn/com/poc/law/rest/impl/LegalRestImpl.java
View file @
aa0fda4b
...
...
@@ -6,6 +6,7 @@ import cn.com.poc.common.utils.Assert;
import
cn.com.poc.common.utils.BlContext
;
import
cn.com.poc.law.dto.AiLawDialoguesDto
;
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.service.AiLawService
;
import
cn.com.poc.support.security.oauth.entity.UserBaseEntity
;
...
...
@@ -65,11 +66,11 @@ public class LegalRestImpl implements LegalRest {
* @param dto
*/
@Override
public
void
templateCall
(
AiLawDialoguesDto
dto
)
throws
Exception
{
public
LegalTemplateDto
templateCall
(
AiLawDialoguesDto
dto
)
throws
Exception
{
UserBaseEntity
userBaseEntity
=
BlContext
.
getCurrentUserNotException
();
if
(
userBaseEntity
==
null
)
{
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
());
}
}
src/main/java/cn/com/poc/law/service/AiLawService.java
View file @
aa0fda4b
package
cn
.
com
.
poc
.
law
.
service
;
import
cn.com.poc.law.dto.LegalTemplateDto
;
/**
* AI财务
*
...
...
@@ -25,5 +27,5 @@ public interface AiLawService {
/**
* @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
;
}
src/main/java/cn/com/poc/law/service/impl/AiLawServiceImpl.java
View file @
aa0fda4b
...
...
@@ -18,9 +18,14 @@ import cn.com.poc.knowledge.aggregate.KnowledgeService;
import
cn.com.poc.knowledge.constant.KnowledgeConstant
;
import
cn.com.poc.knowledge.entity.BizKnowledgeDocumentEntity
;
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.service.AiLawService
;
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.LLMRoleEnum
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.dbchain.DBChainResult
;
...
...
@@ -67,13 +72,6 @@ public class AiLawServiceImpl implements AiLawService {
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
private
BizAiDialoguesService
bizAiDialoguesService
;
...
...
@@ -96,6 +94,8 @@ public class AiLawServiceImpl implements AiLawService {
@Resource
private
BizAgentApplicationGcConfigService
bizAgentApplicationGcConfigService
;
@Resource
LawyerTemplateExtractServiceBuilder
LawyerTemplateExtractServiceBuilder
;
@Override
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 {
/**
* @param dialoguesId
* @param templateCode
* @param input
* @param fileUrl
* @param userId
* @throws Exception
*/
@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
.
setDialoguesId
(
dialoguesId
);
bizAiDialoguesEntity
.
setMemberId
(
userId
);
...
...
@@ -225,11 +228,10 @@ public class AiLawServiceImpl implements AiLawService {
}
BizAiDialoguesEntity
aiDialoguesEntity
=
bizAiDialoguesEntities
.
get
(
0
);
if
(
StringUtils
.
isBlank
(
aiDialoguesEntity
.
getTitle
()))
{
aiDialoguesEntity
.
setDialoguesType
(
AiDialoguesTypeEnum
.
TEMPLATE_LEGAL_DOCUMENT_WRITING
.
getType
());
aiDialoguesEntity
.
setTitle
(
input
);
bizAiDialoguesService
.
update
(
aiDialoguesEntity
);
}
//1.
// 加载文件
String
fileContent
=
StringUtils
.
EMPTY
;
if
(
StringUtils
.
isNoneBlank
(
fileUrl
))
{
...
...
@@ -237,185 +239,13 @@ public class AiLawServiceImpl implements AiLawService {
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
)
{
return
null
;
LegalTemplateDto
legalTemplateDto
=
extractEntityStrategy
.
extractEntity
(
input
+
fileContent
);
return
legalTemplateDto
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment