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
87555dfb
Commit
87555dfb
authored
Nov 26, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 应用发布-新增音色配置
parent
6a12e005
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
470 additions
and
275 deletions
+470
-275
BizAgentApplicationPublishConvert.java
...pplication/convert/BizAgentApplicationPublishConvert.java
+30
-4
BizAgentApplicationPublishEntity.java
..._application/entity/BizAgentApplicationPublishEntity.java
+12
-0
BizAgentApplicationInfoModel.java
...agent_application/model/BizAgentApplicationInfoModel.java
+1
-1
BizAgentApplicationPublishModel.java
...nt_application/model/BizAgentApplicationPublishModel.java
+295
-249
AgentApplicationInfoTest.java
src/test/java/cn/com/poc/AgentApplicationInfoTest.java
+132
-21
No files found.
src/main/java/cn/com/poc/agent_application/convert/BizAgentApplicationPublishConvert.java
View file @
87555dfb
package
cn
.
com
.
poc
.
agent_application
.
convert
;
import
cn.com.poc.agent_application.domain.AgentApplicationBaseInfo
;
import
cn.com.poc.agent_application.domain.AgentApplicationCommConfig
;
import
cn.com.poc.agent_application.domain.AgentApplicationCommModelConfig
;
import
cn.com.poc.agent_application.domain.AgentApplicationKnowledgeConfig
;
import
cn.com.poc.agent_application.domain.*
;
import
cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto
;
import
cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity
;
import
cn.com.poc.agent_application.entity.Variable
;
import
cn.com.poc.agent_application.entity.VoiceConfig
;
import
cn.com.poc.agent_application.model.BizAgentApplicationPublishModel
;
import
cn.com.poc.common.constant.CommonConstant
;
import
cn.com.poc.common.utils.JsonUtils
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.fasterxml.jackson.core.type.TypeReference
;
...
...
@@ -58,6 +57,10 @@ public class BizAgentApplicationPublishConvert {
if
(
StringUtils
.
isNotBlank
(
model
.
getUnitIds
()))
{
entity
.
setUnitIds
(
JsonUtils
.
deSerialize
(
model
.
getUnitIds
(),
String
[].
class
));
}
if
(
StringUtils
.
isNotBlank
(
model
.
getVoiceConfig
()))
{
VoiceConfig
voiceConfig
=
JsonUtils
.
deSerialize
(
model
.
getVoiceConfig
(),
VoiceConfig
.
class
);
entity
.
setVoiceConfig
(
voiceConfig
);
}
entity
.
setIsDeleted
(
model
.
getIsDeleted
());
entity
.
setCreator
(
model
.
getCreator
());
entity
.
setCreatedTime
(
model
.
getCreatedTime
());
...
...
@@ -97,6 +100,10 @@ public class BizAgentApplicationPublishConvert {
if
(
ArrayUtils
.
isNotEmpty
(
entity
.
getUnitIds
()))
{
model
.
setUnitIds
(
JsonUtil
.
toJson
(
entity
.
getUnitIds
()));
}
if
(
ObjectUtil
.
isNotEmpty
(
entity
.
getVoiceConfig
()))
{
model
.
setVoiceConfig
(
JsonUtils
.
serialize
(
entity
.
getVoiceConfig
()));
}
model
.
setIsDeleted
(
entity
.
getIsDeleted
());
model
.
setCreator
(
entity
.
getCreator
());
model
.
setCreatedTime
(
entity
.
getCreatedTime
());
...
...
@@ -136,10 +143,21 @@ public class BizAgentApplicationPublishConvert {
commModelConfig
.
setTemperature
(
entity
.
getTemperature
());
commModelConfig
.
setCommunicationTurn
(
entity
.
getCommunicationTurn
());
AgentApplicationVoiceConfig
voiceConfig
=
new
AgentApplicationVoiceConfig
();
if
(
ObjectUtil
.
isNotEmpty
(
entity
.
getVoiceConfig
()))
{
voiceConfig
.
setDefaultOpen
(
entity
.
getVoiceConfig
().
getDefaultOpen
());
voiceConfig
.
setTimbreId
(
entity
.
getVoiceConfig
().
getTimbreId
());
}
else
{
voiceConfig
.
setDefaultOpen
(
CommonConstant
.
YOrN
.
N
);
voiceConfig
.
setTimbreId
(
StringUtils
.
EMPTY
);
}
dto
.
setBaseInfo
(
baseInfo
);
dto
.
setCommConfig
(
commConfig
);
dto
.
setKnowledgeConfig
(
knowledgeConfig
);
dto
.
setCommModelConfig
(
commModelConfig
);
dto
.
setVoiceConfig
(
voiceConfig
);
dto
.
setUnitIds
(
entity
.
getUnitIds
());
dto
.
setCreator
(
entity
.
getCreator
());
dto
.
setCreatedTime
(
entity
.
getCreatedTime
());
...
...
@@ -185,6 +203,14 @@ public class BizAgentApplicationPublishConvert {
entity
.
setTemperature
(
dto
.
getCommModelConfig
().
getTemperature
());
}
VoiceConfig
voiceConfig
=
new
VoiceConfig
();
if
(
ObjectUtil
.
isNotEmpty
(
dto
.
getVoiceConfig
()))
{
voiceConfig
.
setDefaultOpen
(
dto
.
getVoiceConfig
().
getDefaultOpen
());
voiceConfig
.
setTimbreId
(
dto
.
getVoiceConfig
().
getTimbreId
());
}
else
{
voiceConfig
.
setDefaultOpen
(
CommonConstant
.
YOrN
.
N
);
voiceConfig
.
setTimbreId
(
StringUtils
.
EMPTY
);
}
entity
.
setUnitIds
(
dto
.
getUnitIds
());
entity
.
setCreator
(
dto
.
getCreator
());
entity
.
setCreatedTime
(
dto
.
getCreatedTime
());
...
...
src/main/java/cn/com/poc/agent_application/entity/BizAgentApplicationPublishEntity.java
View file @
87555dfb
...
...
@@ -330,6 +330,18 @@ public class BizAgentApplicationPublishEntity {
this
.
isDocumentParsing
=
isDocumentParsing
;
}
/**
* voice_config
*/
private
VoiceConfig
voiceConfig
;
public
VoiceConfig
getVoiceConfig
()
{
return
voiceConfig
;
}
public
void
setVoiceConfig
(
VoiceConfig
voiceConfig
)
{
this
.
voiceConfig
=
voiceConfig
;
}
/**
* is_deleted
...
...
src/main/java/cn/com/poc/agent_application/model/BizAgentApplicationInfoModel.java
View file @
87555dfb
...
...
@@ -421,7 +421,7 @@ public class BizAgentApplicationInfoModel extends BaseModelClass implements Seri
/**
* voice_config
* 声音配置 default
_open-是否默认开启 timbre_i
d-音色
* 声音配置 default
Open-是否默认开启 timbreI
d-音色
*/
private
java
.
lang
.
String
voiceConfig
;
...
...
src/main/java/cn/com/poc/agent_application/model/BizAgentApplicationPublishModel.java
View file @
87555dfb
This diff is collapsed.
Click to expand it.
src/test/java/cn/com/poc/AgentApplicationInfoTest.java
View file @
87555dfb
...
...
@@ -2,29 +2,31 @@ package cn.com.poc;
import
cn.com.poc.agent_application.aggregate.AgentApplicationInfoService
;
import
cn.com.poc.agent_application.entity.Variable
;
import
cn.com.poc.agent_application.utils.AgentApplicationTools
;
import
cn.com.poc.common.service.RedisService
;
import
cn.com.poc.common.utils.BlContext
;
import
cn.com.poc.expose.aggregate.AgentApplicationService
;
import
cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService
;
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.poc.thirdparty.resource.demand.ai.function.value_memory.SetValueMemoryConstants
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.html_reader.HtmlReaderFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.memory_variable_writer.MemoryVariableWriter
;
import
cn.com.yict.framemax.core.spring.SingleContextInitializer
;
import
cn.com.yict.framemax.security.oauth.support.UsernameOauthTokenAuthenticationToken
;
import
com.google.common.collect.Lists
;
import
org.apache.commons.collections4.ListUtils
;
import
io.github.furstenheim.*
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.security.core.context.SecurityContext
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.context.SecurityContextImpl
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
javax.annotation.Resource
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
initializers
=
SingleContextInitializer
.
class
)
...
...
@@ -43,8 +45,48 @@ public class AgentApplicationInfoTest {
@Test
public
void
del
()
{
String
contentKey
=
SetValueMemoryConstants
.
REDIS_PREFIX
;
redisService
.
del
(
contentKey
);
}
@Test
public
void
html2MD
()
throws
IOException
{
// 创建资源符对象
URL
url
=
new
URL
(
"https://blog.csdn.net/jxlhljh/article/details/124506103"
);
// 创建连接
URLConnection
conn
=
url
.
openConnection
();
// 获取输入流
InputStream
inputStream
=
conn
.
getInputStream
();
// 缓冲区,读取输入流内容,64KB
char
[]
buffer
=
new
char
[
1024
*
64
];
int
len
;
StringBuilder
sb
=
new
StringBuilder
();
// 转换为字符流
InputStreamReader
isr
=
new
InputStreamReader
(
inputStream
);
// 循环读取
while
((
len
=
isr
.
read
(
buffer
))
!=
-
1
)
{
sb
.
append
(
buffer
,
0
,
len
);
}
// System.out.println(sb.toString());
// 关闭资源
inputStream
.
close
();
isr
.
close
();
String
htmlStr
=
sb
.
toString
();
OptionsBuilder
optionsBuilder
=
OptionsBuilder
.
anOptions
();
Options
options
=
optionsBuilder
.
withBr
(
"-"
)
.
withLinkStyle
(
LinkStyle
.
REFERENCED
)
.
withLinkReferenceStyle
(
LinkReferenceStyle
.
SHORTCUT
)
// more options
.
build
();
CopyDown
converter
=
new
CopyDown
(
options
);
String
markdownText
=
converter
.
convert
(
htmlStr
);
FileOutputStream
fileOutputStream
=
new
FileOutputStream
(
"D:\\test.md"
);
fileOutputStream
.
write
(
markdownText
.
getBytes
());
fileOutputStream
.
flush
();
fileOutputStream
.
close
();
// System.out.println(markdownText);
}
...
...
@@ -80,14 +122,83 @@ public class AgentApplicationInfoTest {
@Test
public
void
getValueMemory
()
{
String
agentId
=
"d56d9a6a90ed435d831f84bc1af50547"
;
String
contentKey
=
SetValueMemoryConstants
.
REDIS_PREFIX
+
agentId
+
":"
+
"204"
;
System
.
out
.
println
(
redisService
.
hmget
(
contentKey
));
// Set<Object> keySet = result.keySet();
// for (Object key : keySet) {
// Object value = result.get(key);
// System.out.println("key:" + key + ",value:" + value);
// }
}
@Test
public
void
getFunctionConfig
()
{
System
.
out
.
println
(
new
HtmlReaderFunction
().
getLLMConfig
());
}
@Test
public
void
updateStructVariable
()
{
String
agentId
=
"1"
;
List
<
Variable
>
originals
=
null
;
List
<
Variable
>
transformed
=
null
;
String
identifier
=
AgentApplicationTools
.
identifier
(
agentId
,
agentId
);
if
(
CollectionUtils
.
isEmpty
(
transformed
))
{
// 清除所有字段
MemoryVariableWriter
.
clean
(
identifier
);
}
// 原【变量记忆】为空,则不需要处理
if
(
originals
==
null
)
{
return
;
}
// 1. 获取需要删除的字段集合
// 2. 获取需要更新值的字段集合
Set
<
String
>
delKeys
=
new
HashSet
<>();
Set
<
String
>
updateKeys
=
new
HashSet
<>();
for
(
Variable
variable
:
originals
)
{
String
key
=
variable
.
getKey
();
boolean
needDel
=
transformed
.
stream
().
noneMatch
(
v
->
v
.
getKey
().
equals
(
key
));
if
(
needDel
)
{
delKeys
.
add
(
key
);
}
boolean
needUpdate
=
transformed
.
stream
().
anyMatch
(
v
->
v
.
getKey
().
equals
(
key
));
if
(
needUpdate
)
{
Optional
<
Variable
>
target
=
transformed
.
stream
().
filter
(
v
->
v
.
getKey
().
equals
(
key
)).
findFirst
();
if
(
StringUtils
.
isBlank
(
target
.
get
().
getVariableDefault
()))
{
continue
;
}
Map
<
Object
,
Object
>
map
=
MemoryVariableWriter
.
get
(
identifier
);
String
value
=
map
.
get
(
key
).
toString
();
if
(
StringUtils
.
isBlank
(
value
))
{
updateKeys
.
add
(
key
);
}
}
}
// 3. 获取需要新增的字段集合
Set
<
String
>
addKeys
=
new
HashSet
<>();
for
(
Variable
variable
:
transformed
)
{
String
key
=
variable
.
getKey
();
boolean
needAdd
=
originals
.
stream
().
noneMatch
(
v
->
v
.
getKey
().
equals
(
key
));
if
(
needAdd
)
{
addKeys
.
add
(
key
);
}
}
// 删除
if
(!
delKeys
.
isEmpty
())
{
MemoryVariableWriter
.
delItem
(
identifier
,
delKeys
.
toArray
(
new
String
[
0
]));
}
if
(!
addKeys
.
isEmpty
())
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
String
key
:
addKeys
)
{
Variable
variable
=
transformed
.
stream
().
filter
(
v
->
v
.
getKey
().
equals
(
key
)).
findFirst
().
get
();
map
.
put
(
variable
.
getKey
(),
variable
.
getVariableDefault
());
}
MemoryVariableWriter
.
addItem
(
identifier
,
map
);
}
if
(!
updateKeys
.
isEmpty
())
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
String
key
:
updateKeys
)
{
Variable
variable
=
transformed
.
stream
().
filter
(
v
->
v
.
getKey
().
equals
(
key
)).
findFirst
().
get
();
map
.
put
(
variable
.
getKey
(),
variable
.
getVariableDefault
());
}
MemoryVariableWriter
.
addItem
(
identifier
,
map
);
}
}
}
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