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
ef6af236
Commit
ef6af236
authored
Nov 01, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 初始化 valueMemory 函数
parent
f58c7624
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
17 deletions
+47
-17
AgentApplicationInfoRestImpl.java
...t_application/rest/impl/AgentApplicationInfoRestImpl.java
+23
-6
AgentApplicationServiceImpl.java
...oc/expose/aggregate/impl/AgentApplicationServiceImpl.java
+24
-11
No files found.
src/main/java/cn/com/poc/agent_application/rest/impl/AgentApplicationInfoRestImpl.java
View file @
ef6af236
...
@@ -16,11 +16,13 @@ import cn.com.poc.support.security.oauth.entity.UserBaseEntity;
...
@@ -16,11 +16,13 @@ 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.LargeModelFunctionEnum
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.LargeModelFunctionEnum
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.long_memory.SetLongMemoryConstants
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.long_memory.SetLongMemoryConstants
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.value_memory.GetValueMemory
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
cn.com.yict.framemax.data.model.PagingInfo
;
import
cn.com.yict.framemax.data.model.PagingInfo
;
import
cn.hutool.core.collection.ListUtil
;
import
cn.hutool.core.collection.ListUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.
lang3.Array
Utils
;
import
org.apache.commons.
collections4.Map
Utils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
...
@@ -29,7 +31,10 @@ import javax.annotation.Resource;
...
@@ -29,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.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
@Component
@Component
...
@@ -205,11 +210,23 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
...
@@ -205,11 +210,23 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
List
<
Tool
>
tools
=
new
ArrayList
<>();
List
<
Tool
>
tools
=
new
ArrayList
<>();
//开启对话变量
//开启对话变量
if
(
CollectionUtils
.
isNotEmpty
(
infoEntity
.
getVariableStructure
()))
{
if
(
CollectionUtils
.
isNotEmpty
(
infoEntity
.
getVariableStructure
()))
{
//todo 修正
String
functionName
=
LargeModelFunctionEnum
.
set_value_memory
.
name
();
String
functionName
=
LargeModelFunctionEnum
.
set_value_memory
.
name
();
// String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getVariableStructureLLMConfig(infoEntity.getVariableStructure()).get(0);
String
llmConfig
=
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
getVariableStructureLLMConfig
(
infoEntity
.
getVariableStructure
()).
get
(
0
);
// Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class);
Tool
tool
=
JsonUtils
.
deSerialize
(
llmConfig
,
Tool
.
class
);
// tools.add(tool);
tools
.
add
(
tool
);
//初始化变量函数
Map
<
Object
,
Object
>
map
=
GetValueMemory
.
get
(
agentId
);
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
,
variableDefault
);
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
doFunction
(
jsonObject
.
toJSONString
(),
agentId
);
}
}
}
}
//开启长期记忆
//开启长期记忆
if
(
CommonConstant
.
YOrN
.
Y
.
equals
(
infoEntity
.
getIsLongMemory
()))
{
if
(
CommonConstant
.
YOrN
.
Y
.
equals
(
infoEntity
.
getIsLongMemory
()))
{
...
...
src/main/java/cn/com/poc/expose/aggregate/impl/AgentApplicationServiceImpl.java
View file @
ef6af236
...
@@ -6,6 +6,7 @@ import cn.com.poc.agent_application.constant.AgentApplicationGCConfigConstants;
...
@@ -6,6 +6,7 @@ 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
;
...
@@ -26,11 +27,14 @@ import cn.com.poc.thirdparty.resource.demand.ai.constants.LLMRoleEnum;
...
@@ -26,11 +27,14 @@ 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.LargeModelFunctionEnum
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.value_memory.GetValueMemory
;
import
cn.com.poc.thirdparty.service.LLMService
;
import
cn.com.poc.thirdparty.service.LLMService
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
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
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.MapUtils
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -40,10 +44,7 @@ import org.springframework.stereotype.Service;
...
@@ -40,10 +44,7 @@ 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.ArrayList
;
import
java.util.*
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
@Service
@Service
public
class
AgentApplicationServiceImpl
implements
AgentApplicationService
{
public
class
AgentApplicationServiceImpl
implements
AgentApplicationService
{
...
@@ -77,7 +78,6 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
...
@@ -77,7 +78,6 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
@Resource
@Resource
private
RedisService
redisService
;
private
RedisService
redisService
;
//todo 优化记录保存,对话保持链接/重新链接推送消息
@Override
@Override
public
void
callAgentApplication
(
String
agentId
,
String
dialogsId
,
String
input
,
HttpServletResponse
httpServletResponse
)
{
public
void
callAgentApplication
(
String
agentId
,
String
dialogsId
,
String
input
,
HttpServletResponse
httpServletResponse
)
{
...
@@ -106,7 +106,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
...
@@ -106,7 +106,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
List
<
Message
>
messages
=
buildMessages
(
dialogsId
,
agentId
,
userBaseEntity
.
getUserId
(),
input
);
List
<
Message
>
messages
=
buildMessages
(
dialogsId
,
agentId
,
userBaseEntity
.
getUserId
(),
input
);
//配置对话function
//配置对话function
List
<
Tool
>
tools
=
buildMemoryConfig
(
infoEntity
);
List
<
Tool
>
tools
=
buildMemoryConfig
(
infoEntity
,
dialogsId
);
// 保存用户输入记录
// 保存用户输入记录
Long
inputTimestamp
=
System
.
currentTimeMillis
();
Long
inputTimestamp
=
System
.
currentTimeMillis
();
...
@@ -307,14 +307,27 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
...
@@ -307,14 +307,27 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
bizAgentApplicationDialoguesRecordService
.
save
(
outputRecord
);
bizAgentApplicationDialoguesRecordService
.
save
(
outputRecord
);
}
}
private
List
<
Tool
>
buildMemoryConfig
(
BizAgentApplicationPublishEntity
infoEntity
)
{
private
List
<
Tool
>
buildMemoryConfig
(
BizAgentApplicationPublishEntity
infoEntity
,
String
identifier
)
{
List
<
Tool
>
tools
=
new
ArrayList
<>();
List
<
Tool
>
tools
=
new
ArrayList
<>();
//开启对话变量
//开启对话变量
if
(
CollectionUtils
.
isNotEmpty
(
infoEntity
.
getVariableStructure
()))
{
if
(
CollectionUtils
.
isNotEmpty
(
infoEntity
.
getVariableStructure
()))
{
// String functionName = LargeModelFunctionEnum.set_value_memory.name();
String
functionName
=
LargeModelFunctionEnum
.
set_value_memory
.
name
();
// String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getVariableStructureLLMConfig(infoEntity.getVariableStructure()).get(0);
String
llmConfig
=
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
getVariableStructureLLMConfig
(
infoEntity
.
getVariableStructure
()).
get
(
0
);
// Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class);
Tool
tool
=
JsonUtils
.
deSerialize
(
llmConfig
,
Tool
.
class
);
// tools.add(tool);
tools
.
add
(
tool
);
//初始化变量函数
Map
<
Object
,
Object
>
map
=
GetValueMemory
.
get
(
identifier
);
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
,
variableDefault
);
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
doFunction
(
jsonObject
.
toJSONString
(),
identifier
);
}
}
}
}
//开启长期记忆
//开启长期记忆
if
(
CommonConstant
.
YOrN
.
Y
.
equals
(
infoEntity
.
getIsLongMemory
()))
{
if
(
CommonConstant
.
YOrN
.
Y
.
equals
(
infoEntity
.
getIsLongMemory
()))
{
...
...
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