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
e91da2d1
Commit
e91da2d1
authored
Nov 14, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style
parent
0d05fe25
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
105 additions
and
50 deletions
+105
-50
AgentApplicationInfoRestImpl.java
...t_application/rest/impl/AgentApplicationInfoRestImpl.java
+4
-33
AgentApplicationUtils.java
...om/poc/agent_application/utils/AgentApplicationUtils.java
+61
-0
SQLUtils.java
src/main/java/cn/com/poc/common/utils/SQLUtils.java
+23
-14
AgentApplicationServiceImpl.java
...oc/expose/aggregate/impl/AgentApplicationServiceImpl.java
+2
-3
UserDialoguesDto.java
src/main/java/cn/com/poc/expose/dto/UserDialoguesDto.java
+14
-0
AgentApplicationRestImpl.java
...cn/com/poc/expose/rest/impl/AgentApplicationRestImpl.java
+1
-0
No files found.
src/main/java/cn/com/poc/agent_application/rest/impl/AgentApplicationInfoRestImpl.java
View file @
e91da2d1
...
...
@@ -7,6 +7,7 @@ import cn.com.poc.agent_application.entity.*;
import
cn.com.poc.agent_application.query.AgentApplicationInfoQueryCondition
;
import
cn.com.poc.agent_application.rest.AgentApplicationInfoRest
;
import
cn.com.poc.agent_application.service.*
;
import
cn.com.poc.agent_application.utils.AgentApplicationUtils
;
import
cn.com.poc.common.annotation.RedisLimit
;
import
cn.com.poc.common.constant.CommonConstant
;
import
cn.com.poc.common.service.RedisService
;
...
...
@@ -207,7 +208,7 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
Assert
.
notEmpty
(
dto
.
getMessages
());
try
{
String
agentId
=
dto
.
getAgentId
();
String
dialogueId
=
agentId
;
String
dialogueId
=
dto
.
getAgentId
()
;
BizAgentApplicationInfoEntity
infoEntity
=
bizAgentApplicationInfoService
.
getByAgentId
(
agentId
);
if
(
infoEntity
==
null
)
{
throw
new
I18nMessageException
(
"exception/application.does.not.exist"
);
...
...
@@ -216,36 +217,7 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
List
<
Integer
>
kdIds
=
knowledgeService
.
getKdIdsByKnowledgeInfoIds
(
infoEntity
.
getKnowledgeIds
());
//配置对话function
List
<
Tool
>
tools
=
new
ArrayList
<>();
//开启对话变量
if
(
CollectionUtils
.
isNotEmpty
(
infoEntity
.
getVariableStructure
()))
{
String
functionName
=
LargeModelFunctionEnum
.
memory_variable_writer
.
name
();
String
llmConfig
=
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
getVariableStructureLLMConfig
(
infoEntity
.
getVariableStructure
()).
get
(
0
);
Tool
tool
=
JsonUtils
.
deSerialize
(
llmConfig
,
Tool
.
class
);
tools
.
add
(
tool
);
//初始化变量函数
Map
<
Object
,
Object
>
map
=
GetMemoryVariable
.
get
(
agentId
+
":"
+
agentId
);
List
<
Variable
>
variableStructure
=
infoEntity
.
getVariableStructure
();
if
(
MapUtils
.
isEmpty
(
map
))
{
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
(),
agentId
+
":"
+
agentId
);
}
}
}
//开启长期记忆
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
);
}
List
<
Tool
>
tools
=
AgentApplicationUtils
.
buildMemoryConfig
(
infoEntity
.
getVariableStructure
(),
infoEntity
.
getIsLongMemory
(),
dialogueId
,
agentId
);
//对话大模型配置
String
model
=
StringUtils
.
isNotBlank
(
dto
.
getModelNickName
())
?
dto
.
getModelNickName
()
:
infoEntity
.
getLargeModel
();
...
...
@@ -257,8 +229,7 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
agentApplicationInfoService
.
callAgentApplication
(
agentId
,
dialogueId
,
model
,
infoEntity
.
getUnitIds
(),
agentSystem
,
kdIds
.
toArray
(
new
Integer
[
0
]),
infoEntity
.
getCommunicationTurn
(),
topP
,
temperature
,
dto
.
getMessages
(),
tools
,
httpServletResponse
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
httpServletResponse
.
setContentType
(
"text/event-stream"
);
PrintWriter
writer
=
httpServletResponse
.
getWriter
();
writer
.
write
(
"data: {\"code\":-1,\"message\":\""
+
e
.
getLocalizedMessage
()
+
"\"} \n\n"
);
...
...
src/main/java/cn/com/poc/agent_application/utils/AgentApplicationUtils.java
0 → 100644
View file @
e91da2d1
package
cn
.
com
.
poc
.
agent_application
.
utils
;
import
cn.com.poc.agent_application.entity.Variable
;
import
cn.com.poc.common.constant.CommonConstant
;
import
cn.com.poc.common.utils.JsonUtils
;
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.memory_variable_writer.GetMemoryVariable
;
import
com.alibaba.fastjson.JSONObject
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.MapUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
public
class
AgentApplicationUtils
{
/**
* 构造Agent应用 记忆函数配置
*
* @param variableStructures
* @param isLongMemory
* @param identifier
* @param agentId
* @return
*/
public
static
List
<
Tool
>
buildMemoryConfig
(
List
<
Variable
>
variableStructures
,
String
isLongMemory
,
String
identifier
,
String
agentId
)
{
List
<
Tool
>
tools
=
new
ArrayList
<>();
//开启对话变量
if
(
CollectionUtils
.
isNotEmpty
(
variableStructures
))
{
String
functionName
=
LargeModelFunctionEnum
.
memory_variable_writer
.
name
();
String
llmConfig
=
LargeModelFunctionEnum
.
valueOf
(
functionName
).
getFunction
().
getVariableStructureLLMConfig
(
variableStructures
).
get
(
0
);
Tool
tool
=
JsonUtils
.
deSerialize
(
llmConfig
,
Tool
.
class
);
tools
.
add
(
tool
);
//初始化变量函数
Map
<
Object
,
Object
>
map
=
GetMemoryVariable
.
get
(
identifier
+
":"
+
agentId
);
if
(
MapUtils
.
isEmpty
(
map
))
{
List
<
Variable
>
variableStructure
=
variableStructures
;
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
+
":"
+
agentId
);
}
}
}
//开启长期记忆
if
(
CommonConstant
.
YOrN
.
Y
.
equals
(
isLongMemory
))
{
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/common/utils/SQLUtils.java
View file @
e91da2d1
...
...
@@ -18,6 +18,14 @@ import java.util.stream.Collectors;
**/
public
class
SQLUtils
{
/**
* 获取批量插入sql和参数
*
* @param modelClass
* @param models
* @return
* @throws Exception
*/
public
static
BatchInsertResult
getInsertSql
(
Class
<?
extends
BaseModelClass
>
modelClass
,
List
<?
extends
BaseModelClass
>
models
)
throws
Exception
{
//获取表名
Table
table
=
modelClass
.
getAnnotation
(
Table
.
class
);
...
...
@@ -39,7 +47,7 @@ public class SQLUtils {
tableFieldList
.
add
(
column
.
name
());
modelGetMethodList
.
add
(
method
.
getName
());
}
BatchInsertResult
result
=
new
BatchInsertResult
();
//构造insert sql
String
fieldStr
=
tableFieldList
.
stream
().
collect
(
Collectors
.
joining
(
","
));
StringBuilder
insertSQL
=
new
StringBuilder
();
...
...
@@ -52,7 +60,10 @@ public class SQLUtils {
}
insertSQL
.
append
(
")"
);
result
.
setInsertSQL
(
insertSQL
.
toString
());
//构造实体
if
(
models
!=
null
)
{
List
<
Object
[]>
toInserteParams
=
new
ArrayList
<>(
models
.
size
());
for
(
BaseModelClass
model
:
models
)
{
Object
[]
array
=
new
Object
[
modelGetMethodList
.
size
()];
...
...
@@ -64,10 +75,8 @@ public class SQLUtils {
}
toInserteParams
.
add
(
array
);
}
BatchInsertResult
result
=
new
BatchInsertResult
();
result
.
setInsertSQL
(
insertSQL
.
toString
());
result
.
setInsertParams
(
toInserteParams
);
}
return
result
;
}
...
...
src/main/java/cn/com/poc/expose/aggregate/impl/AgentApplicationServiceImpl.java
View file @
e91da2d1
...
...
@@ -13,6 +13,7 @@ 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.agent_application.service.BizMemberAgentApplicationCollectService
;
import
cn.com.poc.agent_application.utils.AgentApplicationUtils
;
import
cn.com.poc.common.constant.CommonConstant
;
import
cn.com.poc.common.constant.XLangConstant
;
import
cn.com.poc.common.service.RedisService
;
...
...
@@ -29,7 +30,6 @@ import cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelDema
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.GetMemoryVariable
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.value_memory.GetValueMemory
;
import
cn.com.poc.thirdparty.service.LLMService
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.data.model.PagingInfo
;
...
...
@@ -109,12 +109,11 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
//获取知识库配置
List
<
Integer
>
kdIdList
=
knowledgeService
.
getKdIdsByKnowledgeInfoIds
(
infoEntity
.
getKnowledgeIds
());
// 构造对话参数
List
<
Message
>
messages
=
buildMessages
(
dialogsId
,
agentId
,
userBaseEntity
.
getUserId
(),
input
);
//配置对话function
List
<
Tool
>
tools
=
buildMemoryConfig
(
infoEntity
,
dialogs
Id
);
List
<
Tool
>
tools
=
AgentApplicationUtils
.
buildMemoryConfig
(
infoEntity
.
getVariableStructure
(),
infoEntity
.
getIsLongMemory
(),
dialogsId
,
agent
Id
);
// 保存用户输入记录
Long
inputTimestamp
=
System
.
currentTimeMillis
();
...
...
src/main/java/cn/com/poc/expose/dto/UserDialoguesDto.java
View file @
e91da2d1
...
...
@@ -9,6 +9,12 @@ public class UserDialoguesDto implements Serializable {
*/
private
java
.
lang
.
String
dialogsId
;
/**
* 应用ID
*/
private
java
.
lang
.
String
agentId
;
/**
* 内容
*/
...
...
@@ -30,4 +36,12 @@ public class UserDialoguesDto implements Serializable {
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
public
String
getAgentId
()
{
return
agentId
;
}
public
void
setAgentId
(
String
agentId
)
{
this
.
agentId
=
agentId
;
}
}
src/main/java/cn/com/poc/expose/rest/impl/AgentApplicationRestImpl.java
View file @
e91da2d1
...
...
@@ -185,6 +185,7 @@ public class AgentApplicationRestImpl implements AgentApplicationRest {
result
=
memberDialoguesQueryItems
.
stream
().
map
(
item
->
{
UserDialoguesDto
userDialoguesDto
=
new
UserDialoguesDto
();
userDialoguesDto
.
setDialogsId
(
item
.
getDialogsId
());
userDialoguesDto
.
setAgentId
(
item
.
getAgentId
());
String
content
=
item
.
getContent
().
length
()
>
20
?
item
.
getContent
().
substring
(
0
,
20
)
:
item
.
getContent
();
userDialoguesDto
.
setContent
(
content
);
return
userDialoguesDto
;
...
...
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