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
2bece1b0
Commit
2bece1b0
authored
Oct 23, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style: 优化编码
parent
6a719e97
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
43 deletions
+60
-43
AgentApplicationServiceImpl.java
...oc/expose/aggregate/impl/AgentApplicationServiceImpl.java
+59
-42
KnowledgeServiceImpl.java
...om/poc/knowledge/aggregate/impl/KnowledgeServiceImpl.java
+1
-1
No files found.
src/main/java/cn/com/poc/expose/aggregate/impl/AgentApplicationServiceImpl.java
View file @
2bece1b0
...
...
@@ -87,59 +87,31 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
throw
new
BusinessException
(
"未找到应用"
);
}
if
(
StringUtils
.
isBlank
(
dialogsId
))
{
// 用于针对只有单Agent应用分享使用的场景,dialogsId为空
dialogsId
=
agentId
+
"_"
+
userBaseEntity
.
getUserId
();
}
//获取知识库配置
List
<
Integer
>
kdIdList
=
knowledgeService
.
getKdIdsByKnowledgeInfoIds
(
infoEntity
.
getKnowledgeIds
());
// 构造对话参数
List
<
Message
>
messages
=
new
ArrayList
<>();
buildMessages
(
dialogsId
,
agentId
,
userBaseEntity
.
getUserId
(),
messages
,
input
);
List
<
Message
>
messages
=
buildMessages
(
dialogsId
,
agentId
,
userBaseEntity
.
getUserId
(),
input
);
//配置对话function
List
<
Tool
>
tools
=
new
ArrayList
<>();
//开启对话变量
if
(
ArrayUtils
.
isNotEmpty
(
infoEntity
.
getVariableStructure
()))
{
String
functionName
=
"set_value_memory"
;
String
llmConfig
=
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
getVariableStructureLLMConfig
(
infoEntity
.
getVariableStructure
()).
get
(
0
);
Tool
tool
=
JsonUtils
.
deSerialize
(
llmConfig
,
Tool
.
class
);
tools
.
add
(
tool
);
}
//开启长期记忆
if
(
CommonConstant
.
YOrN
.
Y
.
equals
(
infoEntity
.
getIsLongMemory
()))
{
String
functionName
=
"set_long_memory"
;
String
llmConfig
=
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
getLLMConfig
().
get
(
0
);
Tool
tool
=
JsonUtils
.
deSerialize
(
llmConfig
,
Tool
.
class
);
tools
.
add
(
tool
);
}
List
<
Tool
>
tools
=
buildMemoryConfig
(
infoEntity
);
//对话
String
output
=
agentApplicationInfoService
.
callAgentApplication
(
dialogsId
,
infoEntity
.
getLargeModel
(),
infoEntity
.
getUnitIds
(),
infoEntity
.
getAgentSystem
(),
kdIdList
.
toArray
(
new
Integer
[
0
]),
infoEntity
.
getCommunicationTurn
(),
infoEntity
.
getTopP
(),
infoEntity
.
getTemperature
(),
messages
,
tools
,
httpServletResponse
);
//保存对话记录
// 例句回答时间戳
Long
outputTimestamp
=
System
.
currentTimeMillis
();
BizAgentApplicationDialoguesRecordEntity
inputRecord
=
new
BizAgentApplicationDialoguesRecordEntity
();
inputRecord
.
setAgentId
(
infoEntity
.
getAgentId
());
inputRecord
.
setMemberId
(
userBaseEntity
.
getUserId
());
inputRecord
.
setContent
(
input
);
inputRecord
.
setDialogsId
(
dialogsId
);
inputRecord
.
setRole
(
AgentApplicationDialoguesRecordConstants
.
ROLE
.
USER
);
inputRecord
.
setTimestamp
(
inputTimestamp
);
BizAgentApplicationDialoguesRecordEntity
outputRecord
=
new
BizAgentApplicationDialoguesRecordEntity
();
outputRecord
.
setRole
(
AgentApplicationDialoguesRecordConstants
.
ROLE
.
ASSISTANT
);
outputRecord
.
setAgentId
(
infoEntity
.
getAgentId
());
outputRecord
.
setDialogsId
(
dialogsId
);
outputRecord
.
setMemberId
(
userBaseEntity
.
getUserId
());
outputRecord
.
setContent
(
output
);
outputRecord
.
setTimestamp
(
outputTimestamp
);
bizAgentApplicationDialoguesRecordService
.
save
(
inputRecord
);
bizAgentApplicationDialoguesRecordService
.
save
(
outputRecord
);
saveDialoguesRecord
(
dialogsId
,
input
,
infoEntity
,
userBaseEntity
,
inputTimestamp
,
output
);
}
@Override
public
List
<
String
>
createContinueQuestions
(
String
input
)
{
BizAgentApplicationGcConfigEntity
configEntity
=
bizAgentApplicationGcConfigService
.
getByConfigCode
(
AgentApplicationGCConfigConstants
.
AGENT_CONTINUE_QUESTIONS
);
...
...
@@ -167,12 +139,10 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
}}.
toArray
(
new
Message
[
1
]));
largeModelResponse
.
setTopP
(
configEntity
.
getTopP
());
largeModelResponse
.
setUser
(
"POC-CONTINUE-QUESTIONS"
);
LargeModelDemandResult
largeModelDemandResult
=
llmService
.
chat
(
largeModelResponse
);
if
(
largeModelDemandResult
==
null
||
!
"0"
.
equals
(
largeModelDemandResult
.
getCode
()))
{
logger
.
error
(
"continue question error ,largeModelDemandResult:{} , largeModelResponse:{}"
,
largeModelDemandResult
!=
null
?
largeModelDemandResult
.
toString
()
:
StringUtils
.
EMPTY
,
largeModelResponse
);
// throw new BusinessException("追问失败");
return
null
;
}
String
res
=
largeModelDemandResult
.
getMessage
();
...
...
@@ -212,6 +182,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
return
result
;
}
@Override
public
void
createRecommendQuestion
()
throws
InterruptedException
{
List
<
Object
>
questions
=
new
CopyOnWriteArrayList
<>();
ThreadPoolExecutor
threadPoolExecutor
=
new
ThreadPoolExecutor
(
10
,
10
,
5
,
TimeUnit
.
SECONDS
,
new
LinkedBlockingDeque
<>());
...
...
@@ -238,13 +209,16 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
countDownLatch
.
countDown
();
});
}
countDownLatch
.
await
(
2
,
TimeUnit
.
MINUTES
);
if
(
CollectionUtils
.
isEmpty
(
questions
))
{
throw
new
BusinessException
(
"生成推荐问题失败"
);
}
redisService
.
del
(
AGENT_APPLICATION_RECOMMEND_QUESTIONS
);
redisService
.
lSet
(
AGENT_APPLICATION_RECOMMEND_QUESTIONS
,
questions
);
}
private
void
buildMessages
(
String
dialogsId
,
String
agentId
,
Long
userId
,
List
<
Message
>
messages
,
String
input
)
throws
Exception
{
private
List
<
Message
>
buildMessages
(
String
dialogsId
,
String
agentId
,
Long
userId
,
String
input
)
throws
Exception
{
List
<
Message
>
messages
=
new
ArrayList
<>();
BizAgentApplicationDialoguesRecordEntity
recordEntity
=
new
BizAgentApplicationDialoguesRecordEntity
();
recordEntity
.
setDialogsId
(
dialogsId
);
recordEntity
.
setMemberId
(
userId
);
...
...
@@ -273,6 +247,49 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
message
.
setRole
(
AgentApplicationDialoguesRecordConstants
.
ROLE
.
USER
);
messages
.
add
(
message
);
logger
.
info
(
"--------- Build Messages dialogsId:{},agentId:{},messages:{}--------------"
,
dialogsId
,
agentId
,
messages
);
return
messages
;
}
private
void
saveDialoguesRecord
(
String
dialogsId
,
String
input
,
BizAgentApplicationPublishEntity
infoEntity
,
UserBaseEntity
userBaseEntity
,
Long
inputTimestamp
,
String
output
)
throws
Exception
{
// 回答时间戳
Long
outputTimestamp
=
System
.
currentTimeMillis
();
BizAgentApplicationDialoguesRecordEntity
inputRecord
=
new
BizAgentApplicationDialoguesRecordEntity
();
inputRecord
.
setAgentId
(
infoEntity
.
getAgentId
());
inputRecord
.
setMemberId
(
userBaseEntity
.
getUserId
());
inputRecord
.
setContent
(
input
);
inputRecord
.
setDialogsId
(
dialogsId
);
inputRecord
.
setRole
(
AgentApplicationDialoguesRecordConstants
.
ROLE
.
USER
);
inputRecord
.
setTimestamp
(
inputTimestamp
);
BizAgentApplicationDialoguesRecordEntity
outputRecord
=
new
BizAgentApplicationDialoguesRecordEntity
();
outputRecord
.
setRole
(
AgentApplicationDialoguesRecordConstants
.
ROLE
.
ASSISTANT
);
outputRecord
.
setAgentId
(
infoEntity
.
getAgentId
());
outputRecord
.
setDialogsId
(
dialogsId
);
outputRecord
.
setMemberId
(
userBaseEntity
.
getUserId
());
outputRecord
.
setContent
(
output
);
outputRecord
.
setTimestamp
(
outputTimestamp
);
bizAgentApplicationDialoguesRecordService
.
save
(
inputRecord
);
bizAgentApplicationDialoguesRecordService
.
save
(
outputRecord
);
}
private
static
List
<
Tool
>
buildMemoryConfig
(
BizAgentApplicationPublishEntity
infoEntity
)
{
List
<
Tool
>
tools
=
new
ArrayList
<>();
//开启对话变量
if
(
ArrayUtils
.
isNotEmpty
(
infoEntity
.
getVariableStructure
()))
{
String
functionName
=
LargeModelFunctionEnum
.
set_value_memory
.
name
();
String
llmConfig
=
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
getVariableStructureLLMConfig
(
infoEntity
.
getVariableStructure
()).
get
(
0
);
Tool
tool
=
JsonUtils
.
deSerialize
(
llmConfig
,
Tool
.
class
);
tools
.
add
(
tool
);
}
//开启长期记忆
if
(
CommonConstant
.
YOrN
.
Y
.
equals
(
infoEntity
.
getIsLongMemory
()))
{
String
functionName
=
LargeModelFunctionEnum
.
set_long_memory
.
name
();
String
llmConfig
=
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
getLLMConfig
().
get
(
0
);
Tool
tool
=
JsonUtils
.
deSerialize
(
llmConfig
,
Tool
.
class
);
tools
.
add
(
tool
);
}
return
tools
;
}
}
src/main/java/cn/com/poc/knowledge/aggregate/impl/KnowledgeServiceImpl.java
View file @
2bece1b0
...
...
@@ -91,7 +91,7 @@ public class KnowledgeServiceImpl implements KnowledgeService {
//获取文件字符数
long
charCount
=
fileContent
.
length
();
//文件字符数不能超过100w
if
(
charCount
>
2
*
10000
)
{
if
(
charCount
>
100
*
10000
)
{
throw
new
BusinessException
(
"文件内容字符数不能超过2w,文件名: "
+
documentName
);
}
...
...
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