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
164fd5ed
Commit
164fd5ed
authored
Nov 12, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style:AgentApplicationService#getRecommendQuestions
parent
4dc76bfc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
13 deletions
+22
-13
AgentApplicationServiceImpl.java
...oc/expose/aggregate/impl/AgentApplicationServiceImpl.java
+22
-13
No files found.
src/main/java/cn/com/poc/expose/aggregate/impl/AgentApplicationServiceImpl.java
View file @
164fd5ed
...
...
@@ -14,6 +14,7 @@ import cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService;
import
cn.com.poc.agent_application.service.BizAgentApplicationPublishService
;
import
cn.com.poc.agent_application.service.BizMemberAgentApplicationCollectService
;
import
cn.com.poc.common.constant.CommonConstant
;
import
cn.com.poc.common.constant.XLangConstant
;
import
cn.com.poc.common.service.RedisService
;
import
cn.com.poc.common.utils.BlContext
;
import
cn.com.poc.common.utils.JsonUtils
;
...
...
@@ -191,7 +192,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
@Override
public
List
<
String
>
getRecommendQuestions
(
String
xlang
,
Long
memberId
)
{
if
(
StringUtils
.
isBlank
(
xlang
))
{
xlang
=
"zh-cn"
;
xlang
=
XLangConstant
.
ZH_CN
;
}
String
redisKey
=
AGENT_APPLICATION_RECOMMEND_QUESTIONS
+
xlang
;
...
...
@@ -210,32 +211,40 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
return
null
;
}
List
<
Object
>
lastRecomendIdSet
=
null
;
// 获取用户上一次的推荐话题ID,并在本次不重复获取该ID
if
(
memberId
!=
null
)
{
String
lastRecommendQuestionRedisKey
=
MEMBER_RECOMMEND_QUESTIONS_LAST
+
memberId
;
List
<
Object
>
lastRecomendIdSet
=
null
;
if
(
redisService
.
hasKey
(
lastRecommendQuestionRedisKey
))
{
lastRecomendIdSet
=
redisService
.
lGet
(
lastRecommendQuestionRedisKey
,
0
,
-
1
);
}
}
Set
<
Long
>
indexSet
=
new
HashSet
<>(
3
);
SecureRandom
secureRandom
=
new
SecureRandom
();
do
{
long
id
=
(
long
)
secureRandom
.
nextInt
((
int
)
size
);
if
(
lastRecomendIdSet
!=
null
&&
lastRecomendIdSet
.
stream
().
anyMatch
(
v
->
String
.
valueOf
(
v
).
equals
(
String
.
valueOf
(
id
))))
{
long
id
=
secureRandom
.
nextInt
((
int
)
size
);
if
(
CollectionUtils
.
isNotEmpty
(
lastRecomendIdSet
)
&&
lastRecomendIdSet
.
stream
().
anyMatch
(
v
->
String
.
valueOf
(
v
).
equals
(
String
.
valueOf
(
id
))))
{
continue
;
}
indexSet
.
add
(
id
);
}
while
(
indexSet
.
size
()
<
3
);
List
<
String
>
result
=
new
ArrayList
<>();
List
<
Object
>
recordId
=
new
ArrayList
<>(
3
);
List
<
String
>
result
=
new
ArrayList
<>(
3
);
List
<
Object
>
recordId
s
=
new
ArrayList
<>(
3
);
for
(
Long
index
:
indexSet
)
{
recordId
.
add
(
index
);
Object
str
=
redisService
.
lGetIndex
(
redisKey
,
index
);
result
.
add
(
str
.
toString
());
recordIds
.
add
(
index
);
}
//更新记录
if
(
memberId
!=
null
)
{
String
lastRecommendQuestionRedisKey
=
MEMBER_RECOMMEND_QUESTIONS_LAST
+
memberId
;
redisService
.
del
(
lastRecommendQuestionRedisKey
);
redisService
.
lSet
(
lastRecommendQuestionRedisKey
,
recordId
);
redisService
.
lSet
(
lastRecommendQuestionRedisKey
,
recordIds
,
10
*
60
);
}
return
result
;
}
...
...
@@ -257,7 +266,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
largeModelResponse
.
setMessages
(
messages
);
LargeModelDemandResult
largeModelDemandResult
=
llmService
.
chat
(
largeModelResponse
);
if
(
largeModel
Response
==
null
||
!
"0"
.
equals
(
largeModelDemandResult
.
getCode
()))
{
if
(
largeModel
DemandResult
==
null
||
!
"0"
.
equals
(
largeModelDemandResult
.
getCode
()))
{
throw
new
I18nMessageException
(
"exception/failed.to.generate.recommendation.question"
);
}
String
res
=
largeModelDemandResult
.
getMessage
();
...
...
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