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
bef92269
Commit
bef92269
authored
Sep 18, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:Agent应用 追问接口调整
parent
b6c4341e
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
85 additions
and
65 deletions
+85
-65
AgentApplicationInfoService.java
...nt_application/aggregate/AgentApplicationInfoService.java
+1
-8
AgentApplicationInfoServiceImpl.java
...ation/aggregate/impl/AgentApplicationInfoServiceImpl.java
+0
-47
AgentApplicationInfoRest.java
.../poc/agent_application/rest/AgentApplicationInfoRest.java
+1
-4
AgentApplicationInfoRestImpl.java
...t_application/rest/impl/AgentApplicationInfoRestImpl.java
+1
-6
AgentApplicationService.java
.../cn/com/poc/expose/aggregate/AgentApplicationService.java
+10
-0
AgentApplicationServiceImpl.java
...oc/expose/aggregate/impl/AgentApplicationServiceImpl.java
+57
-0
AgentApplicationRest.java
...ain/java/cn/com/poc/expose/rest/AgentApplicationRest.java
+7
-0
AgentApplicationRestImpl.java
...cn/com/poc/expose/rest/impl/AgentApplicationRestImpl.java
+8
-0
No files found.
src/main/java/cn/com/poc/agent_application/aggregate/AgentApplicationInfoService.java
View file @
bef92269
...
@@ -50,13 +50,6 @@ public interface AgentApplicationInfoService {
...
@@ -50,13 +50,6 @@ public interface AgentApplicationInfoService {
*/
*/
List
<
String
>
createFeaturedQuestions
(
String
agentTitle
,
String
agentDesc
);
List
<
String
>
createFeaturedQuestions
(
String
agentTitle
,
String
agentDesc
);
/**
* 追问AI生成
*
* @param input 问题输入
* @param agentId 应用id
* @return
*/
List
<
String
>
createContinueQuestions
(
String
input
,
String
agentId
);
}
}
src/main/java/cn/com/poc/agent_application/aggregate/impl/AgentApplicationInfoServiceImpl.java
View file @
bef92269
...
@@ -207,53 +207,6 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
...
@@ -207,53 +207,6 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
}.
getType
());
}.
getType
());
}
}
@Override
public
List
<
String
>
createContinueQuestions
(
String
input
,
String
agentId
)
{
BizAgentApplicationGcConfigEntity
configEntity
=
bizAgentApplicationGcConfigService
.
getByConfigCode
(
AgentApplicationGCConfigConstants
.
AGENT_CONTINUE_QUESTIONS
);
if
(
null
==
configEntity
)
{
throw
new
BusinessException
(
"创建[开场白]配置不存在"
);
}
BizAgentApplicationInfoEntity
infoEntity
=
bizAgentApplicationInfoService
.
getByAgentId
(
agentId
);
String
continuousQuestionStatus
=
infoEntity
.
getContinuousQuestionStatus
();
if
(
AgentApplicationConstants
.
CONTINUOUS_QUESTION_STATUS
.
CLOSE
.
equals
(
continuousQuestionStatus
))
{
logger
.
warn
(
"continue question is close ,agent_info:{}"
,
infoEntity
);
return
null
;
}
String
configSystem
=
configEntity
.
getConfigSystem
();
configSystem
=
configSystem
.
replace
(
"${input}"
,
input
);
MultiContent
systemMultiContent
=
new
MultiContent
();
systemMultiContent
.
setText
(
configSystem
);
systemMultiContent
.
setType
(
"text"
);
List
<
MultiContent
>
multiContents
=
new
ArrayList
<>();
multiContents
.
add
(
systemMultiContent
);
Message
message
=
new
Message
();
message
.
setContent
(
multiContents
);
message
.
setRole
(
AgentApplicationDialoguesRecordConstants
.
ROLE
.
USER
);
LargeModelResponse
largeModelResponse
=
new
LargeModelResponse
();
largeModelResponse
.
setModel
(
configEntity
.
getLargeModel
());
largeModelResponse
.
setMessages
(
new
ArrayList
<
Message
>()
{{
add
(
message
);
}}.
toArray
(
new
Message
[
1
]));
largeModelResponse
.
setTopP
(
configEntity
.
getTopP
());
largeModelResponse
.
setUser
(
"POC-CONTINUE-QUESTIONS"
);
LargeModelDemandResult
largeModelDemandResult
=
llmService
.
chat
(
largeModelResponse
);
if
(
largeModelDemandResult
==
null
||
!
"0"
.
equals
(
largeModelDemandResult
.
getCode
()))
{
logger
.
error
(
"continue question error ,largeModelDemandResult:{} , largeModelResponse:{}"
,
largeModelDemandResult
!=
null
?
largeModelDemandResult
.
toString
()
:
StringUtils
.
EMPTY
,
largeModelResponse
);
// throw new BusinessException("追问失败");
return
null
;
}
String
res
=
largeModelDemandResult
.
getMessage
();
int
start
=
res
.
lastIndexOf
(
"["
);
int
end
=
res
.
lastIndexOf
(
"]"
);
return
JsonUtils
.
deSerialize
(
res
.
substring
(
start
,
end
+
1
),
new
TypeReference
<
List
<
String
>>()
{
}.
getType
());
}
private
String
buildDialogsPrompt
(
List
<
Message
>
messages
,
String
agentSystem
,
String
[]
knowledgeIds
)
{
private
String
buildDialogsPrompt
(
List
<
Message
>
messages
,
String
agentSystem
,
String
[]
knowledgeIds
)
{
// todo 获取提示词模板
// todo 获取提示词模板
...
...
src/main/java/cn/com/poc/agent_application/rest/AgentApplicationInfoRest.java
View file @
bef92269
...
@@ -72,8 +72,5 @@ public interface AgentApplicationInfoRest extends BaseRest {
...
@@ -72,8 +72,5 @@ public interface AgentApplicationInfoRest extends BaseRest {
*/
*/
String
createPreamble
(
@RequestBody
AgentApplicationGCDto
dto
)
throws
Exception
;
String
createPreamble
(
@RequestBody
AgentApplicationGCDto
dto
)
throws
Exception
;
/**
* 追问
*/
List
<
String
>
createContinueQuestions
(
@RequestBody
AgentApplicationCreateContinueQuesDto
dto
)
throws
Exception
;
}
}
\ No newline at end of file
src/main/java/cn/com/poc/agent_application/rest/impl/AgentApplicationInfoRestImpl.java
View file @
bef92269
...
@@ -160,10 +160,5 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
...
@@ -160,10 +160,5 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
return
agentApplicationInfoService
.
createPreamble
(
dto
.
getAgentTitle
(),
dto
.
getAgentDesc
());
return
agentApplicationInfoService
.
createPreamble
(
dto
.
getAgentTitle
(),
dto
.
getAgentDesc
());
}
}
@Override
public
List
<
String
>
createContinueQuestions
(
AgentApplicationCreateContinueQuesDto
dto
)
throws
Exception
{
cn
.
com
.
poc
.
common
.
utils
.
Assert
.
notNull
(
dto
.
getInput
(),
"agentId不能为空"
);
cn
.
com
.
poc
.
common
.
utils
.
Assert
.
notNull
(
dto
.
getAgentId
(),
"input不能为空"
);
return
agentApplicationInfoService
.
createContinueQuestions
(
dto
.
getInput
(),
dto
.
getAgentId
());
}
}
}
\ No newline at end of file
src/main/java/cn/com/poc/expose/aggregate/AgentApplicationService.java
View file @
bef92269
...
@@ -3,6 +3,7 @@ package cn.com.poc.expose.aggregate;
...
@@ -3,6 +3,7 @@ package cn.com.poc.expose.aggregate;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.List
;
public
interface
AgentApplicationService
{
public
interface
AgentApplicationService
{
...
@@ -11,4 +12,13 @@ public interface AgentApplicationService {
...
@@ -11,4 +12,13 @@ public interface AgentApplicationService {
*/
*/
void
callAgentApplication
(
String
agentId
,
String
dialogsId
,
String
input
,
HttpServletResponse
httpServletResponse
)
throws
Exception
;
void
callAgentApplication
(
String
agentId
,
String
dialogsId
,
String
input
,
HttpServletResponse
httpServletResponse
)
throws
Exception
;
/**
* 追问AI生成
*
* @param input 问题输入
* @param agentId 应用id
* @return
*/
List
<
String
>
createContinueQuestions
(
String
input
,
String
agentId
);
}
}
src/main/java/cn/com/poc/expose/aggregate/impl/AgentApplicationServiceImpl.java
View file @
bef92269
...
@@ -3,9 +3,13 @@ package cn.com.poc.expose.aggregate.impl;
...
@@ -3,9 +3,13 @@ package cn.com.poc.expose.aggregate.impl;
import
cn.com.poc.agent_application.aggregate.AgentApplicationInfoService
;
import
cn.com.poc.agent_application.aggregate.AgentApplicationInfoService
;
import
cn.com.poc.agent_application.constant.AgentApplicationConstants
;
import
cn.com.poc.agent_application.constant.AgentApplicationConstants
;
import
cn.com.poc.agent_application.constant.AgentApplicationDialoguesRecordConstants
;
import
cn.com.poc.agent_application.constant.AgentApplicationDialoguesRecordConstants
;
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.BizAgentApplicationInfoEntity
;
import
cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity
;
import
cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity
;
import
cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordService
;
import
cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordService
;
import
cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService
;
import
cn.com.poc.agent_application.service.BizAgentApplicationPublishService
;
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
;
...
@@ -15,8 +19,13 @@ import cn.com.poc.expose.rest.AgentApplicationRest;
...
@@ -15,8 +19,13 @@ import cn.com.poc.expose.rest.AgentApplicationRest;
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.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.largemodel.LargeModelDemandResult
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelResponse
;
import
cn.com.poc.thirdparty.service.LLMService
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -40,6 +49,12 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
...
@@ -40,6 +49,12 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
@Resource
@Resource
private
AgentApplicationInfoService
agentApplicationInfoService
;
private
AgentApplicationInfoService
agentApplicationInfoService
;
@Resource
private
BizAgentApplicationGcConfigService
bizAgentApplicationGcConfigService
;
@Resource
private
LLMService
llmService
;
@Override
@Override
public
void
callAgentApplication
(
String
agentId
,
String
dialogsId
,
String
input
,
HttpServletResponse
httpServletResponse
)
throws
Exception
{
public
void
callAgentApplication
(
String
agentId
,
String
dialogsId
,
String
input
,
HttpServletResponse
httpServletResponse
)
throws
Exception
{
...
@@ -92,6 +107,48 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
...
@@ -92,6 +107,48 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
bizAgentApplicationDialoguesRecordService
.
save
(
outputRecord
);
bizAgentApplicationDialoguesRecordService
.
save
(
outputRecord
);
}
}
@Override
public
List
<
String
>
createContinueQuestions
(
String
input
,
String
agentId
)
{
BizAgentApplicationGcConfigEntity
configEntity
=
bizAgentApplicationGcConfigService
.
getByConfigCode
(
AgentApplicationGCConfigConstants
.
AGENT_CONTINUE_QUESTIONS
);
if
(
null
==
configEntity
)
{
throw
new
BusinessException
(
"创建[开场白]配置不存在"
);
}
String
configSystem
=
configEntity
.
getConfigSystem
();
configSystem
=
configSystem
.
replace
(
"${input}"
,
input
);
MultiContent
systemMultiContent
=
new
MultiContent
();
systemMultiContent
.
setText
(
configSystem
);
systemMultiContent
.
setType
(
"text"
);
List
<
MultiContent
>
multiContents
=
new
ArrayList
<>();
multiContents
.
add
(
systemMultiContent
);
Message
message
=
new
Message
();
message
.
setContent
(
multiContents
);
message
.
setRole
(
AgentApplicationDialoguesRecordConstants
.
ROLE
.
USER
);
LargeModelResponse
largeModelResponse
=
new
LargeModelResponse
();
largeModelResponse
.
setModel
(
configEntity
.
getLargeModel
());
largeModelResponse
.
setMessages
(
new
ArrayList
<
Message
>()
{{
add
(
message
);
}}.
toArray
(
new
Message
[
1
]));
largeModelResponse
.
setTopP
(
configEntity
.
getTopP
());
largeModelResponse
.
setUser
(
"POC-CONTINUE-QUESTIONS"
);
LargeModelDemandResult
largeModelDemandResult
=
llmService
.
chat
(
largeModelResponse
);
if
(
largeModelDemandResult
==
null
||
!
"0"
.
equals
(
largeModelDemandResult
.
getCode
()))
{
logger
.
error
(
"continue question error ,largeModelDemandResult:{} , largeModelResponse:{}"
,
largeModelDemandResult
!=
null
?
largeModelDemandResult
.
toString
()
:
StringUtils
.
EMPTY
,
largeModelResponse
);
// throw new BusinessException("追问失败");
return
null
;
}
String
res
=
largeModelDemandResult
.
getMessage
();
int
start
=
res
.
lastIndexOf
(
"["
);
int
end
=
res
.
lastIndexOf
(
"]"
);
return
JsonUtils
.
deSerialize
(
res
.
substring
(
start
,
end
+
1
),
new
TypeReference
<
List
<
String
>>()
{
}.
getType
());
}
private
void
buildMessages
(
String
dialogsId
,
String
agentId
,
Long
userId
,
List
<
Message
>
messages
,
String
input
)
throws
Exception
{
private
void
buildMessages
(
String
dialogsId
,
String
agentId
,
Long
userId
,
List
<
Message
>
messages
,
String
input
)
throws
Exception
{
BizAgentApplicationDialoguesRecordEntity
recordEntity
=
new
BizAgentApplicationDialoguesRecordEntity
();
BizAgentApplicationDialoguesRecordEntity
recordEntity
=
new
BizAgentApplicationDialoguesRecordEntity
();
recordEntity
.
setDialogsId
(
dialogsId
);
recordEntity
.
setDialogsId
(
dialogsId
);
...
...
src/main/java/cn/com/poc/expose/rest/AgentApplicationRest.java
View file @
bef92269
package
cn
.
com
.
poc
.
expose
.
rest
;
package
cn
.
com
.
poc
.
expose
.
rest
;
import
cn.com.poc.agent_application.dto.AgentApplicationCreateContinueQuesDto
;
import
cn.com.poc.agent_application.dto.AgentApplicationInfoDto
;
import
cn.com.poc.agent_application.dto.AgentApplicationInfoDto
;
import
cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto
;
import
cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto
;
import
cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto
;
import
cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto
;
...
@@ -36,4 +37,10 @@ public interface AgentApplicationRest extends BaseRest {
...
@@ -36,4 +37,10 @@ public interface AgentApplicationRest extends BaseRest {
*/
*/
@Permission
(
value
=
Access
.
Anonymous
)
@Permission
(
value
=
Access
.
Anonymous
)
BizAgentApplicationPublishDto
getInfo
(
@RequestParam
String
agentId
)
throws
Exception
;
BizAgentApplicationPublishDto
getInfo
(
@RequestParam
String
agentId
)
throws
Exception
;
/**
* 追问
*/
List
<
String
>
createContinueQuestions
(
@RequestBody
AgentApplicationCreateContinueQuesDto
dto
)
throws
Exception
;
}
}
src/main/java/cn/com/poc/expose/rest/impl/AgentApplicationRestImpl.java
View file @
bef92269
...
@@ -2,6 +2,7 @@ package cn.com.poc.expose.rest.impl;
...
@@ -2,6 +2,7 @@ package cn.com.poc.expose.rest.impl;
import
cn.com.poc.agent_application.convert.AgentApplicationInfoConvert
;
import
cn.com.poc.agent_application.convert.AgentApplicationInfoConvert
;
import
cn.com.poc.agent_application.convert.BizAgentApplicationPublishConvert
;
import
cn.com.poc.agent_application.convert.BizAgentApplicationPublishConvert
;
import
cn.com.poc.agent_application.dto.AgentApplicationCreateContinueQuesDto
;
import
cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto
;
import
cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto
;
import
cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto
;
import
cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto
;
import
cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity
;
import
cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity
;
...
@@ -66,4 +67,11 @@ public class AgentApplicationRestImpl implements AgentApplicationRest {
...
@@ -66,4 +67,11 @@ public class AgentApplicationRestImpl implements AgentApplicationRest {
}
}
return
BizAgentApplicationPublishConvert
.
entityToDto
(
entity
);
return
BizAgentApplicationPublishConvert
.
entityToDto
(
entity
);
}
}
@Override
public
List
<
String
>
createContinueQuestions
(
AgentApplicationCreateContinueQuesDto
dto
)
throws
Exception
{
cn
.
com
.
poc
.
common
.
utils
.
Assert
.
notNull
(
dto
.
getInput
(),
"agentId不能为空"
);
cn
.
com
.
poc
.
common
.
utils
.
Assert
.
notNull
(
dto
.
getAgentId
(),
"input不能为空"
);
return
agentApplicationService
.
createContinueQuestions
(
dto
.
getInput
(),
dto
.
getAgentId
());
}
}
}
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