Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
陈老铁
chatbot-api
提交
efef5042
chatbot-api
项目概览
陈老铁
/
chatbot-api
与 Fork 源项目一致
Fork自
fuzhengwei / chatbot-api
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
chatbot-api
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
efef5042
编写于
1月 19, 2023
作者:
小傅哥
⛹
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
小傅哥,feat:第5节:整合知识星球与ChatGPT
上级
72ad219e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
111 addition
and
12 deletion
+111
-12
chatbot-api-application/pom.xml
chatbot-api-application/pom.xml
+24
-0
chatbot-api-application/src/main/java/cn/bugstack/chatbot/api/application/job/ChatbotSchedule.java
...bugstack/chatbot/api/application/job/ChatbotSchedule.java
+79
-0
chatbot-api-domain/pom.xml
chatbot-api-domain/pom.xml
+0
-6
chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/IZsxqApi.java
...in/java/cn/bugstack/chatbot/api/domain/zsxq/IZsxqApi.java
+0
-4
chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/service/ZsxqApi.java
.../cn/bugstack/chatbot/api/domain/zsxq/service/ZsxqApi.java
+2
-2
chatbot-api-interfaces/pom.xml
chatbot-api-interfaces/pom.xml
+5
-0
chatbot-api-interfaces/src/main/java/cn/bugstack/chatbot/api/ApiApplication.java
...src/main/java/cn/bugstack/chatbot/api/ApiApplication.java
+1
-0
未找到文件。
chatbot-api-application/pom.xml
浏览文件 @
efef5042
...
...
@@ -11,5 +11,29 @@
<artifactId>
chatbot-api-application
</artifactId>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
</dependency>
<dependency>
<groupId>
cn.bugstack.ai
</groupId>
<artifactId>
chatbot-api-domain
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
chatbot-api-application/src/main/java/cn/bugstack/chatbot/api/application/job/ChatbotSchedule.java
0 → 100644
浏览文件 @
efef5042
package
cn.bugstack.chatbot.api.application.job
;
import
cn.bugstack.chatbot.api.domain.ai.IOpenAI
;
import
cn.bugstack.chatbot.api.domain.zsxq.IZsxqApi
;
import
cn.bugstack.chatbot.api.domain.zsxq.model.aggregates.UnAnsweredQuestionsAggregates
;
import
cn.bugstack.chatbot.api.domain.zsxq.model.vo.Topics
;
import
com.alibaba.fastjson.JSON
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
javax.annotation.Resource
;
import
java.util.Calendar
;
import
java.util.GregorianCalendar
;
import
java.util.List
;
import
java.util.Random
;
/**
* @author 小傅哥,微信:fustack
* @description 问题任务
* @github https://github.com/fuzhengwei
* @Copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获!
*/
@EnableScheduling
@Configuration
public
class
ChatbotSchedule
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
ChatbotSchedule
.
class
);
@Value
(
"${chatbot-api.groupId}"
)
private
String
groupId
;
@Value
(
"${chatbot-api.cookie}"
)
private
String
cookie
;
@Resource
private
IZsxqApi
zsxqApi
;
@Resource
private
IOpenAI
openAI
;
// 表达式:cron.qqe2.com
@Scheduled
(
cron
=
"0/30 * * * * ?"
)
public
void
run
()
{
try
{
if
(
new
Random
().
nextBoolean
())
{
logger
.
info
(
"随机打烊中..."
);
return
;
}
GregorianCalendar
calendar
=
new
GregorianCalendar
();
int
hour
=
calendar
.
get
(
Calendar
.
HOUR_OF_DAY
);
if
(
hour
>
22
||
hour
<
7
)
{
logger
.
info
(
"打烊时间不工作,AI 下班了!"
);
return
;
}
// 1. 检索问题
UnAnsweredQuestionsAggregates
unAnsweredQuestionsAggregates
=
zsxqApi
.
queryUnAnsweredQuestionsTopicId
(
groupId
,
cookie
);
logger
.
info
(
"检索结果:{}"
,
JSON
.
toJSONString
(
unAnsweredQuestionsAggregates
));
List
<
Topics
>
topics
=
unAnsweredQuestionsAggregates
.
getResp_data
().
getTopics
();
if
(
null
==
topics
||
topics
.
isEmpty
())
{
logger
.
info
(
"本次检索未查询到待会答问题"
);
return
;
}
// 2. AI 回答
Topics
topic
=
topics
.
get
(
0
);
String
answer
=
openAI
.
doChatGPT
(
topic
.
getQuestion
().
getText
().
trim
());
// 3. 问题回复
boolean
status
=
zsxqApi
.
answer
(
groupId
,
cookie
,
topic
.
getTopic_id
(),
answer
,
false
);
logger
.
info
(
"编号:{} 问题:{} 回答:{} 状态:{}"
,
topic
.
getTopic_id
(),
topic
.
getQuestion
().
getText
(),
answer
,
status
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"自动回答问题异常"
,
e
);
}
}
}
chatbot-api-domain/pom.xml
浏览文件 @
efef5042
...
...
@@ -42,12 +42,6 @@
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpmime
</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sf.json-lib/json-lib -->
<dependency>
<groupId>
net.sf.json-lib
</groupId>
<artifactId>
json-lib
</artifactId>
<classifier>
jdk15
</classifier>
<!-- jdk版本 -->
</dependency>
</dependencies>
</project>
\ No newline at end of file
chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/IZsxqApi.java
浏览文件 @
efef5042
package
cn.bugstack.chatbot.api.domain.zsxq
;
import
cn.bugstack.chatbot.api.domain.zsxq.model.aggregates.UnAnsweredQuestionsAggregates
;
import
com.sun.xml.internal.ws.policy.privateutil.PolicyUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
/**
...
...
chatbot-api-domain/src/main/java/cn/bugstack/chatbot/api/domain/zsxq/service/ZsxqApi.java
浏览文件 @
efef5042
...
...
@@ -6,7 +6,7 @@ import cn.bugstack.chatbot.api.domain.zsxq.model.req.AnswerReq;
import
cn.bugstack.chatbot.api.domain.zsxq.model.req.ReqData
;
import
cn.bugstack.chatbot.api.domain.zsxq.model.res.AnswerRes
;
import
com.alibaba.fastjson.JSON
;
import
net.sf.
json.JSONObject
;
import
com.alibaba.fast
json.JSONObject
;
import
org.apache.http.HttpStatus
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
...
...
@@ -73,7 +73,7 @@ public class ZsxqApi implements IZsxqApi {
*/
AnswerReq
answerReq
=
new
AnswerReq
(
new
ReqData
(
text
,
silenced
));
String
paramJson
=
JSONObject
.
fromObject
(
answerReq
).
toString
(
);
String
paramJson
=
JSONObject
.
toJSONString
(
answerReq
);
StringEntity
stringEntity
=
new
StringEntity
(
paramJson
,
ContentType
.
create
(
"text/json"
,
"UTF-8"
));
post
.
setEntity
(
stringEntity
);
...
...
chatbot-api-interfaces/pom.xml
浏览文件 @
efef5042
...
...
@@ -78,6 +78,11 @@
<artifactId>
chatbot-api-domain
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
cn.bugstack.ai
</groupId>
<artifactId>
chatbot-api-application
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
chatbot-api-interfaces/src/main/java/cn/bugstack/chatbot/api/ApiApplication.java
浏览文件 @
efef5042
...
...
@@ -2,6 +2,7 @@ package cn.bugstack.chatbot.api;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.ComponentScan
;
/**
* @author 小傅哥,微信:fustack
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录