mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-12 04:03:42 +08:00
添加微信和知识星球的推广二维码
This commit is contained in:
@@ -13,5 +13,6 @@
|
|||||||
* [x] markdown 语法解析和代码高亮
|
* [x] markdown 语法解析和代码高亮
|
||||||
* [ ] 用户配置界面,配置用户的使用习惯,可以让用户配置自己的 API KEY,调用自己的 API Key,将不记 Token 的使用次数
|
* [ ] 用户配置界面,配置用户的使用习惯,可以让用户配置自己的 API KEY,调用自己的 API Key,将不记 Token 的使用次数
|
||||||
* [ ] 嵌入 AI 绘画功能,支持根据描述词生成图片
|
* [ ] 嵌入 AI 绘画功能,支持根据描述词生成图片
|
||||||
|
* [x] 点卡用完之后,提示加入知识星球
|
||||||
* [ ] 增加 Buffer 层,将相同的问题答案缓存起来,相同问题直接返回答案。
|
* [ ] 增加 Buffer 层,将相同的问题答案缓存起来,相同问题直接返回答案。
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ErrorMsg = "抱歉,AI 助手开小差了,我马上找人去盘它。"
|
const ErrorMsg = "抱歉,AI 助手开小差了,请马上联系管理员去盘它。"
|
||||||
|
|
||||||
// ChatHandle 处理聊天 WebSocket 请求
|
// ChatHandle 处理聊天 WebSocket 请求
|
||||||
func (s *Server) ChatHandle(c *gin.Context) {
|
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 {
|
if user.MaxCalls > 0 && user.RemainingCalls <= 0 {
|
||||||
replyMessage(ws, "当前 user 点数已经用尽,请充值后再使用或者联系管理员!", false)
|
replyMessage(ws, "当前 TOKEN 点数已经用尽,加入我们的知识星球可以免费领取点卡!", false)
|
||||||
|
replyMessage(ws, "", true)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var r = types.ApiRequest{
|
var r = types.ApiRequest{
|
||||||
@@ -148,6 +149,7 @@ func (s *Server) sendMessage(session types.ChatSession, role types.ChatRole, pro
|
|||||||
// 如果三次请求都失败的话,则返回对应的错误信息
|
// 如果三次请求都失败的话,则返回对应的错误信息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
replyMessage(ws, ErrorMsg, false)
|
replyMessage(ws, ErrorMsg, false)
|
||||||
|
replyMessage(ws, "", true)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ func (s *Server) ConfigSetHandle(c *gin.Context) {
|
|||||||
s.Config.Chat.Model = model
|
s.Config.Chat.Model = model
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if accessKey, ok := data["access_key"]; ok {
|
||||||
|
s.Config.AccessKey = accessKey
|
||||||
|
}
|
||||||
|
|
||||||
// Temperature
|
// Temperature
|
||||||
if temperature, ok := data["temperature"]; ok {
|
if temperature, ok := data["temperature"]; ok {
|
||||||
v, err := strconv.ParseFloat(temperature, 32)
|
v, err := strconv.ParseFloat(temperature, 32)
|
||||||
@@ -150,6 +154,7 @@ func (s *Server) BatchAddUserHandle(c *gin.Context) {
|
|||||||
var data struct {
|
var data struct {
|
||||||
Number int `json:"number"`
|
Number int `json:"number"`
|
||||||
MaxCalls int `json:"max_calls"`
|
MaxCalls int `json:"max_calls"`
|
||||||
|
EnableHistory bool `json:"enable_history"`
|
||||||
}
|
}
|
||||||
err := json.NewDecoder(c.Request.Body).Decode(&data)
|
err := json.NewDecoder(c.Request.Body).Decode(&data)
|
||||||
if err != nil || data.MaxCalls <= 0 {
|
if err != nil || data.MaxCalls <= 0 {
|
||||||
@@ -164,7 +169,7 @@ func (s *Server) BatchAddUserHandle(c *gin.Context) {
|
|||||||
for err == nil {
|
for err == nil {
|
||||||
name = utils.RandString(12)
|
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 {
|
if err == nil {
|
||||||
users = append(users, name)
|
users = append(users, name)
|
||||||
}
|
}
|
||||||
@@ -226,6 +231,11 @@ func (s *Server) RemoveUserHandle(c *gin.Context) {
|
|||||||
return
|
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()})
|
c.JSON(http.StatusOK, types.BizVo{Code: types.Success, Message: types.OkMsg, Data: GetUsers()})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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/add", s.AddUserHandle)
|
||||||
engine.POST("api/config/user/batch-add", s.BatchAddUserHandle)
|
engine.POST("api/config/user/batch-add", s.BatchAddUserHandle)
|
||||||
engine.POST("api/config/user/set", s.SetUserHandle)
|
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/user/remove", s.RemoveUserHandle)
|
||||||
engine.POST("api/config/apikey/add", s.AddApiKeyHandle)
|
engine.POST("api/config/apikey/add", s.AddApiKeyHandle)
|
||||||
engine.POST("api/config/apikey/remove", s.RemoveApiKeyHandle)
|
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-Origin", origin)
|
||||||
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
|
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")
|
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") {
|
if strings.HasPrefix(c.Request.URL.Path, "/api/config") {
|
||||||
accessKey := c.GetHeader("ACCESS_KEY")
|
accessKey := c.GetHeader("ACCESS_KEY")
|
||||||
if accessKey != s.Config.AccessKey {
|
if accessKey != strings.TrimSpace(s.Config.AccessKey) {
|
||||||
c.Abort()
|
c.Abort()
|
||||||
c.JSON(http.StatusOK, types.BizVo{Code: types.NotAuthorized, Message: "No Permissions"})
|
c.JSON(http.StatusOK, types.BizVo{Code: types.NotAuthorized, Message: "No Permissions"})
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
BIN
web/public/images/start.png
Normal file
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
BIN
web/public/images/wx.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
@@ -14,7 +14,7 @@ Global['Chat'] = Chat
|
|||||||
const routes = [
|
const routes = [
|
||||||
{
|
{
|
||||||
name: 'home', path: '/', component: Chat, meta: {
|
name: 'home', path: '/', component: Chat, meta: {
|
||||||
title: 'WeChat-GPT'
|
title: 'ChatGPT-Plus'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,6 +20,12 @@
|
|||||||
<Delete/>
|
<Delete/>
|
||||||
</el-icon>
|
</el-icon>
|
||||||
</el-button>
|
</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>
|
||||||
|
|
||||||
<div class="chat-box" id="chat-box" :style="{height: chatBoxHeight+'px'}">
|
<div class="chat-box" id="chat-box" :style="{height: chatBoxHeight+'px'}">
|
||||||
@@ -52,11 +58,6 @@
|
|||||||
<div class="btn-container">
|
<div class="btn-container">
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-button type="success" class="send" :disabled="sending" v-on:click="sendMessage">发送</el-button>
|
<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>
|
</el-row>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -84,6 +85,14 @@
|
|||||||
<el-button type="primary" @click="submitToken">提交</el-button>
|
<el-button type="primary" @click="submitToken">提交</el-button>
|
||||||
</el-row>
|
</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>
|
</el-dialog>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -191,7 +200,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
window.addEventListener("resize", () => {
|
window.addEventListener("resize", () => {
|
||||||
this.chatBoxHeight = window.innerHeight - this.toolBoxHeight;
|
this.chatBoxHeight = window.innerHeight - this.toolBoxHeight;
|
||||||
this.inputBoxWidth = window.innerWidth - 20;
|
// this.inputBoxWidth = window.innerWidth - 20;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.connect();
|
this.connect();
|
||||||
@@ -314,6 +323,10 @@ export default defineComponent({
|
|||||||
// 从后端获取聊天历史记录
|
// 从后端获取聊天历史记录
|
||||||
fetchChatHistory: function () {
|
fetchChatHistory: function () {
|
||||||
httpPost("/api/chat/history", {role: this.role}).then((res) => {
|
httpPost("/api/chat/history", {role: this.role}).then((res) => {
|
||||||
|
if (this.chatData.length > 0) { // 如果已经有聊天记录了,就不追加了
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const data = res.data
|
const data = res.data
|
||||||
const md = require('markdown-it')();
|
const md = require('markdown-it')();
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
@@ -477,7 +490,7 @@ export default defineComponent({
|
|||||||
margin-right 5px;
|
margin-right 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.clear-history {
|
.clear-history, .config {
|
||||||
margin-left 5px;
|
margin-left 5px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -491,7 +504,7 @@ export default defineComponent({
|
|||||||
padding: 0 10px 10px 10px;
|
padding: 0 10px 10px 10px;
|
||||||
|
|
||||||
.chat-line {
|
.chat-line {
|
||||||
padding 10px;
|
padding 10px 5px;
|
||||||
font-size 14px;
|
font-size 14px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
@@ -542,7 +555,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
.el-row {
|
.el-row {
|
||||||
flex-wrap nowrap
|
flex-wrap nowrap
|
||||||
width 106px;
|
//width 106px;
|
||||||
align-items center
|
align-items center
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -564,6 +577,10 @@ export default defineComponent({
|
|||||||
width: 0;
|
width: 0;
|
||||||
height: 0;
|
height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.row-center {
|
||||||
|
justify-content center
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user