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
06124b3c
Commit
06124b3c
authored
Oct 22, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 首页推荐问
parent
a965da2a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
127 additions
and
0 deletions
+127
-0
RecommendQuestionScheduler.java
...ent_application/scheduler/RecommendQuestionScheduler.java
+30
-0
AgentApplicationService.java
.../cn/com/poc/expose/aggregate/AgentApplicationService.java
+12
-0
AgentApplicationServiceImpl.java
...oc/expose/aggregate/impl/AgentApplicationServiceImpl.java
+75
-0
AgentApplicationRest.java
...ain/java/cn/com/poc/expose/rest/AgentApplicationRest.java
+5
-0
AgentApplicationRestImpl.java
...cn/com/poc/expose/rest/impl/AgentApplicationRestImpl.java
+5
-0
No files found.
src/main/java/cn/com/poc/agent_application/scheduler/RecommendQuestionScheduler.java
0 → 100644
View file @
06124b3c
package
cn
.
com
.
poc
.
agent_application
.
scheduler
;
import
cn.com.poc.expose.aggregate.AgentApplicationService
;
import
cn.com.poc.knowledge.constant.KnowledgeConstant
;
import
cn.com.poc.knowledge.query.KnowledgeInfosQueryCondition
;
import
cn.com.poc.knowledge.query.KnowledgeInfosQueryItem
;
import
cn.com.poc.message.entity.KnowledgeTrainStatusMessage
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.List
;
@Component
public
class
RecommendQuestionScheduler
{
@Resource
private
AgentApplicationService
agentApplicationService
;
/**
* 每日凌晨
*
* @throws Exception
*/
@Scheduled
(
cron
=
"0 0 0 * * ?"
)
public
void
knowledgeInfoStatusUpdateScheduler
()
throws
Exception
{
agentApplicationService
.
createRecommendQuestion
();
}
}
src/main/java/cn/com/poc/expose/aggregate/AgentApplicationService.java
View file @
06124b3c
...
...
@@ -18,4 +18,16 @@ public interface AgentApplicationService {
*/
List
<
String
>
createContinueQuestions
(
String
input
);
/**
* [首页] 获取推荐问
*/
List
<
String
>
getRecommendQuestions
()
throws
InterruptedException
;
/**
* [首页] 生成推荐问
*
* @throws InterruptedException
*/
void
createRecommendQuestion
()
throws
InterruptedException
;
}
src/main/java/cn/com/poc/expose/aggregate/impl/AgentApplicationServiceImpl.java
View file @
06124b3c
...
...
@@ -10,6 +10,7 @@ import cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordSe
import
cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService
;
import
cn.com.poc.agent_application.service.BizAgentApplicationPublishService
;
import
cn.com.poc.common.constant.CommonConstant
;
import
cn.com.poc.common.service.RedisService
;
import
cn.com.poc.common.utils.BlContext
;
import
cn.com.poc.common.utils.JsonUtils
;
import
cn.com.poc.expose.aggregate.AgentApplicationService
;
...
...
@@ -33,14 +34,21 @@ import org.springframework.stereotype.Service;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
java.security.SecureRandom
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.concurrent.*
;
import
java.util.concurrent.atomic.AtomicInteger
;
@Service
public
class
AgentApplicationServiceImpl
implements
AgentApplicationService
{
final
private
Logger
logger
=
LoggerFactory
.
getLogger
(
AgentApplicationService
.
class
);
final
private
String
AGENT_APPLICATION_RECOMMEND_QUESTIONS
=
"AGENT_APPLICATION_RECOMMEND_QUESTIONS"
;
@Resource
private
KnowledgeService
knowledgeService
;
...
...
@@ -59,6 +67,9 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
@Resource
private
LLMService
llmService
;
@Resource
private
RedisService
redisService
;
@Override
public
void
callAgentApplication
(
String
agentId
,
String
dialogsId
,
String
input
,
HttpServletResponse
httpServletResponse
)
throws
Exception
{
...
...
@@ -172,6 +183,70 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
}.
getType
());
}
@Override
public
List
<
String
>
getRecommendQuestions
()
throws
InterruptedException
{
if
(!
redisService
.
hasKey
(
AGENT_APPLICATION_RECOMMEND_QUESTIONS
))
{
synchronized
(
AgentApplicationInfoService
.
class
)
{
if
(!
redisService
.
hasKey
(
AGENT_APPLICATION_RECOMMEND_QUESTIONS
))
{
createRecommendQuestion
();
}
}
}
long
size
=
redisService
.
lGetListSize
(
AGENT_APPLICATION_RECOMMEND_QUESTIONS
);
if
(
size
<
3
)
{
redisService
.
del
(
AGENT_APPLICATION_RECOMMEND_QUESTIONS
);
return
null
;
}
Set
<
Long
>
indexSet
=
new
HashSet
<>();
SecureRandom
secureRandom
=
new
SecureRandom
();
do
{
indexSet
.
add
((
long
)
secureRandom
.
nextInt
((
int
)
size
));
}
while
(
indexSet
.
size
()
<
3
);
List
<
String
>
result
=
new
ArrayList
<>();
for
(
Long
index
:
indexSet
)
{
Object
str
=
redisService
.
lGetIndex
(
AGENT_APPLICATION_RECOMMEND_QUESTIONS
,
index
);
result
.
add
(
str
.
toString
());
}
return
result
;
}
public
void
createRecommendQuestion
()
throws
InterruptedException
{
List
<
String
>
questions
=
new
CopyOnWriteArrayList
<>();
ThreadPoolExecutor
threadPoolExecutor
=
new
ThreadPoolExecutor
(
10
,
10
,
5
,
TimeUnit
.
SECONDS
,
new
LinkedBlockingDeque
<>());
CountDownLatch
countDownLatch
=
new
CountDownLatch
(
20
);
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
threadPoolExecutor
.
execute
(()
->
{
Message
message
=
new
Message
();
message
.
setRole
(
AgentApplicationDialoguesRecordConstants
.
ROLE
.
USER
);
MultiContent
multiContent
=
new
MultiContent
();
multiContent
.
setText
(
"请给我生成一个推荐问题,不超过50字"
);
multiContent
.
setType
(
"text"
);
ArrayList
<
MultiContent
>
multiContents
=
new
ArrayList
<>();
multiContents
.
add
(
multiContent
);
message
.
setContent
(
multiContents
);
Message
[]
messages
=
new
Message
[]{
message
};
LargeModelResponse
largeModelResponse
=
new
LargeModelResponse
();
largeModelResponse
.
setModel
(
"ERNIE-3.5-8K"
);
largeModelResponse
.
setMessages
(
messages
);
LargeModelDemandResult
largeModelDemandResult
=
llmService
.
chat
(
largeModelResponse
);
questions
.
add
(
largeModelDemandResult
.
getMessage
());
countDownLatch
.
countDown
();
});
}
countDownLatch
.
await
(
2
,
TimeUnit
.
MINUTES
);
redisService
.
del
(
AGENT_APPLICATION_RECOMMEND_QUESTIONS
);
for
(
String
question
:
questions
)
{
redisService
.
lSet
(
AGENT_APPLICATION_RECOMMEND_QUESTIONS
,
question
);
}
}
private
void
buildMessages
(
String
dialogsId
,
String
agentId
,
Long
userId
,
List
<
Message
>
messages
,
String
input
)
throws
Exception
{
BizAgentApplicationDialoguesRecordEntity
recordEntity
=
new
BizAgentApplicationDialoguesRecordEntity
();
recordEntity
.
setDialogsId
(
dialogsId
);
...
...
src/main/java/cn/com/poc/expose/rest/AgentApplicationRest.java
View file @
06124b3c
...
...
@@ -20,6 +20,11 @@ import java.util.List;
@Permission
(
value
=
Access
.
Safety
)
public
interface
AgentApplicationRest
extends
BaseRest
{
/**
* 【首页】 获取推荐问
*/
List
<
String
>
getRecommendQuestions
()
throws
Exception
;
/**
* 创建对话
*/
...
...
src/main/java/cn/com/poc/expose/rest/impl/AgentApplicationRestImpl.java
View file @
06124b3c
...
...
@@ -54,6 +54,11 @@ public class AgentApplicationRestImpl implements AgentApplicationRest {
@Resource
private
BizAgentApplicationDialoguesRecordService
bizAgentApplicationDialoguesRecordService
;
@Override
public
List
<
String
>
getRecommendQuestions
()
throws
Exception
{
return
agentApplicationService
.
getRecommendQuestions
();
}
@Override
public
String
createDialogues
()
{
return
"DIA_"
+
UUIDTool
.
getUUID
();
...
...
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