diff --git a/README.md b/README.md index 355279cc..9a868e86 100644 --- a/README.md +++ b/README.md @@ -13,5 +13,6 @@ * [x] markdown 语法解析和代码高亮 * [ ] 用户配置界面,配置用户的使用习惯,可以让用户配置自己的 API KEY,调用自己的 API Key,将不记 Token 的使用次数 * [ ] 嵌入 AI 绘画功能,支持根据描述词生成图片 +* [x] 点卡用完之后,提示加入知识星球 * [ ] 增加 Buffer 层,将相同的问题答案缓存起来,相同问题直接返回答案。 diff --git a/server/chat_handler.go b/server/chat_handler.go index 4a43eba4..3d0bb061 100644 --- a/server/chat_handler.go +++ b/server/chat_handler.go @@ -17,7 +17,7 @@ import ( "time" ) -const ErrorMsg = "抱歉,AI 助手开小差了,我马上找人去盘它。" +const ErrorMsg = "抱歉,AI 助手开小差了,请马上联系管理员去盘它。" // ChatHandle 处理聊天 WebSocket 请求 func (s *Server) ChatHandle(c *gin.Context) { @@ -70,7 +70,8 @@ func (s *Server) sendMessage(session types.ChatSession, role types.ChatRole, pro } if user.MaxCalls > 0 && user.RemainingCalls <= 0 { - replyMessage(ws, "当前 user 点数已经用尽,请充值后再使用或者联系管理员!", false) + replyMessage(ws, "当前 TOKEN 点数已经用尽,加入我们的知识星球可以免费领取点卡!", false) + replyMessage(ws, "![](images/start.png)", true) return nil } var r = types.ApiRequest{ @@ -148,6 +149,7 @@ func (s *Server) sendMessage(session types.ChatSession, role types.ChatRole, pro // 如果三次请求都失败的话,则返回对应的错误信息 if err != nil { replyMessage(ws, ErrorMsg, false) + replyMessage(ws, "![](images/wx.png)", true) return err } diff --git a/server/config_handler.go b/server/config_handler.go index 11c62b45..f90efcfa 100644 --- a/server/config_handler.go +++ b/server/config_handler.go @@ -24,6 +24,10 @@ func (s *Server) ConfigSetHandle(c *gin.Context) { s.Config.Chat.Model = model } + if accessKey, ok := data["access_key"]; ok { + s.Config.AccessKey = accessKey + } + // Temperature if temperature, ok := data["temperature"]; ok { v, err := strconv.ParseFloat(temperature, 32) @@ -148,8 +152,9 @@ func (s *Server) AddUserHandle(c *gin.Context) { // BatchAddUserHandle 批量生成 Username func (s *Server) BatchAddUserHandle(c *gin.Context) { var data struct { - Number int `json:"number"` - MaxCalls int `json:"max_calls"` + Number int `json:"number"` + MaxCalls int `json:"max_calls"` + EnableHistory bool `json:"enable_history"` } err := json.NewDecoder(c.Request.Body).Decode(&data) if err != nil || data.MaxCalls <= 0 { @@ -164,7 +169,7 @@ func (s *Server) BatchAddUserHandle(c *gin.Context) { for err == nil { name = utils.RandString(12) } - err = PutUser(types.User{Name: name, MaxCalls: data.MaxCalls, RemainingCalls: data.MaxCalls}) + err = PutUser(types.User{Name: name, MaxCalls: data.MaxCalls, RemainingCalls: data.MaxCalls, EnableHistory: data.EnableHistory}) if err == nil { users = append(users, name) } @@ -226,6 +231,11 @@ func (s *Server) RemoveUserHandle(c *gin.Context) { return } + c.JSON(http.StatusOK, types.BizVo{Code: types.Success, Message: types.OkMsg}) +} + +// GetUserListHandle 获取用户列表 +func (s *Server) GetUserListHandle(c *gin.Context) { c.JSON(http.StatusOK, types.BizVo{Code: types.Success, Message: types.OkMsg, Data: GetUsers()}) } diff --git a/server/server.go b/server/server.go index cb024524..88a773ee 100644 --- a/server/server.go +++ b/server/server.go @@ -91,6 +91,7 @@ func (s *Server) Run(webRoot embed.FS, path string, debug bool) { engine.POST("api/config/user/add", s.AddUserHandle) engine.POST("api/config/user/batch-add", s.BatchAddUserHandle) engine.POST("api/config/user/set", s.SetUserHandle) + engine.POST("api/config/user/list", s.GetUserListHandle) engine.POST("api/config/user/remove", s.RemoveUserHandle) engine.POST("api/config/apikey/add", s.AddApiKeyHandle) engine.POST("api/config/apikey/remove", s.RemoveApiKeyHandle) @@ -173,7 +174,7 @@ func corsMiddleware() gin.HandlerFunc { c.Header("Access-Control-Allow-Origin", origin) c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") //允许跨域设置可以返回其他子段,可以自定义字段 - c.Header("Access-Control-Allow-Headers", "Authorization, Content-Length, Content-Type, ChatGPT-TOKEN") + c.Header("Access-Control-Allow-Headers", "Authorization, Content-Length, Content-Type, ChatGPT-TOKEN, ACCESS_KEY") // 允许浏览器(客户端)可以解析的头部 (重要) c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers") //设置缓存时间 @@ -209,7 +210,7 @@ func AuthorizeMiddleware(s *Server) gin.HandlerFunc { if strings.HasPrefix(c.Request.URL.Path, "/api/config") { accessKey := c.GetHeader("ACCESS_KEY") - if accessKey != s.Config.AccessKey { + if accessKey != strings.TrimSpace(s.Config.AccessKey) { c.Abort() c.JSON(http.StatusOK, types.BizVo{Code: types.NotAuthorized, Message: "No Permissions"}) } else { diff --git a/web/public/images/start.png b/web/public/images/start.png new file mode 100644 index 00000000..8e3ca234 Binary files /dev/null and b/web/public/images/start.png differ diff --git a/web/public/images/wx.png b/web/public/images/wx.png new file mode 100644 index 00000000..2769591c Binary files /dev/null and b/web/public/images/wx.png differ diff --git a/web/src/main.js b/web/src/main.js index e248bffc..8c2d1879 100644 --- a/web/src/main.js +++ b/web/src/main.js @@ -14,7 +14,7 @@ Global['Chat'] = Chat const routes = [ { name: 'home', path: '/', component: Chat, meta: { - title: 'WeChat-GPT' + title: 'ChatGPT-Plus' } }, { diff --git a/web/src/views/Chat.vue b/web/src/views/Chat.vue index 249b380f..2d35f862 100644 --- a/web/src/views/Chat.vue +++ b/web/src/views/Chat.vue @@ -20,6 +20,12 @@ + + + + + +
@@ -52,11 +58,6 @@
发送 - - - - -
@@ -84,6 +85,14 @@ 提交 + +

打开微信扫下面二维码免费领取口令

+
+ + + + +
@@ -191,7 +200,7 @@ export default defineComponent({ window.addEventListener("resize", () => { this.chatBoxHeight = window.innerHeight - this.toolBoxHeight; - this.inputBoxWidth = window.innerWidth - 20; + // this.inputBoxWidth = window.innerWidth - 20; }); this.connect(); @@ -314,6 +323,10 @@ export default defineComponent({ // 从后端获取聊天历史记录 fetchChatHistory: function () { httpPost("/api/chat/history", {role: this.role}).then((res) => { + if (this.chatData.length > 0) { // 如果已经有聊天记录了,就不追加了 + return + } + const data = res.data const md = require('markdown-it')(); for (let i = 0; i < data.length; i++) { @@ -477,7 +490,7 @@ export default defineComponent({ margin-right 5px; } - .clear-history { + .clear-history, .config { margin-left 5px; } } @@ -491,7 +504,7 @@ export default defineComponent({ padding: 0 10px 10px 10px; .chat-line { - padding 10px; + padding 10px 5px; font-size 14px; display: flex; align-items: flex-start; @@ -542,7 +555,7 @@ export default defineComponent({ .el-row { flex-wrap nowrap - width 106px; + //width 106px; align-items center } @@ -564,6 +577,10 @@ export default defineComponent({ width: 0; height: 0; } + + .row-center { + justify-content center + } } }