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
b6c4341e
Commit
b6c4341e
authored
Sep 18, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:Agent应用 追问接口调整
parent
7cfa6685
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
118 additions
and
58 deletions
+118
-58
AgentApplicationInfoService.java
...nt_application/aggregate/AgentApplicationInfoService.java
+4
-2
AgentApplicationInfoServiceImpl.java
...ation/aggregate/impl/AgentApplicationInfoServiceImpl.java
+27
-44
AgentApplicationCreateContinueQuesDto.java
...pplication/dto/AgentApplicationCreateContinueQuesDto.java
+21
-8
BizAgentApplicationInfoEntity.java
...ent_application/entity/BizAgentApplicationInfoEntity.java
+34
-1
AgentApplicationInfoRest.java
.../poc/agent_application/rest/AgentApplicationInfoRest.java
+1
-1
AgentApplicationInfoRestImpl.java
...t_application/rest/impl/AgentApplicationInfoRestImpl.java
+4
-2
LargeModelDemandResult.java
...e/demand/ai/entity/largemodel/LargeModelDemandResult.java
+8
-0
LargeModelResponse.java
...ource/demand/ai/entity/largemodel/LargeModelResponse.java
+19
-0
No files found.
src/main/java/cn/com/poc/agent_application/aggregate/AgentApplicationInfoService.java
View file @
b6c4341e
...
...
@@ -53,8 +53,10 @@ public interface AgentApplicationInfoService {
/**
* 追问AI生成
*
* @param messages@return
* @param input 问题输入
* @param agentId 应用id
* @return
*/
List
<
String
>
createContinueQuestions
(
List
<
Message
>
messages
,
String
agentId
);
List
<
String
>
createContinueQuestions
(
String
input
,
String
agentId
);
}
src/main/java/cn/com/poc/agent_application/aggregate/impl/AgentApplicationInfoServiceImpl.java
View file @
b6c4341e
...
...
@@ -71,6 +71,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
bizAgentApplicationInfoEntity
.
setAgentPublishStatus
(
AgentApplicationConstants
.
AGENT_PUBLISH_STATUS
.
PUBLISH
);
bizAgentApplicationInfoEntity
.
setPublishTime
(
new
Date
());
if
(
null
==
bizAgentApplicationInfoService
.
update
(
bizAgentApplicationInfoEntity
))
{
logger
.
error
(
"update and publish agent error , bizAgentApplicationInfoEntity:{}"
,
bizAgentApplicationInfoEntity
);
throw
new
BusinessException
(
"发布失败"
);
}
...
...
@@ -102,7 +103,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
@Override
public
void
createAgentSystem
(
String
input
,
HttpServletResponse
httpServletResponse
)
throws
Exception
{
BizAgentApplicationGcConfigEntity
configEntity
=
bizAgentApplicationGcConfigService
.
getByConfigCode
(
AgentApplicationGCConfigConstants
.
AGENT_SYSTEM
);
if
(
null
==
configEntity
)
{
if
(
null
==
configEntity
||
StringUtils
.
isBlank
(
configEntity
.
getConfigSystem
())
)
{
throw
new
BusinessException
(
"创建[角色指令]配置不存在"
);
}
...
...
@@ -133,15 +134,19 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
@Override
public
String
createPreamble
(
String
agentTitle
,
String
agentDesc
)
{
BizAgentApplicationGcConfigEntity
configEntity
=
bizAgentApplicationGcConfigService
.
getByConfigCode
(
AgentApplicationGCConfigConstants
.
AGENT_PREAMBLE
);
if
(
null
==
configEntity
)
{
if
(
null
==
configEntity
||
StringUtils
.
isBlank
(
configEntity
.
getConfigSystem
())
)
{
throw
new
BusinessException
(
"创建[开场白]配置不存在"
);
}
List
<
MultiContent
>
multiContents
=
new
ArrayList
<>();
multiContents
.
add
(
new
MultiContent
()
{{
String
configSystem
=
configEntity
.
getConfigSystem
();
configSystem
=
configSystem
.
replace
(
"${agent_title}"
,
agentTitle
);
configSystem
=
configSystem
.
replace
(
"${agent_desc}"
,
agentDesc
);
if
(
StringUtils
.
isNotBlank
(
agentTitle
))
{
configSystem
=
configSystem
.
replace
(
"${agent_title}"
,
agentTitle
);
}
if
(
StringUtils
.
isNotBlank
(
agentDesc
))
{
configSystem
=
configSystem
.
replace
(
"${agent_desc}"
,
agentDesc
);
}
setText
(
configSystem
);
setType
(
"text"
);
}});
...
...
@@ -165,15 +170,19 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
@Override
public
List
<
String
>
createFeaturedQuestions
(
String
agentTitle
,
String
agentDesc
)
{
BizAgentApplicationGcConfigEntity
configEntity
=
bizAgentApplicationGcConfigService
.
getByConfigCode
(
AgentApplicationGCConfigConstants
.
AGENT_FEATURED_QUESTIONS
);
if
(
null
==
configEntity
)
{
if
(
null
==
configEntity
||
StringUtils
.
isBlank
(
configEntity
.
getConfigSystem
())
)
{
throw
new
BusinessException
(
"创建[开场白]配置不存在"
);
}
List
<
MultiContent
>
multiContents
=
new
ArrayList
<>();
multiContents
.
add
(
new
MultiContent
()
{{
String
configSystem
=
configEntity
.
getConfigSystem
();
configSystem
=
configSystem
.
replace
(
"${agent_title}"
,
agentTitle
);
configSystem
=
configSystem
.
replace
(
"${agent_desc}"
,
agentDesc
);
if
(
StringUtils
.
isNotEmpty
(
agentTitle
))
{
configSystem
=
configSystem
.
replace
(
"${agent_title}"
,
agentTitle
);
}
if
(
StringUtils
.
isNotEmpty
(
agentDesc
))
{
configSystem
=
configSystem
.
replace
(
"${agent_desc}"
,
agentDesc
);
}
setText
(
configSystem
);
setType
(
"text"
);
}});
...
...
@@ -199,72 +208,46 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
}
@Override
public
List
<
String
>
createContinueQuestions
(
List
<
Message
>
messages
,
String
agentId
)
{
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
(
"
连续问题已关闭"
);
logger
.
warn
(
"
continue question is close ,agent_info:{}"
,
infoEntity
);
return
null
;
}
String
configSystem
=
configEntity
.
getConfigSystem
();
int
turn
=
3
;
if
(
AgentApplicationConstants
.
CONTINUOUS_QUESTION_STATUS
.
CUSTOMIZABLE
.
equals
(
continuousQuestionStatus
))
{
configSystem
=
configSystem
.
replace
(
"${input}"
,
infoEntity
.
getContinuousQuestionSystem
());
turn
=
infoEntity
.
getContinuousQuestionTurn
();
}
configSystem
=
configSystem
.
replace
(
"${input}"
,
input
);
MultiContent
systemMultiContent
=
new
MultiContent
();
systemMultiContent
.
setText
(
configSystem
);
systemMultiContent
.
setType
(
"text"
);
List
<
MultiContent
>
multiContents
=
new
ArrayList
<>();
multiContents
.
add
(
systemMultiContent
);
Message
systemMessage
=
new
Message
();
systemMessage
.
setContent
(
multiContents
);
systemMessage
.
setRole
(
AgentApplicationDialoguesRecordConstants
.
ROLE
.
SYSTEM
);
int
messLength
=
messages
.
size
()
-
1
;
int
skip
=
turn
*
2
;
if
(
skip
<
messLength
)
{
messages
=
messages
.
subList
(
messLength
-
skip
,
messages
.
size
());
}
StringBuilder
userBuilder
=
new
StringBuilder
();
for
(
Message
message
:
messages
)
{
userBuilder
.
append
(
message
.
getRole
()).
append
(
":"
).
append
(
message
.
getContent
().
get
(
0
).
getText
()).
append
(
StringUtils
.
LF
);
}
MultiContent
multiContent
=
new
MultiContent
();
multiContent
.
setText
(
userBuilder
.
toString
());
multiContent
.
setType
(
"text"
);
List
<
MultiContent
>
userMultiContent
=
new
ArrayList
<>();
userMultiContent
.
add
(
multiContent
);
Message
message
=
new
Message
();
message
.
setContent
(
userMultiContent
);
message
.
setContent
(
multiContents
);
message
.
setRole
(
AgentApplicationDialoguesRecordConstants
.
ROLE
.
USER
);
LargeModelResponse
largeModelResponse
=
new
LargeModelResponse
();
largeModelResponse
.
setModel
(
configEntity
.
getLargeModel
());
largeModelResponse
.
setMessages
(
new
ArrayList
<
Message
>()
{{
add
(
systemMessage
);
add
(
message
);
}}.
toArray
(
new
Message
[
2
]));
}}.
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
(
"]"
);
...
...
src/main/java/cn/com/poc/agent_application/dto/AgentApplicationCreateContinueQuesDto.java
View file @
b6c4341e
package
cn
.
com
.
poc
.
agent_application
.
dto
;
import
cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message
;
import
java.io.Serializable
;
import
java.util.List
;
public
class
AgentApplicationCreateContinueQuesDto
implements
Serializable
{
private
List
<
Message
>
messages
;
/**
* 问题输入
*/
private
String
input
;
/**
* 应用ID
*/
private
String
agentId
;
public
String
getInput
()
{
return
input
;
}
public
void
setInput
(
String
input
)
{
this
.
input
=
input
;
}
public
List
<
Message
>
getMessages
()
{
return
messages
;
public
String
getAgentId
()
{
return
agentId
;
}
public
void
set
Messages
(
List
<
Message
>
messages
)
{
this
.
messages
=
messages
;
public
void
set
AgentId
(
String
agentId
)
{
this
.
agentId
=
agentId
;
}
}
src/main/java/cn/com/poc/agent_application/entity/BizAgentApplicationInfoEntity.java
View file @
b6c4341e
package
cn
.
com
.
poc
.
agent_application
.
entity
;
package
cn
.
com
.
poc
.
agent_application
.
entity
;
import
java.util.Arrays
;
public
class
BizAgentApplicationInfoEntity
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -304,4 +306,35 @@ public class BizAgentApplicationInfoEntity {
public
void
setSysVersion
(
java
.
lang
.
Integer
sysVersion
){
this
.
sysVersion
=
sysVersion
;
}
@Override
public
String
toString
()
{
return
"BizAgentApplicationInfoEntity{"
+
"id="
+
id
+
", memberId="
+
memberId
+
", agentId='"
+
agentId
+
'\''
+
", agentAvatar='"
+
agentAvatar
+
'\''
+
", agentTitle='"
+
agentTitle
+
'\''
+
", agentDesc='"
+
agentDesc
+
'\''
+
", agentSystem='"
+
agentSystem
+
'\''
+
", agentPublishStatus='"
+
agentPublishStatus
+
'\''
+
", publishTime="
+
publishTime
+
", preamble='"
+
preamble
+
'\''
+
", featuredQuestions="
+
Arrays
.
toString
(
featuredQuestions
)
+
", communicationTurn="
+
communicationTurn
+
", continuousQuestionStatus='"
+
continuousQuestionStatus
+
'\''
+
", continuousQuestionSystem='"
+
continuousQuestionSystem
+
'\''
+
", continuousQuestionTurn="
+
continuousQuestionTurn
+
", knowledgeIds="
+
Arrays
.
toString
(
knowledgeIds
)
+
", largeModel='"
+
largeModel
+
'\''
+
", topP="
+
topP
+
", unitIds="
+
Arrays
.
toString
(
unitIds
)
+
", isDeleted='"
+
isDeleted
+
'\''
+
", creator='"
+
creator
+
'\''
+
", createdTime="
+
createdTime
+
", modifier='"
+
modifier
+
'\''
+
", modifiedTime="
+
modifiedTime
+
", sysVersion="
+
sysVersion
+
'}'
;
}
}
\ No newline at end of file
src/main/java/cn/com/poc/agent_application/rest/AgentApplicationInfoRest.java
View file @
b6c4341e
...
...
@@ -75,5 +75,5 @@ public interface AgentApplicationInfoRest extends BaseRest {
/**
* 追问
*/
List
<
String
>
createContinueQuestions
(
@RequestBody
AgentApplicationCreateContinueQuesDto
dto
,
@RequestParam
String
agentId
)
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 @
b6c4341e
...
...
@@ -161,7 +161,9 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
}
@Override
public
List
<
String
>
createContinueQuestions
(
AgentApplicationCreateContinueQuesDto
dto
,
String
agentId
)
throws
Exception
{
return
agentApplicationInfoService
.
createContinueQuestions
(
dto
.
getMessages
(),
agentId
);
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/thirdparty/resource/demand/ai/entity/largemodel/LargeModelDemandResult.java
View file @
b6c4341e
...
...
@@ -25,4 +25,12 @@ public class LargeModelDemandResult extends AbstractResult implements Serializab
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
@Override
public
String
toString
()
{
return
"LargeModelDemandResult{"
+
"code='"
+
code
+
'\''
+
", message='"
+
message
+
'\''
+
'}'
;
}
}
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/entity/largemodel/LargeModelResponse.java
View file @
b6c4341e
...
...
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
java.io.Serializable
;
import
java.util.Arrays
;
import
java.util.Map
;
/**
...
...
@@ -140,4 +141,22 @@ public class LargeModelResponse implements Serializable {
public
void
setUser
(
String
user
)
{
this
.
user
=
user
;
}
@Override
public
String
toString
()
{
return
"LargeModelResponse{"
+
"model='"
+
model
+
'\''
+
", messages="
+
Arrays
.
toString
(
messages
)
+
", temperature="
+
temperature
+
", topP="
+
topP
+
", n="
+
n
+
", stream="
+
stream
+
", stop="
+
Arrays
.
toString
(
stop
)
+
", maxTokens="
+
maxTokens
+
", presencePenalty="
+
presencePenalty
+
", frequencyPenalty="
+
frequencyPenalty
+
", logit_bias="
+
logit_bias
+
", user='"
+
user
+
'\''
+
'}'
;
}
}
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