添加微信和知识星球的推广二维码

This commit is contained in:
RockYang 2023-03-29 14:27:04 +08:00
parent eb562ea3c9
commit bd41f742d2
8 changed files with 48 additions and 17 deletions

View File

@ -13,5 +13,6 @@
* [x] markdown 语法解析和代码高亮
* [ ] 用户配置界面,配置用户的使用习惯,可以让用户配置自己的 API KEY调用自己的 API Key将不记 Token 的使用次数
* [ ] 嵌入 AI 绘画功能,支持根据描述词生成图片
* [x] 点卡用完之后,提示加入知识星球
* [ ] 增加 Buffer 层,将相同的问题答案缓存起来,相同问题直接返回答案。

View File

@ -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
}

View File

@ -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()})
}

View File

@ -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 {

BIN
web/public/images/start.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
web/public/images/wx.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -14,7 +14,7 @@ Global['Chat'] = Chat
const routes = [
{
name: 'home', path: '/', component: Chat, meta: {
title: 'WeChat-GPT'
title: 'ChatGPT-Plus'
}
},
{

View File

@ -20,6 +20,12 @@
<Delete/>
</el-icon>
</el-button>
<el-button type="info" size="small" class="config" ref="send-btn" circle @click="showConnectDialog = true">
<el-icon>
<Tools/>
</el-icon>
</el-button>
</div>
<div class="chat-box" id="chat-box" :style="{height: chatBoxHeight+'px'}">
@ -52,11 +58,6 @@
<div class="btn-container">
<el-row>
<el-button type="success" class="send" :disabled="sending" v-on:click="sendMessage">发送</el-button>
<el-button type="info" class="config" ref="send-btn" circle @click="showConnectDialog = true">
<el-icon>
<Tools/>
</el-icon>
</el-button>
</el-row>
</div>
@ -84,6 +85,14 @@
<el-button type="primary" @click="submitToken">提交</el-button>
</el-row>
<el-row class="row-center">
<p>打开微信扫下面二维码免费领取口令</p>
</el-row>
<el-row class="row-center">
<el-image src="images/wx.png" fit="cover"/>
</el-row>
</el-dialog>
</div>
</div>
@ -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
}
}
}