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
2c689394
Commit
2c689394
authored
Sep 18, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:Agent应用 头像生成
parent
d1c508bf
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
471 additions
and
16 deletions
+471
-16
AgentApplicationInfoService.java
...nt_application/aggregate/AgentApplicationInfoService.java
+1
-1
AgentApplicationInfoServiceImpl.java
...ation/aggregate/impl/AgentApplicationInfoServiceImpl.java
+39
-12
AgentApplicationInfoRest.java
.../poc/agent_application/rest/AgentApplicationInfoRest.java
+4
-1
AgentApplicationInfoRestImpl.java
...t_application/rest/impl/AgentApplicationInfoRestImpl.java
+5
-1
BosConfigService.java
...main/java/cn/com/poc/common/service/BosConfigService.java
+8
-1
BosConfigServiceImpl.java
.../cn/com/poc/common/service/impl/BosConfigServiceImpl.java
+36
-0
AICreateImageService.java
...ty/resource/demand/ai/aggregate/AICreateImageService.java
+41
-0
AICreateImageServiceImpl.java
...ce/demand/ai/aggregate/impl/AICreateImageServiceImpl.java
+321
-0
BaiduAISailsText2ImageRequest.java
.../ai/entity/generations/BaiduAISailsText2ImageRequest.java
+16
-0
No files found.
src/main/java/cn/com/poc/agent_application/aggregate/AgentApplicationInfoService.java
View file @
2c689394
...
@@ -57,7 +57,7 @@ public interface AgentApplicationInfoService {
...
@@ -57,7 +57,7 @@ public interface AgentApplicationInfoService {
* @param agentDesc 应用描述
* @param agentDesc 应用描述
* @return Agent 应用图标URL
* @return Agent 应用图标URL
*/
*/
String
createAgentIcon
(
String
agentTitle
,
String
agentDesc
);
String
createAgentIcon
(
String
agentTitle
,
String
agentDesc
)
throws
Exception
;
/**
/**
* Agent 应用标题,描述生成
* Agent 应用标题,描述生成
...
...
src/main/java/cn/com/poc/agent_application/aggregate/impl/AgentApplicationInfoServiceImpl.java
View file @
2c689394
...
@@ -13,15 +13,19 @@ import cn.com.poc.agent_application.service.BizAgentApplicationPublishService;
...
@@ -13,15 +13,19 @@ import cn.com.poc.agent_application.service.BizAgentApplicationPublishService;
import
cn.com.poc.common.utils.BlContext
;
import
cn.com.poc.common.utils.BlContext
;
import
cn.com.poc.common.utils.JsonUtils
;
import
cn.com.poc.common.utils.JsonUtils
;
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.aggregate.AICreateImageService
;
import
cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService
;
import
cn.com.poc.thirdparty.resource.demand.ai.aggregate.DemandKnowledgeService
;
import
cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message
;
import
cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message
;
import
cn.com.poc.thirdparty.resource.demand.ai.common.domain.MultiContent
;
import
cn.com.poc.thirdparty.resource.demand.ai.common.domain.MultiContent
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.generations.BaiduAISailsText2ImageRequest
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.generations.BaiduAISailsText2ImageResult
;
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.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.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.BeanUtil
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang.ArrayUtils
;
import
org.apache.commons.lang.ArrayUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -61,6 +65,9 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
...
@@ -61,6 +65,9 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
@Resource
@Resource
private
DemandKnowledgeService
demandKnowledgeService
;
private
DemandKnowledgeService
demandKnowledgeService
;
@Resource
private
AICreateImageService
aiCreateImageService
;
@Resource
@Resource
private
LLMService
llmService
;
private
LLMService
llmService
;
...
@@ -85,11 +92,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
...
@@ -85,11 +92,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
}
}
@Override
@Override
public
String
callAgentApplication
(
String
largeModel
,
String
[]
unitIds
,
String
agentSystem
,
public
String
callAgentApplication
(
String
largeModel
,
String
[]
unitIds
,
String
agentSystem
,
String
[]
knowledgeIds
,
Integer
communicationTurn
,
Float
topP
,
List
<
Message
>
messages
,
HttpServletResponse
httpServletResponse
)
throws
Exception
{
String
[]
knowledgeIds
,
Integer
communicationTurn
,
Float
topP
,
logger
.
info
(
"--------- Call Agent Application large model:{},unitIds:{},agentSystem:{},knowledgeIds:{}"
+
" communicationTurn:{},topP:{},messages:{}--------------"
,
largeModel
,
unitIds
,
agentSystem
,
knowledgeIds
,
communicationTurn
,
topP
,
messages
);
List
<
Message
>
messages
,
HttpServletResponse
httpServletResponse
)
throws
Exception
{
logger
.
info
(
"--------- Call Agent Application large model:{},unitIds:{},agentSystem:{},knowledgeIds:{}"
+
" communicationTurn:{},topP:{},messages:{}--------------"
,
largeModel
,
unitIds
,
agentSystem
,
knowledgeIds
,
communicationTurn
,
topP
,
messages
);
//todo 调用组件
//todo 调用组件
String
promptTemplate
=
buildDialogsPrompt
(
messages
,
agentSystem
,
knowledgeIds
);
String
promptTemplate
=
buildDialogsPrompt
(
messages
,
agentSystem
,
knowledgeIds
);
...
@@ -214,11 +218,11 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
...
@@ -214,11 +218,11 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
}
}
@Override
@Override
public
String
createAgentIcon
(
String
agentTitle
,
String
agentDesc
)
{
public
String
createAgentIcon
(
String
agentTitle
,
String
agentDesc
)
throws
Exception
{
Assert
.
isTrue
(
StringUtils
.
isNotBlank
(
agentTitle
)
||
StringUtils
.
isNotBlank
(
agentDesc
),
"请输入标题或者描述再生成应用头像"
);
BizAgentApplicationGcConfigEntity
configEntity
=
bizAgentApplicationGcConfigService
.
getByConfigCode
(
AgentApplicationGCConfigConstants
.
AGENT_ICON
);
BizAgentApplicationGcConfigEntity
configEntity
=
bizAgentApplicationGcConfigService
.
getByConfigCode
(
AgentApplicationGCConfigConstants
.
AGENT_ICON
);
if
(
null
==
configEntity
||
StringUtils
.
isBlank
(
configEntity
.
getConfigSystem
()))
{
if
(
null
==
configEntity
||
StringUtils
.
isBlank
(
configEntity
.
getConfigSystem
()))
{
throw
new
BusinessException
(
"创建[头像
]配置不存在
"
);
throw
new
BusinessException
(
"创建[头像
提示语]配置不存在,请联系管理员
"
);
}
}
List
<
MultiContent
>
multiContents
=
new
ArrayList
<>();
List
<
MultiContent
>
multiContents
=
new
ArrayList
<>();
...
@@ -247,12 +251,35 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
...
@@ -247,12 +251,35 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
largeModelResponse
.
setUser
(
"POC-CREATE-AGENT-PROMPT"
);
largeModelResponse
.
setUser
(
"POC-CREATE-AGENT-PROMPT"
);
LargeModelDemandResult
largeModelDemandResult
=
llmService
.
chat
(
largeModelResponse
);
LargeModelDemandResult
largeModelDemandResult
=
llmService
.
chat
(
largeModelResponse
);
if
(
largeModelDemandResult
==
null
||
!
"0"
.
equals
(
largeModelDemandResult
.
getCode
()))
{
if
(
largeModelDemandResult
==
null
||
!
"0"
.
equals
(
largeModelDemandResult
.
getCode
())
||
StringUtils
.
isEmpty
(
largeModelDemandResult
.
getMessage
())
)
{
logger
.
error
(
"create
preamble
error, largeModelResponse:{}"
,
largeModelResponse
);
logger
.
error
(
"create
agent icon prompt
error, largeModelResponse:{}"
,
largeModelResponse
);
throw
new
BusinessException
(
"创建[
开场白]失败
"
);
throw
new
BusinessException
(
"创建[
头像]失败,请稍后再试
"
);
}
}
return
null
;
logger
.
info
(
"create agent application icon prompt, result:{}"
,
largeModelDemandResult
);
String
createIconPrompt
=
largeModelDemandResult
.
getMessage
();
BaiduAISailsText2ImageRequest
baiduAISailsText2ImageRequest
=
new
BaiduAISailsText2ImageRequest
();
baiduAISailsText2ImageRequest
.
setPrompt
(
createIconPrompt
);
baiduAISailsText2ImageRequest
.
setNegativePrompt
(
null
);
baiduAISailsText2ImageRequest
.
setSize
(
"768x768"
);
baiduAISailsText2ImageRequest
.
setN
(
1
);
baiduAISailsText2ImageRequest
.
setSteps
(
15
);
baiduAISailsText2ImageRequest
.
setSamplerIndex
(
"Euler a"
);
baiduAISailsText2ImageRequest
.
setSeed
(
null
);
baiduAISailsText2ImageRequest
.
setCfgCcale
(
null
);
baiduAISailsText2ImageRequest
.
setStyle
(
"Base"
);
baiduAISailsText2ImageRequest
.
setUserId
(
"AGENT-APPLICATION-ICON-CREATE"
);
baiduAISailsText2ImageRequest
.
setAcctId
(
null
);
BaiduAISailsText2ImageResult
baiduAISailsText2ImageResult
=
aiCreateImageService
.
executeSailsText2Image
(
baiduAISailsText2ImageRequest
);
if
(
baiduAISailsText2ImageResult
==
null
||
CollectionUtils
.
isEmpty
(
baiduAISailsText2ImageResult
.
getData
())
||
StringUtils
.
isEmpty
(
baiduAISailsText2ImageResult
.
getData
().
get
(
0
).
getUrl
()))
{
logger
.
error
(
"create agent icon error, baiduAISailsText2ImageRequest:{} "
,
baiduAISailsText2ImageRequest
);
throw
new
BusinessException
(
"创建[头像]失败,请稍后再试"
);
}
return
baiduAISailsText2ImageResult
.
getData
().
get
(
0
).
getUrl
();
}
}
private
String
buildDialogsPrompt
(
List
<
Message
>
messages
,
String
agentSystem
,
String
[]
knowledgeIds
)
{
private
String
buildDialogsPrompt
(
List
<
Message
>
messages
,
String
agentSystem
,
String
[]
knowledgeIds
)
{
...
...
src/main/java/cn/com/poc/agent_application/rest/AgentApplicationInfoRest.java
View file @
2c689394
...
@@ -72,5 +72,8 @@ public interface AgentApplicationInfoRest extends BaseRest {
...
@@ -72,5 +72,8 @@ public interface AgentApplicationInfoRest extends BaseRest {
*/
*/
String
createPreamble
(
@RequestBody
AgentApplicationGCDto
dto
)
throws
Exception
;
String
createPreamble
(
@RequestBody
AgentApplicationGCDto
dto
)
throws
Exception
;
/**
* AI创建应用头像
*/
String
createAgentApplicationAvatar
(
@RequestBody
AgentApplicationGCDto
dto
)
throws
Exception
;
}
}
\ No newline at end of file
src/main/java/cn/com/poc/agent_application/rest/impl/AgentApplicationInfoRestImpl.java
View file @
2c689394
...
@@ -160,5 +160,9 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
...
@@ -160,5 +160,9 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
return
agentApplicationInfoService
.
createPreamble
(
dto
.
getAgentTitle
(),
dto
.
getAgentDesc
());
return
agentApplicationInfoService
.
createPreamble
(
dto
.
getAgentTitle
(),
dto
.
getAgentDesc
());
}
}
@Override
public
String
createAgentApplicationAvatar
(
AgentApplicationGCDto
dto
)
throws
Exception
{
Assert
.
isTrue
(
StringUtils
.
isNotBlank
(
dto
.
getAgentDesc
())
||
StringUtils
.
isNotBlank
(
dto
.
getAgentTitle
()),
"请输入标题或者描述再生成应用头像"
);
return
agentApplicationInfoService
.
createAgentIcon
(
dto
.
getAgentTitle
(),
dto
.
getAgentDesc
());
}
}
}
\ No newline at end of file
src/main/java/cn/com/poc/common/service/BosConfigService.java
View file @
2c689394
...
@@ -11,5 +11,12 @@ public interface BosConfigService extends BaseService {
...
@@ -11,5 +11,12 @@ public interface BosConfigService extends BaseService {
String
uploadFileByByteArray2Oss
(
byte
[]
decodedByte
,
String
fileName
,
String
fileType
)
throws
IOException
;
String
uploadFileByByteArray2Oss
(
byte
[]
decodedByte
,
String
fileName
,
String
fileType
)
throws
IOException
;
String
upload
(
InputStream
inputStream
,
String
fileType
,
String
contentType
)
throws
IOException
;
String
upload
(
InputStream
inputStream
,
String
fileType
,
String
contentType
)
throws
IOException
;
String
uploadImageByBase64
(
String
base64
)
throws
IOException
;
String
uploadImageByUrl2Bos
(
String
url
)
throws
IOException
;
}
}
src/main/java/cn/com/poc/common/service/impl/BosConfigServiceImpl.java
View file @
2c689394
package
cn
.
com
.
poc
.
common
.
service
.
impl
;
package
cn
.
com
.
poc
.
common
.
service
.
impl
;
import
cn.com.poc.common.service.BosConfigService
;
import
cn.com.poc.common.service.BosConfigService
;
import
cn.com.poc.common.utils.Assert
;
import
cn.com.poc.common.utils.UUIDTool
;
import
cn.com.yict.framemax.core.config.Config
;
import
cn.com.yict.framemax.core.config.Config
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
cn.com.yict.framemax.frame.service.FmxParamConfigService
;
import
cn.com.yict.framemax.frame.service.FmxParamConfigService
;
...
@@ -15,8 +17,13 @@ import org.apache.http.client.utils.DateUtils;
...
@@ -15,8 +17,13 @@ import org.apache.http.client.utils.DateUtils;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.io.BufferedInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.Base64
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.Optional
;
import
java.util.Optional
;
...
@@ -122,6 +129,35 @@ public class BosConfigServiceImpl implements BosConfigService {
...
@@ -122,6 +129,35 @@ public class BosConfigServiceImpl implements BosConfigService {
}
}
}
}
@Override
public
String
uploadImageByBase64
(
String
base64
)
throws
IOException
{
Assert
.
notBlank
(
base64
);
byte
[]
decode
=
Base64
.
getDecoder
().
decode
(
base64
);
String
fileType
=
"jpeg"
;
return
this
.
uploadFileByByteArray2Oss
(
decode
,
UUIDTool
.
getUUID
(),
fileType
);
}
@Override
public
String
uploadImageByUrl2Bos
(
String
path
)
throws
IOException
{
StringBuffer
resultUrl
=
new
StringBuffer
();
String
fileType
=
"jpeg"
;
URL
url
=
new
URL
(
path
);
HttpURLConnection
httpUrl
=
(
HttpURLConnection
)
url
.
openConnection
();
httpUrl
.
setRequestMethod
(
"GET"
);
httpUrl
.
usingProxy
();
httpUrl
.
connect
();
InputStream
inputStream
=
new
BufferedInputStream
(
httpUrl
.
getInputStream
());
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
4096
];
int
n
=
0
;
while
(-
1
!=
(
n
=
inputStream
.
read
(
buffer
)))
{
output
.
write
(
buffer
,
0
,
n
);
}
byte
[]
content
=
output
.
toByteArray
();
return
this
.
uploadFileByByteArray2Oss
(
content
,
UUIDTool
.
getUUID
(),
fileType
);
}
//返回即将创建的文件名
//返回即将创建的文件名
private
String
createFileName
(
String
fileType
)
{
private
String
createFileName
(
String
fileType
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
StringBuilder
stringBuilder
=
new
StringBuilder
();
...
...
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/aggregate/AICreateImageService.java
0 → 100644
View file @
2c689394
package
cn
.
com
.
poc
.
thirdparty
.
resource
.
demand
.
ai
.
aggregate
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.generations.*
;
import
javax.servlet.http.HttpServletResponse
;
/**
* @author alex.yao
* @date 2023/5/30
*
* 图片创建
**/
public
interface
AICreateImageService
{
/**
* 调用OpenAi创建图片接口
*/
GenerationsResult
invokeCreateImage
(
GenerationsRequest
request
)
throws
Exception
;
/**
* 调用Baidu创建图片接口(普通版)
*/
GenerationsResult
invokeCreateImage
(
BaiduGenerationsRequest
request
)
throws
Exception
;
/**
* 调用Baidu创建图片接口(高级版)
*/
GenerationsResult
invokeCreateImageV2
(
BaiduGenerationsV2Request
request
)
throws
Exception
;
/**
* 调用Baidu千帆大模型文生图
* Stable-Diffusion-XL是业内知名的跨模态大模型,由StabilityAI研发并开源,有着业内领先的图像生成能力。
*/
BaiduAISailsText2ImageResult
executeSailsText2Image
(
BaiduAISailsText2ImageRequest
request
)
throws
Exception
;
/**
* 千帆大模型图生文
* Fuyu-8B是由Adept AI训练的多模态图像理解模型,可以支持多样的图像分辨率,回答图形图表有关问题。模型在视觉问答和图像描述等任务上表现良好。
*/
BaiduAISailsImage2TextResult
executeSailsImage2Text
(
BaiduAISailsImage2TextRequest
request
,
HttpServletResponse
httpServletResponse
)
throws
Exception
;
}
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/aggregate/impl/AICreateImageServiceImpl.java
0 → 100644
View file @
2c689394
This diff is collapsed.
Click to expand it.
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/entity/generations/BaiduAISailsText2ImageRequest.java
View file @
2c689394
...
@@ -206,4 +206,20 @@ public class BaiduAISailsText2ImageRequest extends AbstractRequest<BaiduAISailsT
...
@@ -206,4 +206,20 @@ public class BaiduAISailsText2ImageRequest extends AbstractRequest<BaiduAISailsT
public
String
getMethod
()
throws
Exception
{
public
String
getMethod
()
throws
Exception
{
return
null
;
return
null
;
}
}
@Override
public
String
toString
()
{
return
"BaiduAISailsText2ImageRequest{"
+
"prompt='"
+
prompt
+
'\''
+
", negativePrompt='"
+
negativePrompt
+
'\''
+
", size='"
+
size
+
'\''
+
", n="
+
n
+
", steps="
+
steps
+
", samplerIndex='"
+
samplerIndex
+
'\''
+
", seed="
+
seed
+
", cfgCcale="
+
cfgCcale
+
", style='"
+
style
+
'\''
+
", userId='"
+
userId
+
'\''
+
'}'
;
}
}
}
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