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
c65615be
Commit
c65615be
authored
Oct 25, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:期望用户发送信息后就会生成历史记录,而不是等回答完才生成
parent
b417649c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
33 deletions
+56
-33
BizAgentApplicationDialoguesRecordService.java
...on/service/BizAgentApplicationDialoguesRecordService.java
+1
-1
BizAgentApplicationDialoguesRecordServiceImpl.java
...e/impl/BizAgentApplicationDialoguesRecordServiceImpl.java
+1
-1
AgentApplicationServiceImpl.java
...oc/expose/aggregate/impl/AgentApplicationServiceImpl.java
+54
-31
No files found.
src/main/java/cn/com/poc/agent_application/service/BizAgentApplicationDialoguesRecordService.java
View file @
c65615be
...
...
@@ -19,7 +19,7 @@ public interface BizAgentApplicationDialoguesRecordService extends BaseService {
BizAgentApplicationDialoguesRecordEntity
update
(
BizAgentApplicationDialoguesRecordEntity
entity
)
throws
Exception
;
void
deletedById
(
java
.
lang
.
Long
id
)
throws
Exception
;
void
deletedById
(
java
.
lang
.
Long
id
)
;
List
<
BizAgentApplicationDialoguesRecordEntity
>
getRecord
(
String
agentId
,
Integer
turn
);
...
...
src/main/java/cn/com/poc/agent_application/service/impl/BizAgentApplicationDialoguesRecordServiceImpl.java
View file @
c65615be
...
...
@@ -121,7 +121,7 @@ public class BizAgentApplicationDialoguesRecordServiceImpl extends BaseServiceIm
return
BizAgentApplicationDialoguesRecordConvert
.
modelToEntity
(
saveModel
);
}
public
void
deletedById
(
java
.
lang
.
Long
id
)
throws
Exception
{
public
void
deletedById
(
Long
id
)
{
Assert
.
notNull
(
id
);
BizAgentApplicationDialoguesRecordModel
model
=
this
.
repository
.
get
(
id
);
if
(
model
!=
null
)
{
...
...
src/main/java/cn/com/poc/expose/aggregate/impl/AgentApplicationServiceImpl.java
View file @
c65615be
...
...
@@ -10,7 +10,6 @@ import cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordSe
import
cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService
;
import
cn.com.poc.agent_application.service.BizAgentApplicationPublishService
;
import
cn.com.poc.common.constant.CommonConstant
;
import
cn.com.poc.common.pool.CommonThreadPoolExecutor
;
import
cn.com.poc.common.service.RedisService
;
import
cn.com.poc.common.utils.BlContext
;
import
cn.com.poc.common.utils.JsonUtils
;
...
...
@@ -40,7 +39,6 @@ import java.util.ArrayList;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.concurrent.*
;
@Service
public
class
AgentApplicationServiceImpl
implements
AgentApplicationService
{
...
...
@@ -72,44 +70,69 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
@Override
public
void
callAgentApplication
(
String
agentId
,
String
dialogsId
,
String
input
,
HttpServletResponse
httpServletResponse
)
throws
Exception
{
public
void
callAgentApplication
(
String
agentId
,
String
dialogsId
,
String
input
,
HttpServletResponse
httpServletResponse
)
{
UserBaseEntity
userBaseEntity
=
BlContext
.
getCurrentUserNotException
();
if
(
userBaseEntity
==
null
)
{
throw
new
BusinessException
(
"用户未登录"
);
}
// 记录输入时间戳
Long
inputTimestamp
=
System
.
currentTimeMillis
();
Long
userRecordId
=
null
;
try
{
BizAgentApplicationPublishEntity
infoEntity
=
bizAgentApplicationPublishService
.
getByAgentId
(
agentId
);
if
(
infoEntity
==
null
)
{
logger
.
warn
(
"can not find agent application , agent_id:{}"
,
agentId
);
throw
new
BusinessException
(
"未找到应用"
);
}
BizAgentApplicationPublishEntity
infoEntity
=
bizAgentApplicationPublishService
.
getByAgentId
(
agentId
);
if
(
infoEntity
==
null
)
{
logger
.
warn
(
"can not find agent application , agent_id:{}"
,
agentId
);
throw
new
BusinessException
(
"未找到应用"
);
}
if
(
StringUtils
.
isBlank
(
dialogsId
))
{
// 用于针对只有单Agent应用分享使用的场景,dialogsId为空
dialogsId
=
agentId
+
"_"
+
userBaseEntity
.
getUserId
();
}
if
(
StringUtils
.
isBlank
(
dialogsId
))
{
// 用于针对只有单Agent应用分享使用的场景,dialogsId为空
dialogsId
=
agentId
+
"_"
+
userBaseEntity
.
getUserId
();
//获取知识库配置
List
<
Integer
>
kdIdList
=
knowledgeService
.
getKdIdsByKnowledgeInfoIds
(
infoEntity
.
getKnowledgeIds
());
// 记录输入时间戳
Long
inputTimestamp
=
System
.
currentTimeMillis
();
BizAgentApplicationDialoguesRecordEntity
inputRecord
=
new
BizAgentApplicationDialoguesRecordEntity
();
inputRecord
.
setAgentId
(
agentId
);
inputRecord
.
setMemberId
(
userBaseEntity
.
getUserId
());
inputRecord
.
setContent
(
input
);
inputRecord
.
setDialogsId
(
dialogsId
);
inputRecord
.
setRole
(
AgentApplicationDialoguesRecordConstants
.
ROLE
.
USER
);
inputRecord
.
setTimestamp
(
inputTimestamp
);
BizAgentApplicationDialoguesRecordEntity
saveRecord
=
bizAgentApplicationDialoguesRecordService
.
save
(
inputRecord
);
userRecordId
=
saveRecord
.
getId
();
// 构造对话参数
List
<
Message
>
messages
=
buildMessages
(
dialogsId
,
agentId
,
userBaseEntity
.
getUserId
(),
input
);
//配置对话function
List
<
Tool
>
tools
=
buildMemoryConfig
(
infoEntity
);
// 记录输出时间戳
BizAgentApplicationDialoguesRecordEntity
outputRecord
=
new
BizAgentApplicationDialoguesRecordEntity
();
outputRecord
.
setRole
(
AgentApplicationDialoguesRecordConstants
.
ROLE
.
ASSISTANT
);
outputRecord
.
setAgentId
(
infoEntity
.
getAgentId
());
outputRecord
.
setDialogsId
(
dialogsId
);
outputRecord
.
setMemberId
(
userBaseEntity
.
getUserId
());
outputRecord
.
setTimestamp
(
System
.
currentTimeMillis
());
//对话
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
);
//保存对话记录
outputRecord
.
setContent
(
output
);
bizAgentApplicationDialoguesRecordService
.
save
(
outputRecord
);
}
catch
(
Exception
e
)
{
if
(
userRecordId
!=
null
){
bizAgentApplicationDialoguesRecordService
.
deletedById
(
userRecordId
);
}
}
//获取知识库配置
List
<
Integer
>
kdIdList
=
knowledgeService
.
getKdIdsByKnowledgeInfoIds
(
infoEntity
.
getKnowledgeIds
());
// 构造对话参数
List
<
Message
>
messages
=
buildMessages
(
dialogsId
,
agentId
,
userBaseEntity
.
getUserId
(),
input
);
//配置对话function
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
);
//保存对话记录
saveDialoguesRecord
(
dialogsId
,
input
,
infoEntity
,
userBaseEntity
,
inputTimestamp
,
output
);
}
...
...
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