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
ce4d270e
Commit
ce4d270e
authored
Sep 19, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:AgentApplication 标题和描述AI生成
parent
802bde32
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
130 additions
and
0 deletions
+130
-0
AgentApplicationInfoService.java
...nt_application/aggregate/AgentApplicationInfoService.java
+4
-0
AgentApplicationInfoServiceImpl.java
...ation/aggregate/impl/AgentApplicationInfoServiceImpl.java
+42
-0
AgentApplicationGCConfigConstants.java
...plication/constant/AgentApplicationGCConfigConstants.java
+2
-0
CreateAgentTitleAndDescEntity.java
...ent_application/entity/CreateAgentTitleAndDescEntity.java
+32
-0
AgentApplicationInfoRest.java
.../poc/agent_application/rest/AgentApplicationInfoRest.java
+5
-0
AgentApplicationInfoRestImpl.java
...t_application/rest/impl/AgentApplicationInfoRestImpl.java
+14
-0
AgentApplicationInfoTest.java
src/test/java/cn/com/poc/AgentApplicationInfoTest.java
+31
-0
No files found.
src/main/java/cn/com/poc/agent_application/aggregate/AgentApplicationInfoService.java
View file @
ce4d270e
package
cn
.
com
.
poc
.
agent_application
.
aggregate
;
import
cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity
;
import
cn.com.poc.agent_application.entity.CreateAgentTitleAndDescEntity
;
import
cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message
;
import
javax.servlet.http.HttpServletResponse
;
...
...
@@ -61,5 +62,8 @@ public interface AgentApplicationInfoService {
/**
* Agent 应用标题,描述生成
*
* @param input 用户输入内容
*/
CreateAgentTitleAndDescEntity
createAgentTitleAndDesc
(
String
input
);
}
src/main/java/cn/com/poc/agent_application/aggregate/impl/AgentApplicationInfoServiceImpl.java
View file @
ce4d270e
...
...
@@ -7,6 +7,7 @@ import cn.com.poc.agent_application.constant.AgentApplicationGCConfigConstants;
import
cn.com.poc.agent_application.entity.BizAgentApplicationGcConfigEntity
;
import
cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity
;
import
cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity
;
import
cn.com.poc.agent_application.entity.CreateAgentTitleAndDescEntity
;
import
cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService
;
import
cn.com.poc.agent_application.service.BizAgentApplicationInfoService
;
import
cn.com.poc.agent_application.service.BizAgentApplicationPublishService
;
...
...
@@ -282,6 +283,47 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
return
baiduAISailsText2ImageResult
.
getData
().
get
(
0
).
getUrl
();
}
@Override
public
CreateAgentTitleAndDescEntity
createAgentTitleAndDesc
(
String
input
)
{
BizAgentApplicationGcConfigEntity
configEntity
=
bizAgentApplicationGcConfigService
.
getByConfigCode
(
AgentApplicationGCConfigConstants
.
AGENT_INFO
);
if
(
null
==
configEntity
||
StringUtils
.
isBlank
(
configEntity
.
getConfigSystem
()))
{
throw
new
BusinessException
(
"创建[应用信息]配置不存在,请联系管理员"
);
}
List
<
MultiContent
>
multiContents
=
new
ArrayList
<>();
multiContents
.
add
(
new
MultiContent
()
{{
String
configSystem
=
configEntity
.
getConfigSystem
();
if
(
StringUtils
.
isNotBlank
(
input
))
{
configSystem
=
configSystem
.
replace
(
"${input}"
,
input
);
}
setText
(
configSystem
);
setType
(
"text"
);
}});
Message
message
=
new
Message
();
message
.
setContent
(
multiContents
);
message
.
setRole
(
AgentApplicationDialoguesRecordConstants
.
ROLE
.
USER
);
List
<
Message
>
messages
=
new
ArrayList
<
Message
>()
{{
add
(
message
);
}};
LargeModelResponse
largeModelResponse
=
new
LargeModelResponse
();
largeModelResponse
.
setModel
(
configEntity
.
getLargeModel
());
largeModelResponse
.
setMessages
(
messages
.
toArray
(
new
Message
[
1
]));
largeModelResponse
.
setTopP
(
configEntity
.
getTopP
());
largeModelResponse
.
setUser
(
"POC-CREATE-AGENT-INFO"
);
LargeModelDemandResult
largeModelDemandResult
=
llmService
.
chat
(
largeModelResponse
);
if
(
largeModelDemandResult
==
null
||
!
"0"
.
equals
(
largeModelDemandResult
.
getCode
())
||
StringUtils
.
isEmpty
(
largeModelDemandResult
.
getMessage
()))
{
logger
.
error
(
"create agent icon title And desc error, largeModelResponse:{}"
,
largeModelResponse
);
throw
new
BusinessException
(
"创建[应用信息]失败,请稍后再试"
);
}
logger
.
info
(
"create agent application icon title And desc, response:{},result:{}"
,
largeModelResponse
,
largeModelDemandResult
);
String
res
=
largeModelDemandResult
.
getMessage
();
int
start
=
res
.
lastIndexOf
(
"{"
);
int
end
=
res
.
lastIndexOf
(
"}"
);
return
JsonUtils
.
deSerialize
(
res
.
substring
(
start
,
end
+
1
),
CreateAgentTitleAndDescEntity
.
class
);
}
private
String
buildDialogsPrompt
(
List
<
Message
>
messages
,
String
agentSystem
,
String
[]
knowledgeIds
)
{
// todo 获取提示词模板
String
promptTemplate
=
"${agentSystem}"
;
...
...
src/main/java/cn/com/poc/agent_application/constant/AgentApplicationGCConfigConstants.java
View file @
ce4d270e
...
...
@@ -13,5 +13,7 @@ public interface AgentApplicationGCConfigConstants {
String
AGENT_ICON
=
"AgentIcon"
;
String
AGENT_INFO
=
"AgentInfo"
;
}
src/main/java/cn/com/poc/agent_application/entity/CreateAgentTitleAndDescEntity.java
0 → 100644
View file @
ce4d270e
package
cn
.
com
.
poc
.
agent_application
.
entity
;
public
class
CreateAgentTitleAndDescEntity
{
private
String
agentTitle
;
private
String
agentDesc
;
public
String
getAgentTitle
()
{
return
agentTitle
;
}
public
void
setAgentTitle
(
String
agentTitle
)
{
this
.
agentTitle
=
agentTitle
;
}
public
String
getAgentDesc
()
{
return
agentDesc
;
}
public
void
setAgentDesc
(
String
agentDesc
)
{
this
.
agentDesc
=
agentDesc
;
}
@Override
public
String
toString
()
{
return
"CreateAgentTitleAndDescEntity{"
+
"agentTitle='"
+
agentTitle
+
'\''
+
", agentDesc='"
+
agentDesc
+
'\''
+
'}'
;
}
}
src/main/java/cn/com/poc/agent_application/rest/AgentApplicationInfoRest.java
View file @
ce4d270e
...
...
@@ -76,4 +76,9 @@ public interface AgentApplicationInfoRest extends BaseRest {
* AI创建应用头像
*/
String
createAgentApplicationAvatar
(
@RequestBody
AgentApplicationGCDto
dto
)
throws
Exception
;
/**
* AI创建应用标题和描述
*/
AgentApplicationGCDto
createAgentTitleAndDesc
(
@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 @
ce4d270e
...
...
@@ -6,6 +6,7 @@ import cn.com.poc.agent_application.convert.BizAgentApplicationLargeModelListCon
import
cn.com.poc.agent_application.dto.*
;
import
cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity
;
import
cn.com.poc.agent_application.entity.BizAgentApplicationLargeModelListEntity
;
import
cn.com.poc.agent_application.entity.CreateAgentTitleAndDescEntity
;
import
cn.com.poc.agent_application.query.AgentApplicationInfoQueryCondition
;
import
cn.com.poc.agent_application.rest.AgentApplicationInfoRest
;
import
cn.com.poc.agent_application.service.BizAgentApplicationInfoService
;
...
...
@@ -165,4 +166,17 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
Assert
.
isTrue
(
StringUtils
.
isNotBlank
(
dto
.
getAgentDesc
())
||
StringUtils
.
isNotBlank
(
dto
.
getAgentTitle
()),
"请输入标题或者描述再生成应用头像"
);
return
agentApplicationInfoService
.
createAgentIcon
(
dto
.
getAgentTitle
(),
dto
.
getAgentDesc
());
}
@Override
public
AgentApplicationGCDto
createAgentTitleAndDesc
(
AgentApplicationGCDto
dto
)
throws
Exception
{
Assert
.
notNull
(
dto
.
getInput
(),
"输入不能为空"
);
CreateAgentTitleAndDescEntity
entity
=
agentApplicationInfoService
.
createAgentTitleAndDesc
(
dto
.
getInput
());
if
(
null
==
entity
)
{
throw
new
BusinessException
(
"生成失败,请稍后重试"
);
}
AgentApplicationGCDto
result
=
new
AgentApplicationGCDto
();
result
.
setAgentTitle
(
entity
.
getAgentTitle
());
result
.
setAgentDesc
(
entity
.
getAgentDesc
());
return
result
;
}
}
\ No newline at end of file
src/test/java/cn/com/poc/AgentApplicationInfoTest.java
0 → 100644
View file @
ce4d270e
package
cn
.
com
.
poc
;
import
cn.com.poc.agent_application.aggregate.AgentApplicationInfoService
;
import
cn.com.yict.framemax.core.spring.SingleContextInitializer
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
javax.annotation.Resource
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
initializers
=
SingleContextInitializer
.
class
)
@WebAppConfiguration
public
class
AgentApplicationInfoTest
{
@Resource
private
AgentApplicationInfoService
applicationInfoService
;
/**
* Agent 应用标题,描述生成
*/
@Test
public
void
createAgentTitleAndDesc
()
{
String
input
=
"测试标题"
;
System
.
out
.
println
(
applicationInfoService
.
createAgentTitleAndDesc
(
input
));
}
}
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