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
d9e13ce9
Commit
d9e13ce9
authored
Nov 19, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style
parent
51d16f4b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
122 additions
and
182 deletions
+122
-182
AgentApplicationInfoService.java
...nt_application/aggregate/AgentApplicationInfoService.java
+7
-3
AgentApplicationInfoServiceImpl.java
...ation/aggregate/impl/AgentApplicationInfoServiceImpl.java
+23
-63
CreateAgentTitleAndDescEntity.java
...ent_application/entity/CreateAgentTitleAndDescEntity.java
+6
-0
AgentApplicationInfoRestImpl.java
...t_application/rest/impl/AgentApplicationInfoRestImpl.java
+17
-27
AgentApplicationTools.java
...om/poc/agent_application/utils/AgentApplicationTools.java
+13
-3
RedisLimit.java
src/main/java/cn/com/poc/common/annotation/RedisLimit.java
+3
-2
AgentApplicationServiceImpl.java
...oc/expose/aggregate/impl/AgentApplicationServiceImpl.java
+23
-78
AgentLongMemoryEntity.java
...demand/ai/function/long_memory/AgentLongMemoryEntity.java
+1
-2
LongMemory.java
...y/resource/demand/ai/function/long_memory/LongMemory.java
+29
-4
No files found.
src/main/java/cn/com/poc/agent_application/aggregate/AgentApplicationInfoService.java
View file @
d9e13ce9
...
@@ -12,12 +12,16 @@ public interface AgentApplicationInfoService {
...
@@ -12,12 +12,16 @@ public interface AgentApplicationInfoService {
/**
/**
* 创建/更新应用
* 创建/更新应用
*
* @param entity 应用信息
*/
*/
BizAgentApplicationInfoEntity
saveOrUpdate
(
BizAgentApplicationInfoEntity
entity
)
throws
Exception
;
BizAgentApplicationInfoEntity
saveOrUpdate
(
BizAgentApplicationInfoEntity
entity
)
throws
Exception
;
/**
/**
* 更新并发布应用
* 更新并发布应用
*
* @param entity 应用信息
*/
*/
boolean
updateAndPublish
(
BizAgentApplicationInfoEntity
entity
)
throws
Exception
;
boolean
updateAndPublish
(
BizAgentApplicationInfoEntity
entity
)
throws
Exception
;
...
@@ -29,7 +33,7 @@ public interface AgentApplicationInfoService {
...
@@ -29,7 +33,7 @@ public interface AgentApplicationInfoService {
boolean
deletedAgentApplication
(
String
agentId
)
throws
Exception
;
boolean
deletedAgentApplication
(
String
agentId
)
throws
Exception
;
/**
/**
* 应用对话
*
Agent
应用对话
*
*
* @param agentId 应用ID
* @param agentId 应用ID
* @param identifier 对话唯一标识
* @param identifier 对话唯一标识
...
@@ -50,7 +54,7 @@ public interface AgentApplicationInfoService {
...
@@ -50,7 +54,7 @@ public interface AgentApplicationInfoService {
/**
/**
* 应用下架
* 应用下架
*
*
* @param agentId
* @param agentId
应用ID
* @return
* @return
*/
*/
boolean
unPublish
(
String
agentId
)
throws
Exception
;
boolean
unPublish
(
String
agentId
)
throws
Exception
;
...
@@ -58,7 +62,7 @@ public interface AgentApplicationInfoService {
...
@@ -58,7 +62,7 @@ public interface AgentApplicationInfoService {
/**
/**
* 角色指令AI生成
* 角色指令AI生成
*
*
* @param input
* @param input
用户输入内容
* @param httpServletResponse
* @param httpServletResponse
* @return
* @return
*/
*/
...
...
src/main/java/cn/com/poc/agent_application/aggregate/impl/AgentApplicationInfoServiceImpl.java
View file @
d9e13ce9
This diff is collapsed.
Click to expand it.
src/main/java/cn/com/poc/agent_application/entity/CreateAgentTitleAndDescEntity.java
View file @
d9e13ce9
...
@@ -2,8 +2,14 @@ package cn.com.poc.agent_application.entity;
...
@@ -2,8 +2,14 @@ package cn.com.poc.agent_application.entity;
public
class
CreateAgentTitleAndDescEntity
{
public
class
CreateAgentTitleAndDescEntity
{
/**
* 应用名称
*/
private
String
agentTitle
;
private
String
agentTitle
;
/**
* 应用描述
*/
private
String
agentDesc
;
private
String
agentDesc
;
public
String
getAgentTitle
()
{
public
String
getAgentTitle
()
{
...
...
src/main/java/cn/com/poc/agent_application/rest/impl/AgentApplicationInfoRestImpl.java
View file @
d9e13ce9
...
@@ -7,18 +7,19 @@ import cn.com.poc.agent_application.entity.*;
...
@@ -7,18 +7,19 @@ import cn.com.poc.agent_application.entity.*;
import
cn.com.poc.agent_application.query.AgentApplicationInfoQueryCondition
;
import
cn.com.poc.agent_application.query.AgentApplicationInfoQueryCondition
;
import
cn.com.poc.agent_application.rest.AgentApplicationInfoRest
;
import
cn.com.poc.agent_application.rest.AgentApplicationInfoRest
;
import
cn.com.poc.agent_application.service.*
;
import
cn.com.poc.agent_application.service.*
;
import
cn.com.poc.agent_application.utils.AgentApplicationTools
Builder
;
import
cn.com.poc.agent_application.utils.AgentApplicationTools
;
import
cn.com.poc.common.annotation.RedisLimit
;
import
cn.com.poc.common.annotation.RedisLimit
;
import
cn.com.poc.common.constant.CommonConstant
;
import
cn.com.poc.common.constant.CommonConstant
;
import
cn.com.poc.common.service.RedisService
;
import
cn.com.poc.common.utils.BlContext
;
import
cn.com.poc.common.utils.BlContext
;
import
cn.com.poc.knowledge.aggregate.KnowledgeService
;
import
cn.com.poc.knowledge.aggregate.KnowledgeService
;
import
cn.com.poc.support.security.oauth.entity.UserBaseEntity
;
import
cn.com.poc.support.security.oauth.entity.UserBaseEntity
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Tool
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Tool
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.long_memory.SetLongMemoryConstants
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.long_memory.AgentLongMemoryEntity
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.long_memory.LongMemory
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.memory_variable_writer.MemoryVariableWriter
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.memory_variable_writer.MemoryVariableWriter
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.data.model.PagingInfo
;
import
cn.com.yict.framemax.data.model.PagingInfo
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.collection.ListUtil
;
import
cn.hutool.core.collection.ListUtil
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.MapUtils
;
import
org.apache.commons.collections4.MapUtils
;
...
@@ -30,7 +31,10 @@ import javax.annotation.Resource;
...
@@ -30,7 +31,10 @@ import javax.annotation.Resource;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.io.PrintWriter
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
@Component
@Component
...
@@ -51,9 +55,6 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
...
@@ -51,9 +55,6 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
@Resource
@Resource
private
KnowledgeService
knowledgeService
;
private
KnowledgeService
knowledgeService
;
@Resource
private
RedisService
redisService
;
@Resource
@Resource
private
BizMemberAgentApplicationCollectService
bizMemberAgentApplicationCollectService
;
private
BizMemberAgentApplicationCollectService
bizMemberAgentApplicationCollectService
;
...
@@ -212,7 +213,7 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
...
@@ -212,7 +213,7 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
List
<
Integer
>
kdIds
=
knowledgeService
.
getKdIdsByKnowledgeInfoIds
(
infoEntity
.
getKnowledgeIds
());
List
<
Integer
>
kdIds
=
knowledgeService
.
getKdIdsByKnowledgeInfoIds
(
infoEntity
.
getKnowledgeIds
());
//配置对话function
//配置对话function
List
<
Tool
>
tools
=
AgentApplicationTools
Builder
.
buildFunctionConfig
(
infoEntity
.
getVariableStructure
(),
infoEntity
.
getIsLongMemory
(),
dialogueId
,
agentId
,
infoEntity
.
getUnitIds
(),
infoEntity
.
getIsDocumentParsing
());
List
<
Tool
>
tools
=
AgentApplicationTools
.
buildFunctionConfig
(
infoEntity
.
getVariableStructure
(),
infoEntity
.
getIsLongMemory
(),
dialogueId
,
agentId
,
infoEntity
.
getUnitIds
(),
infoEntity
.
getIsDocumentParsing
());
//对话大模型配置
//对话大模型配置
String
model
=
StringUtils
.
isNotBlank
(
dto
.
getModelNickName
())
?
dto
.
getModelNickName
()
:
infoEntity
.
getLargeModel
();
String
model
=
StringUtils
.
isNotBlank
(
dto
.
getModelNickName
())
?
dto
.
getModelNickName
()
:
infoEntity
.
getLargeModel
();
...
@@ -340,35 +341,24 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
...
@@ -340,35 +341,24 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
@Override
@Override
public
List
<
AgentLongMemoryDto
>
getLongMemoryList
(
String
agentId
)
{
public
List
<
AgentLongMemoryDto
>
getLongMemoryList
(
String
agentId
)
{
Assert
.
notNull
(
agentId
);
Assert
.
notNull
(
agentId
);
List
<
AgentLongMemoryDto
>
result
=
new
ArrayList
<>();
List
<
AgentLongMemoryEntity
>
longMemoryEntities
=
LongMemory
.
get
(
AgentApplicationTools
.
identifier
(
agentId
,
agentId
));
String
key
=
agentId
+
":"
+
agentId
;
return
longMemoryEntities
.
stream
().
map
(
value
->
{
String
contentKey
=
SetLongMemoryConstants
.
REDIS_PREFIX
+
key
+
":"
+
BlContext
.
getCurrentUserNotException
().
getUserId
().
toString
();
AgentLongMemoryDto
agentLongMemoryDto
=
new
AgentLongMemoryDto
();
Map
<
Object
,
Object
>
map
=
redisService
.
hmget
(
contentKey
);
BeanUtil
.
copyProperties
(
value
,
agentLongMemoryDto
);
Set
<
Object
>
keySet
=
map
.
keySet
();
return
agentLongMemoryDto
;
}).
sorted
(
Comparator
.
comparing
(
AgentLongMemoryDto:
:
getTimestamp
).
reversed
()).
collect
(
Collectors
.
toList
());
for
(
Object
mapKey
:
keySet
)
{
AgentLongMemoryDto
entity
=
new
AgentLongMemoryDto
();
entity
.
setContent
(
map
.
get
(
mapKey
).
toString
());
entity
.
setTimestamp
(
mapKey
.
toString
());
result
.
add
(
entity
);
}
return
result
.
stream
().
sorted
(
Comparator
.
comparing
(
AgentLongMemoryDto:
:
getTimestamp
).
reversed
()).
collect
(
Collectors
.
toList
());
}
}
@Override
@Override
public
void
deleteLongMemoryByKey
(
String
agentId
,
String
timestamp
)
{
public
void
deleteLongMemoryByKey
(
String
agentId
,
String
timestamp
)
{
Assert
.
notNull
(
agentId
);
Assert
.
notNull
(
agentId
);
Assert
.
notNull
(
timestamp
);
Assert
.
notNull
(
timestamp
);
String
key
=
agentId
+
":"
+
agentId
;
LongMemory
.
delByKey
(
agentId
,
timestamp
);
String
contentKey
=
SetLongMemoryConstants
.
REDIS_PREFIX
+
key
+
":"
+
BlContext
.
getCurrentUserNotException
().
getUserId
().
toString
();
redisService
.
hdel
(
contentKey
,
timestamp
);
}
}
@Override
@Override
public
void
deleteLongMemory
(
String
agentId
)
{
public
void
deleteLongMemory
(
String
agentId
)
{
Assert
.
notNull
(
agentId
);
Assert
.
notNull
(
agentId
);
String
key
=
agentId
+
":"
+
agentId
;
LongMemory
.
clean
(
agentId
);
String
contentKey
=
SetLongMemoryConstants
.
REDIS_PREFIX
+
key
+
":"
+
BlContext
.
getCurrentUserNotException
().
getUserId
().
toString
();
redisService
.
del
(
contentKey
);
}
}
}
}
\ No newline at end of file
src/main/java/cn/com/poc/agent_application/utils/AgentApplicationTools
Builder
.java
→
src/main/java/cn/com/poc/agent_application/utils/AgentApplicationTools.java
View file @
d9e13ce9
...
@@ -15,7 +15,7 @@ import java.util.ArrayList;
...
@@ -15,7 +15,7 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
public
class
AgentApplicationTools
Builder
{
public
class
AgentApplicationTools
{
/**
/**
...
@@ -39,7 +39,7 @@ public class AgentApplicationToolsBuilder {
...
@@ -39,7 +39,7 @@ public class AgentApplicationToolsBuilder {
tools
.
add
(
tool
);
tools
.
add
(
tool
);
//初始化变量函数
//初始化变量函数
Map
<
Object
,
Object
>
map
=
MemoryVariableWriter
.
get
(
identifier
+
":"
+
agentId
);
Map
<
Object
,
Object
>
map
=
MemoryVariableWriter
.
get
(
identifier
(
identifier
,
agentId
)
);
if
(
MapUtils
.
isEmpty
(
map
))
{
if
(
MapUtils
.
isEmpty
(
map
))
{
List
<
Variable
>
variableStructure
=
variableStructures
;
List
<
Variable
>
variableStructure
=
variableStructures
;
for
(
Variable
variable
:
variableStructure
)
{
for
(
Variable
variable
:
variableStructure
)
{
...
@@ -48,7 +48,7 @@ public class AgentApplicationToolsBuilder {
...
@@ -48,7 +48,7 @@ public class AgentApplicationToolsBuilder {
JSONObject
jsonObject
=
new
JSONObject
();
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"key"
,
key
);
jsonObject
.
put
(
"key"
,
key
);
jsonObject
.
put
(
"value"
,
variableDefault
);
jsonObject
.
put
(
"value"
,
variableDefault
);
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
doFunction
(
jsonObject
.
toJSONString
(),
identifier
+
":"
+
agentId
);
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
doFunction
(
jsonObject
.
toJSONString
(),
identifier
(
identifier
,
agentId
)
);
}
}
}
}
}
}
...
@@ -83,5 +83,15 @@ public class AgentApplicationToolsBuilder {
...
@@ -83,5 +83,15 @@ public class AgentApplicationToolsBuilder {
return
tools
;
return
tools
;
}
}
/**
* 创建会话唯一标识符
*
* @param dialogueId 对话ID
* @param agentId 应用ID
* @return
*/
public
static
String
identifier
(
String
dialogueId
,
String
agentId
)
{
return
dialogueId
+
":"
+
agentId
;
}
}
}
src/main/java/cn/com/poc/common/annotation/RedisLimit.java
View file @
d9e13ce9
...
@@ -7,7 +7,7 @@ import java.lang.annotation.*;
...
@@ -7,7 +7,7 @@ import java.lang.annotation.*;
/**
/**
* 限流
* 限流
*/
*/
@Target
(
ElementType
.
METHOD
)
@Target
(
{
ElementType
.
METHOD
,
ElementType
.
TYPE
}
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Component
@Component
@Documented
@Documented
...
@@ -77,7 +77,8 @@ public @interface RedisLimit {
...
@@ -77,7 +77,8 @@ public @interface RedisLimit {
*/
*/
MONTH_OF_YEAR
;
MONTH_OF_YEAR
;
LimitTimeUnit
(){}
LimitTimeUnit
()
{
}
}
}
}
}
src/main/java/cn/com/poc/expose/aggregate/impl/AgentApplicationServiceImpl.java
View file @
d9e13ce9
...
@@ -6,14 +6,13 @@ import cn.com.poc.agent_application.constant.AgentApplicationGCConfigConstants;
...
@@ -6,14 +6,13 @@ import cn.com.poc.agent_application.constant.AgentApplicationGCConfigConstants;
import
cn.com.poc.agent_application.entity.BizAgentApplicationDialoguesRecordEntity
;
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.BizAgentApplicationPublishEntity
;
import
cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity
;
import
cn.com.poc.agent_application.entity.Variable
;
import
cn.com.poc.agent_application.query.MemberCollectQueryCondition
;
import
cn.com.poc.agent_application.query.MemberCollectQueryCondition
;
import
cn.com.poc.agent_application.query.MemberCollectQueryItem
;
import
cn.com.poc.agent_application.query.MemberCollectQueryItem
;
import
cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordService
;
import
cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordService
;
import
cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService
;
import
cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService
;
import
cn.com.poc.agent_application.service.BizAgentApplicationPublishService
;
import
cn.com.poc.agent_application.service.BizAgentApplicationPublishService
;
import
cn.com.poc.agent_application.service.BizMemberAgentApplicationCollectService
;
import
cn.com.poc.agent_application.service.BizMemberAgentApplicationCollectService
;
import
cn.com.poc.agent_application.utils.AgentApplicationTools
Builder
;
import
cn.com.poc.agent_application.utils.AgentApplicationTools
;
import
cn.com.poc.common.constant.CommonConstant
;
import
cn.com.poc.common.constant.CommonConstant
;
import
cn.com.poc.common.constant.XLangConstant
;
import
cn.com.poc.common.constant.XLangConstant
;
import
cn.com.poc.common.service.RedisService
;
import
cn.com.poc.common.service.RedisService
;
...
@@ -22,22 +21,18 @@ import cn.com.poc.common.utils.JsonUtils;
...
@@ -22,22 +21,18 @@ import cn.com.poc.common.utils.JsonUtils;
import
cn.com.poc.expose.aggregate.AgentApplicationService
;
import
cn.com.poc.expose.aggregate.AgentApplicationService
;
import
cn.com.poc.knowledge.aggregate.KnowledgeService
;
import
cn.com.poc.knowledge.aggregate.KnowledgeService
;
import
cn.com.poc.support.security.oauth.entity.UserBaseEntity
;
import
cn.com.poc.support.security.oauth.entity.UserBaseEntity
;
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.MultiContent
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.MultiContent
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Tool
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Tool
;
import
cn.com.poc.thirdparty.resource.demand.ai.constants.LLMRoleEnum
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelDemandResult
;
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.resource.demand.ai.function.LargeModelFunctionEnum
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.memory_variable_writer.MemoryVariableWriter
;
import
cn.com.poc.thirdparty.service.LLMService
;
import
cn.com.poc.thirdparty.service.LLMService
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.data.model.PagingInfo
;
import
cn.com.yict.framemax.data.model.PagingInfo
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.github.houbb.opencc4j.util.ZhConverterUtil
;
import
com.github.houbb.opencc4j.util.ZhConverterUtil
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.MapUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -46,7 +41,10 @@ import org.springframework.stereotype.Service;
...
@@ -46,7 +41,10 @@ import org.springframework.stereotype.Service;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.security.SecureRandom
;
import
java.security.SecureRandom
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
@Service
@Service
...
@@ -54,6 +52,9 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
...
@@ -54,6 +52,9 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
final
private
Logger
logger
=
LoggerFactory
.
getLogger
(
AgentApplicationService
.
class
);
final
private
Logger
logger
=
LoggerFactory
.
getLogger
(
AgentApplicationService
.
class
);
/**
* 推荐问Key
*/
final
private
String
AGENT_APPLICATION_RECOMMEND_QUESTIONS
=
"AGENT_APPLICATION_RECOMMEND_QUESTIONS:"
;
final
private
String
AGENT_APPLICATION_RECOMMEND_QUESTIONS
=
"AGENT_APPLICATION_RECOMMEND_QUESTIONS:"
;
/**
/**
...
@@ -103,7 +104,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
...
@@ -103,7 +104,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
if
(
StringUtils
.
isBlank
(
dialogsId
))
{
if
(
StringUtils
.
isBlank
(
dialogsId
))
{
// 用于针对只有单Agent应用分享使用的场景,dialogsId为空
// 用于针对只有单Agent应用分享使用的场景,dialogsId为空
dialogsId
=
agentId
+
"
_
"
+
userBaseEntity
.
getUserId
();
dialogsId
=
agentId
+
"
-
"
+
userBaseEntity
.
getUserId
();
}
}
//获取知识库配置
//获取知识库配置
...
@@ -124,10 +125,10 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
...
@@ -124,10 +125,10 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
bizAgentApplicationDialoguesRecordService
.
save
(
inputRecord
);
bizAgentApplicationDialoguesRecordService
.
save
(
inputRecord
);
//配置对话function
//配置对话function
List
<
Tool
>
tools
=
AgentApplicationTools
Builder
.
buildFunctionConfig
(
infoEntity
.
getVariableStructure
(),
infoEntity
.
getIsLongMemory
(),
dialogsId
,
agentId
,
infoEntity
.
getUnitIds
(),
infoEntity
.
getIsDocumentParsing
());
List
<
Tool
>
tools
=
AgentApplicationTools
.
buildFunctionConfig
(
infoEntity
.
getVariableStructure
(),
infoEntity
.
getIsLongMemory
(),
dialogsId
,
agentId
,
infoEntity
.
getUnitIds
(),
infoEntity
.
getIsDocumentParsing
());
//
记录输出时间戳
//记录输出时间戳
BizAgentApplicationDialoguesRecordEntity
outputRecord
=
new
BizAgentApplicationDialoguesRecordEntity
();
BizAgentApplicationDialoguesRecordEntity
outputRecord
=
new
BizAgentApplicationDialoguesRecordEntity
();
outputRecord
.
setRole
(
AgentApplicationDialoguesRecordConstants
.
ROLE
.
ASSISTANT
);
outputRecord
.
setRole
(
AgentApplicationDialoguesRecordConstants
.
ROLE
.
ASSISTANT
);
outputRecord
.
setAgentId
(
infoEntity
.
getAgentId
());
outputRecord
.
setAgentId
(
infoEntity
.
getAgentId
());
...
@@ -255,6 +256,17 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
...
@@ -255,6 +256,17 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
createENQuestion
();
createENQuestion
();
}
}
@Override
public
List
<
MemberCollectQueryItem
>
getCollectedApplications
(
Long
memberId
,
PagingInfo
pagingInfo
)
{
MemberCollectQueryCondition
condition
=
new
MemberCollectQueryCondition
();
condition
.
setMemberId
(
memberId
);
condition
.
setIsCollect
(
CommonConstant
.
YOrN
.
Y
);
List
<
MemberCollectQueryItem
>
memberCollectQueryItems
=
bizMemberAgentApplicationCollectService
.
queryMemberCollect
(
condition
,
pagingInfo
);
return
memberCollectQueryItems
;
}
private
void
createCNQuestion
()
{
private
void
createCNQuestion
()
{
Message
message
=
new
Message
();
Message
message
=
new
Message
();
message
.
setRole
(
LLMRoleEnum
.
USER
.
getRole
());
message
.
setRole
(
LLMRoleEnum
.
USER
.
getRole
());
...
@@ -308,15 +320,6 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
...
@@ -308,15 +320,6 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
redisService
.
lSet
(
AGENT_APPLICATION_RECOMMEND_QUESTIONS
+
"en"
,
questions
);
redisService
.
lSet
(
AGENT_APPLICATION_RECOMMEND_QUESTIONS
+
"en"
,
questions
);
}
}
@Override
public
List
<
MemberCollectQueryItem
>
getCollectedApplications
(
Long
memberId
,
PagingInfo
pagingInfo
)
{
MemberCollectQueryCondition
condition
=
new
MemberCollectQueryCondition
();
condition
.
setMemberId
(
memberId
);
condition
.
setIsCollect
(
CommonConstant
.
YOrN
.
Y
);
List
<
MemberCollectQueryItem
>
memberCollectQueryItems
=
bizMemberAgentApplicationCollectService
.
queryMemberCollect
(
condition
,
pagingInfo
);
return
memberCollectQueryItems
;
}
private
List
<
Message
>
buildMessages
(
String
dialogsId
,
String
agentId
,
Long
userId
,
String
input
)
throws
Exception
{
private
List
<
Message
>
buildMessages
(
String
dialogsId
,
String
agentId
,
Long
userId
,
String
input
)
throws
Exception
{
List
<
Message
>
messages
=
new
ArrayList
<>();
List
<
Message
>
messages
=
new
ArrayList
<>();
BizAgentApplicationDialoguesRecordEntity
recordEntity
=
new
BizAgentApplicationDialoguesRecordEntity
();
BizAgentApplicationDialoguesRecordEntity
recordEntity
=
new
BizAgentApplicationDialoguesRecordEntity
();
...
@@ -351,62 +354,4 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
...
@@ -351,62 +354,4 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
logger
.
info
(
"--------- Build Messages dialogsId:{},agentId:{},messages:{}--------------"
,
dialogsId
,
agentId
,
messages
);
logger
.
info
(
"--------- Build Messages dialogsId:{},agentId:{},messages:{}--------------"
,
dialogsId
,
agentId
,
messages
);
return
messages
;
return
messages
;
}
}
@Deprecated
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
List
<
Tool
>
buildMemoryConfig
(
BizAgentApplicationPublishEntity
infoEntity
,
String
identifier
)
{
List
<
Tool
>
tools
=
new
ArrayList
<>();
//开启对话变量
if
(
CollectionUtils
.
isNotEmpty
(
infoEntity
.
getVariableStructure
()))
{
String
functionName
=
LargeModelFunctionEnum
.
memory_variable_writer
.
name
();
String
llmConfig
=
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
getLLMConfig
(
infoEntity
.
getVariableStructure
()).
get
(
0
);
Tool
tool
=
JsonUtils
.
deSerialize
(
llmConfig
,
Tool
.
class
);
tools
.
add
(
tool
);
//初始化变量函数
Map
<
Object
,
Object
>
map
=
MemoryVariableWriter
.
get
(
identifier
+
":"
+
infoEntity
.
getAgentId
());
if
(
MapUtils
.
isEmpty
(
map
))
{
List
<
Variable
>
variableStructure
=
infoEntity
.
getVariableStructure
();
for
(
Variable
variable
:
variableStructure
)
{
String
key
=
variable
.
getKey
();
String
variableDefault
=
variable
.
getVariableDefault
();
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"key"
,
key
);
jsonObject
.
put
(
"value"
,
variableDefault
);
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
doFunction
(
jsonObject
.
toJSONString
(),
identifier
+
":"
+
infoEntity
.
getAgentId
());
}
}
}
//开启长期记忆
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/thirdparty/resource/demand/ai/function/long_memory/LongMemoryEntity.java
→
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/function/long_memory/
Agent
LongMemoryEntity.java
View file @
d9e13ce9
package
cn
.
com
.
poc
.
thirdparty
.
resource
.
demand
.
ai
.
function
.
long_memory
;
package
cn
.
com
.
poc
.
thirdparty
.
resource
.
demand
.
ai
.
function
.
long_memory
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.Date
;
public
class
LongMemoryEntity
implements
Serializable
{
public
class
Agent
LongMemoryEntity
implements
Serializable
{
private
String
content
;
private
String
content
;
...
...
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/function/long_memory/LongMemory.java
View file @
d9e13ce9
package
cn
.
com
.
poc
.
thirdparty
.
resource
.
demand
.
ai
.
function
.
long_memory
;
package
cn
.
com
.
poc
.
thirdparty
.
resource
.
demand
.
ai
.
function
.
long_memory
;
import
cn.com.poc.agent_application.utils.AgentApplicationTools
;
import
cn.com.poc.common.service.RedisService
;
import
cn.com.poc.common.service.RedisService
;
import
cn.com.poc.common.utils.BlContext
;
import
cn.com.poc.common.utils.BlContext
;
import
cn.com.poc.common.utils.SpringUtils
;
import
cn.com.poc.common.utils.SpringUtils
;
...
@@ -11,16 +12,16 @@ import java.util.Set;
...
@@ -11,16 +12,16 @@ import java.util.Set;
public
class
LongMemory
{
public
class
LongMemory
{
public
static
List
<
LongMemoryEntity
>
get
(
String
key
)
{
public
static
List
<
AgentLongMemoryEntity
>
get
(
String
identifier
)
{
RedisService
redisService
=
SpringUtils
.
getBean
(
RedisService
.
class
);
RedisService
redisService
=
SpringUtils
.
getBean
(
RedisService
.
class
);
List
<
LongMemoryEntity
>
result
=
new
ArrayList
<>();
List
<
Agent
LongMemoryEntity
>
result
=
new
ArrayList
<>();
// 查询用户相关信息(什么内容都可以)
// 查询用户相关信息(什么内容都可以)
String
contentKey
=
SetLongMemoryConstants
.
REDIS_PREFIX
+
key
+
":"
+
BlContext
.
getCurrentUserNotException
().
getUserId
().
toString
();
String
contentKey
=
SetLongMemoryConstants
.
REDIS_PREFIX
+
identifier
+
":"
+
BlContext
.
getCurrentUserNotException
().
getUserId
().
toString
();
Map
<
Object
,
Object
>
map
=
redisService
.
hmget
(
contentKey
);
Map
<
Object
,
Object
>
map
=
redisService
.
hmget
(
contentKey
);
Set
<
Object
>
keySet
=
map
.
keySet
();
Set
<
Object
>
keySet
=
map
.
keySet
();
for
(
Object
mapKey
:
keySet
)
{
for
(
Object
mapKey
:
keySet
)
{
LongMemoryEntity
entity
=
new
LongMemoryEntity
();
AgentLongMemoryEntity
entity
=
new
Agent
LongMemoryEntity
();
entity
.
setContent
(
map
.
get
(
mapKey
).
toString
());
entity
.
setContent
(
map
.
get
(
mapKey
).
toString
());
entity
.
setTimestamp
(
mapKey
.
toString
());
entity
.
setTimestamp
(
mapKey
.
toString
());
result
.
add
(
entity
);
result
.
add
(
entity
);
...
@@ -28,4 +29,28 @@ public class LongMemory {
...
@@ -28,4 +29,28 @@ public class LongMemory {
return
result
;
return
result
;
}
}
/**
* 清除用户在在应用的长期记忆内容
*
* @param agentId
*/
public
static
void
clean
(
String
agentId
)
{
RedisService
redisService
=
SpringUtils
.
getBean
(
RedisService
.
class
);
String
key
=
AgentApplicationTools
.
identifier
(
agentId
,
agentId
);
String
contentKey
=
SetLongMemoryConstants
.
REDIS_PREFIX
+
key
+
":"
+
BlContext
.
getCurrentUserNotException
().
getUserId
().
toString
();
redisService
.
del
(
contentKey
);
}
/**
* 根据时间戳 删除用户在应用的长期记忆 某个时间保存的内容
*
* @param agentId 应用id
* @param item 时间戳
*/
public
static
void
delByKey
(
String
agentId
,
String
item
)
{
RedisService
redisService
=
SpringUtils
.
getBean
(
RedisService
.
class
);
String
key
=
AgentApplicationTools
.
identifier
(
agentId
,
agentId
);
String
contentKey
=
SetLongMemoryConstants
.
REDIS_PREFIX
+
key
+
":"
+
BlContext
.
getCurrentUserNotException
().
getUserId
().
toString
();
redisService
.
hdel
(
contentKey
,
item
);
}
}
}
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