mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-18 01:06:39 +08:00
修复重复推送打招呼信息的 Bug
This commit is contained in:
parent
40bf2b5c1b
commit
e60decedd4
@ -18,7 +18,8 @@ func (s *Server) TestHandle(c *gin.Context) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) ConfigGetHandle(c *gin.Context) {
|
// GetAllConfigHandle 获取所有配置
|
||||||
|
func (s *Server) GetAllConfigHandle(c *gin.Context) {
|
||||||
data := struct {
|
data := struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
ConsoleTitle string `json:"console_title"`
|
ConsoleTitle string `json:"console_title"`
|
||||||
@ -44,6 +45,22 @@ func (s *Server) ConfigGetHandle(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, types.BizVo{Code: types.Success, Data: data})
|
c.JSON(http.StatusOK, types.BizVo{Code: types.Success, Data: data})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) GetConfigHandle(c *gin.Context) {
|
||||||
|
data := struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
ConsoleTitle string `json:"console_title"`
|
||||||
|
WechatCard string `json:"wechat_card"` // 个人微信二维码
|
||||||
|
WechatGroup string `json:"wechat_group"` // 微信群二维码
|
||||||
|
}{
|
||||||
|
Title: s.Config.Title,
|
||||||
|
ConsoleTitle: s.Config.ConsoleTitle,
|
||||||
|
WechatCard: s.Config.ImgURL.WechatCard,
|
||||||
|
WechatGroup: s.Config.ImgURL.WechatGroup,
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, types.BizVo{Code: types.Success, Data: data})
|
||||||
|
}
|
||||||
|
|
||||||
// ConfigSetHandle set configs
|
// ConfigSetHandle set configs
|
||||||
func (s *Server) ConfigSetHandle(c *gin.Context) {
|
func (s *Server) ConfigSetHandle(c *gin.Context) {
|
||||||
var data struct {
|
var data struct {
|
||||||
|
@ -95,7 +95,8 @@ func (s *Server) Run(webRoot embed.FS, path string, debug bool) {
|
|||||||
engine.POST("api/img/get", s.GetImgURLHandle)
|
engine.POST("api/img/get", s.GetImgURLHandle)
|
||||||
engine.POST("api/img/set", s.SetImgURLHandle)
|
engine.POST("api/img/set", s.SetImgURLHandle)
|
||||||
|
|
||||||
engine.GET("api/config/get", s.ConfigGetHandle)
|
engine.GET("api/config/get", s.GetConfigHandle) // 获取一些公开的配置信息,前端使用
|
||||||
|
engine.GET("api/admin/config/get", s.GetAllConfigHandle) // 获取所有配置,后台管理使用
|
||||||
engine.POST("api/admin/config/set", s.ConfigSetHandle)
|
engine.POST("api/admin/config/set", s.ConfigSetHandle)
|
||||||
|
|
||||||
engine.GET("api/chat-roles/list", s.GetChatRoleListHandle)
|
engine.GET("api/chat-roles/list", s.GetChatRoleListHandle)
|
||||||
@ -221,6 +222,7 @@ func AuthorizeMiddleware(s *Server) gin.HandlerFunc {
|
|||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
if c.Request.URL.Path == "/api/login" ||
|
if c.Request.URL.Path == "/api/login" ||
|
||||||
c.Request.URL.Path == "/api/admin/login" ||
|
c.Request.URL.Path == "/api/admin/login" ||
|
||||||
|
c.Request.URL.Path == "/api/config/get" ||
|
||||||
c.Request.URL.Path == "/api/chat-roles/list" ||
|
c.Request.URL.Path == "/api/chat-roles/list" ||
|
||||||
!strings.HasPrefix(c.Request.URL.Path, "/api") {
|
!strings.HasPrefix(c.Request.URL.Path, "/api") {
|
||||||
c.Next()
|
c.Next()
|
||||||
|
@ -116,7 +116,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-row class="row-center">
|
<el-row class="row-center">
|
||||||
<el-image src="images/wx.png" fit="cover"/>
|
<el-image :src="sysConfig['wechat_card']" fit="cover" style="width: 250px;"/>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
@ -153,6 +153,8 @@ export default defineComponent({
|
|||||||
showConfigDialog: false,
|
showConfigDialog: false,
|
||||||
userInfo: {},
|
userInfo: {},
|
||||||
showLoginDialog: false,
|
showLoginDialog: false,
|
||||||
|
sysConfig: {}, // 系统配置
|
||||||
|
hasHelloMsg: {}, // 是否发送过打招呼信息
|
||||||
|
|
||||||
showStopGenerate: false,
|
showStopGenerate: false,
|
||||||
showReGenerate: false,
|
showReGenerate: false,
|
||||||
@ -198,6 +200,13 @@ export default defineComponent({
|
|||||||
this.inputBoxWidth = window.innerWidth - 20;
|
this.inputBoxWidth = window.innerWidth - 20;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 获取系统配置
|
||||||
|
httpGet('/api/config/get').then((res) => {
|
||||||
|
this.sysConfig = res.data;
|
||||||
|
}).catch(() => {
|
||||||
|
ElMessage.error('获取系统配置失败')
|
||||||
|
})
|
||||||
|
|
||||||
this.connect();
|
this.connect();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -220,7 +229,7 @@ export default defineComponent({
|
|||||||
socket.addEventListener('open', () => {
|
socket.addEventListener('open', () => {
|
||||||
// 获取聊天角色
|
// 获取聊天角色
|
||||||
if (this.chatRoles.length === 0) {
|
if (this.chatRoles.length === 0) {
|
||||||
httpGet("/api/config/chat-roles/get").then((res) => {
|
httpGet("/api/chat-roles/list").then((res) => {
|
||||||
// ElMessage.success('创建会话成功!');
|
// ElMessage.success('创建会话成功!');
|
||||||
this.chatRoles = res.data;
|
this.chatRoles = res.data;
|
||||||
this.loading = false
|
this.loading = false
|
||||||
@ -246,6 +255,9 @@ export default defineComponent({
|
|||||||
reader.readAsText(event.data, "UTF-8");
|
reader.readAsText(event.data, "UTF-8");
|
||||||
reader.onload = () => {
|
reader.onload = () => {
|
||||||
const data = JSON.parse(String(reader.result));
|
const data = JSON.parse(String(reader.result));
|
||||||
|
if (data['is_hello_msg'] && this.hasHelloMsg[this.role]) { // 一定发送过打招呼信息的
|
||||||
|
return
|
||||||
|
}
|
||||||
if (data.type === 'start') {
|
if (data.type === 'start') {
|
||||||
this.chatData.push({
|
this.chatData.push({
|
||||||
type: "reply",
|
type: "reply",
|
||||||
@ -260,6 +272,8 @@ export default defineComponent({
|
|||||||
this.sending = false;
|
this.sending = false;
|
||||||
if (data['is_hello_msg'] !== true) {
|
if (data['is_hello_msg'] !== true) {
|
||||||
this.showReGenerate = true;
|
this.showReGenerate = true;
|
||||||
|
} else {
|
||||||
|
this.hasHelloMsg[this.role] = true
|
||||||
}
|
}
|
||||||
this.showStopGenerate = false;
|
this.showStopGenerate = false;
|
||||||
this.lineBuffer = ''; // 清空缓冲
|
this.lineBuffer = ''; // 清空缓冲
|
||||||
@ -331,6 +345,9 @@ export default defineComponent({
|
|||||||
this.loading = true
|
this.loading = true
|
||||||
// 清空对话列表
|
// 清空对话列表
|
||||||
this.chatData = [];
|
this.chatData = [];
|
||||||
|
this.hasHelloMsg = {};
|
||||||
|
this.showStopGenerate = false;
|
||||||
|
this.showReGenerate = false;
|
||||||
this.connect();
|
this.connect();
|
||||||
for (const key in this.chatRoles) {
|
for (const key in this.chatRoles) {
|
||||||
if (this.chatRoles[key].key === this.role) {
|
if (this.chatRoles[key].key === this.role) {
|
||||||
@ -679,7 +696,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
.tip-text {
|
.tip-text {
|
||||||
text-align left
|
text-align left
|
||||||
padding 0 20px 10px 20px;
|
padding 20px;
|
||||||
|
|
||||||
.el-alert {
|
.el-alert {
|
||||||
padding 5px;
|
padding 5px;
|
||||||
|
@ -149,7 +149,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-row class="row-center">
|
<el-row class="row-center">
|
||||||
<el-image src="https://img.r9it.com/chatgpt/wechat-group.jpeg" fit="cover"/>
|
<el-image :src="sysConfig['wechat_group']" fit="cover" style="width: 250px;"/>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
@ -223,6 +223,9 @@ export default defineComponent({
|
|||||||
curChat: null, // 当前会话
|
curChat: null, // 当前会话
|
||||||
curPrompt: null, // 当前用户输入
|
curPrompt: null, // 当前用户输入
|
||||||
|
|
||||||
|
sysConfig: {}, // 系统配置
|
||||||
|
hasHelloMsg: {}, // 是否发送过打招呼信息
|
||||||
|
|
||||||
showStopGenerate: false,
|
showStopGenerate: false,
|
||||||
showReGenerate: false,
|
showReGenerate: false,
|
||||||
canReGenerate: false, // 是否可以重新生
|
canReGenerate: false, // 是否可以重新生
|
||||||
@ -280,6 +283,13 @@ export default defineComponent({
|
|||||||
this.chatList = chatList;
|
this.chatList = chatList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取系统配置
|
||||||
|
httpGet('/api/config/get').then((res) => {
|
||||||
|
this.sysConfig = res.data;
|
||||||
|
}).catch(() => {
|
||||||
|
ElMessage.error('获取系统配置失败')
|
||||||
|
})
|
||||||
|
|
||||||
// 创建新会话
|
// 创建新会话
|
||||||
this.newChat();
|
this.newChat();
|
||||||
},
|
},
|
||||||
@ -310,8 +320,10 @@ export default defineComponent({
|
|||||||
|
|
||||||
// 获取历史记录
|
// 获取历史记录
|
||||||
this.fetchChatHistory(this.curChat.id);
|
this.fetchChatHistory(this.curChat.id);
|
||||||
if (this.chatData.length === 0) { // 显示打招呼信息
|
// 显示打招呼信息
|
||||||
|
if (!this.hasHelloMsg[this.curChat.id] && this.chatData.length === 0) {
|
||||||
this.chatData.push(this.helloMsg);
|
this.chatData.push(this.helloMsg);
|
||||||
|
this.hasHelloMsg[this.curChat.id] = true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -666,6 +678,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
this.appendChat();
|
this.appendChat();
|
||||||
this.chatData = [];
|
this.chatData = [];
|
||||||
|
this.hasHelloMsg = {};
|
||||||
this.curChat = chat;
|
this.curChat = chat;
|
||||||
this.showStopGenerate = false;
|
this.showStopGenerate = false;
|
||||||
this.showReGenerate = false;
|
this.showReGenerate = false;
|
||||||
|
@ -163,7 +163,7 @@
|
|||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-row class="row-center">
|
<el-row class="row-center">
|
||||||
<el-image src="images/wx.png" fit="cover"/>
|
<el-image :src="sysConfig.wechat_card" fit="cover" style="width: 250px;"/>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
@ -222,7 +222,8 @@ export default defineComponent({
|
|||||||
allChatRoles: [], // 所有角色集合
|
allChatRoles: [], // 所有角色集合
|
||||||
role: 'gpt',
|
role: 'gpt',
|
||||||
inputValue: '', // 聊天内容
|
inputValue: '', // 聊天内容
|
||||||
sendHelloMsg: {}, // 是否发送过打招呼信息
|
hasHelloMsg: {}, // 是否发送过打招呼信息
|
||||||
|
sysConfig: {}, // 系统配置
|
||||||
|
|
||||||
showConfigDialog: false, // 显示配置对话框
|
showConfigDialog: false, // 显示配置对话框
|
||||||
userInfo: {},
|
userInfo: {},
|
||||||
@ -272,6 +273,13 @@ export default defineComponent({
|
|||||||
this.resizeElement();
|
this.resizeElement();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 获取系统配置
|
||||||
|
httpGet('/api/config/get').then((res) => {
|
||||||
|
this.sysConfig = res.data;
|
||||||
|
}).catch(() => {
|
||||||
|
ElMessage.error('获取系统配置失败')
|
||||||
|
})
|
||||||
|
|
||||||
this.connect();
|
this.connect();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -327,7 +335,7 @@ export default defineComponent({
|
|||||||
reader.readAsText(event.data, "UTF-8");
|
reader.readAsText(event.data, "UTF-8");
|
||||||
reader.onload = () => {
|
reader.onload = () => {
|
||||||
const data = JSON.parse(String(reader.result));
|
const data = JSON.parse(String(reader.result));
|
||||||
if (data['is_hello_msg'] && this.sendHelloMsg[this.role]) { // 一定发送过打招呼信息的
|
if (data['is_hello_msg'] && this.hasHelloMsg[this.role]) { // 一定发送过打招呼信息的
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +354,7 @@ export default defineComponent({
|
|||||||
if (data['is_hello_msg'] !== true) {
|
if (data['is_hello_msg'] !== true) {
|
||||||
this.showReGenerate = true;
|
this.showReGenerate = true;
|
||||||
} else {
|
} else {
|
||||||
this.sendHelloMsg[this.role] = true
|
this.hasHelloMsg[this.role] = true
|
||||||
}
|
}
|
||||||
this.showStopGenerate = false;
|
this.showStopGenerate = false;
|
||||||
this.lineBuffer = ''; // 清空缓冲
|
this.lineBuffer = ''; // 清空缓冲
|
||||||
@ -427,6 +435,7 @@ export default defineComponent({
|
|||||||
this.replyIcon = item.icon;
|
this.replyIcon = item.icon;
|
||||||
// 清空对话列表
|
// 清空对话列表
|
||||||
this.chatData = [];
|
this.chatData = [];
|
||||||
|
this.hasHelloMsg = {};
|
||||||
this.showStopGenerate = false;
|
this.showStopGenerate = false;
|
||||||
this.showReGenerate = false;
|
this.showReGenerate = false;
|
||||||
this.connect();
|
this.connect();
|
||||||
|
@ -139,7 +139,7 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
// 获取系统配置
|
// 获取系统配置
|
||||||
httpGet('/api/config/get').then((res) => {
|
httpGet('/api/admin/config/get').then((res) => {
|
||||||
this.form = res.data;
|
this.form = res.data;
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
ElMessage.error('获取系统配置失败')
|
ElMessage.error('获取系统配置失败')
|
||||||
|
Loading…
Reference in New Issue
Block a user