Compare commits

...

36 Commits

Author SHA1 Message Date
RockYang
4e65a5b1a1 opt: optimize the layout for regiseter page. add function to disable registration 2023-08-02 17:44:13 +08:00
RockYang
b09d23f97f feat: the dashboard page is ready for admin console 2023-08-02 16:37:47 +08:00
RockYang
3529649ba9 refactor: refactor admin console page layout 2023-08-02 15:00:18 +08:00
RockYang
fdd659f393 fix: fixed bug for chat request's token reach the max token limit for OpenAI 2023-08-01 17:58:03 +08:00
RockYang
9eb8da2789 feat: new function for add user in manger console user list page 2023-08-01 16:02:49 +08:00
RockYang
ffb1ef0470 doc: add video tutorial for deploying system 2023-08-01 10:15:43 +08:00
RockYang
862c6aea43 docs: remove docs for deploy manually 2023-07-31 20:04:22 +08:00
RockYang
54fe4b7588 opt: optimize the build script and docker-compose yaml file 2023-07-31 17:31:02 +08:00
RockYang
c6062ee70e feat: add env var to set log level 2023-07-31 08:34:11 +08:00
RockYang
bed184dc1f feat: update system config cache for AppServer when updating system config in admin console 2023-07-31 08:13:20 +08:00
RockYang
29094ba3b3 add system config cache for AppServer object 2023-07-31 06:56:28 +08:00
RockYang
a18188876c feat: allow user to login with username and mobile no 2023-07-27 15:37:50 +08:00
RockYang
4faee3e48e fix: deauthorize some apis 2023-07-27 10:53:14 +08:00
RockYang
1a6afcd266 fix: fix bug for mobile verify code function not available in register page 2023-07-27 10:29:59 +08:00
RockYang
f567831d92 style: adjust reward image styles 2023-07-26 17:57:19 +08:00
RockYang
cf36ca4285 chore: optimize build script, compress reward img 2023-07-26 17:48:16 +08:00
RockYang
0e4ae01498 feat: add reset password function to user list page 2023-07-26 15:22:11 +08:00
RockYang
7b90f8cb13 docs: add change log file 2023-07-25 17:37:20 +08:00
RockYang
c33215529a docs: 更新文档和数据库文件 2023-07-25 17:25:23 +08:00
RockYang
c5be114db2 feat: 完成人机交互验证 API 接入,增加短信防刷验证 2023-07-25 17:00:24 +08:00
RockYang
cab955c292 feat: 头条,微博热搜等函数 API 实现 2023-07-25 15:02:43 +08:00
RockYang
ca8c8e6490 opt: 取消强制手机号验证,更新配置 2023-07-24 18:18:09 +08:00
RockYang
253951b4b3 feat: 完成众筹后台管理功能 2023-07-24 15:59:29 +08:00
RockYang
4d6444ebf3 chore: add error log for reading chat response buffer 2023-07-24 12:05:38 +08:00
RockYang
94d8d8a9d4 opt: record user_id for reward verify 2023-07-22 08:42:30 +08:00
RockYang
e02badf7bb feat: reward verify is ready 2023-07-21 22:29:14 +08:00
RockYang
dd88622c64 feat: 增加打赏核销功能 2023-07-21 18:26:51 +08:00
RockYang
c4d7126c4d feat: 集成微信收款服务 2023-07-20 17:46:32 +08:00
RockYang
86bc063941 put logs in log file 2023-07-20 16:36:12 +08:00
RockYang
dce85eb519 fix: 修复阿里云短信发送失败的 bug 2023-07-16 16:05:11 +08:00
RockYang
4ab879d697 fix: 用户使用自己绑定的 API 调用,则不计算 calls 和 token 消耗 2023-07-16 11:55:45 +08:00
RockYang
681e52df50 Merge branch 'main' into prod 2023-07-16 09:57:27 +08:00
RockYang
fb554c0315 chore: 更新项目打包脚本 2023-07-16 09:55:00 +08:00
RockYang
accf8eeb77 feat: plugin function is ready 2023-07-15 21:52:30 +08:00
RockYang
3e41edd3b5 feat: 支持上下文深度配置,计算每轮对话消耗的总 token 数量 2023-07-15 18:37:25 +08:00
RockYang
9126cfff20 refactor: 更改 OpenAI 请求 Body 数据结构,兼容函数调用请求 2023-07-15 18:00:40 +08:00
82 changed files with 3179 additions and 1722 deletions

68
CHANGELOG.md Normal file
View File

@@ -0,0 +1,68 @@
# 更新日志
## v3.0.6
1. 管理后台:新增用户名和手机号码搜索功能
2. 管理后台:新增重置用户密码功能
3. 管理后台:支持关闭注册功能,新增添加用户功能,适用于内部使用场景
4. 管理后台:新增仪表盘页面,统计当天的新增用户,新增会话数据,以及 Token 消耗
5. Bug修复修复注册页面验证码不显示 Bug
6. Bug修复优化上下文 Token 计算算法,修复聊天上下文超出限制时循环发送消息的 Bug
7. 功能修正:允许用户使用手机号码登录
8. 功能优化:更新系统配置后同步更新服务端内存变量数据
9. 功能优化:优化打包脚本,减少容器镜像大小
## v3.0.5
重磅功能更新!!! 新增函数插件支持可以轻松地接入你的第三方插件服务ChatGPT 自动帮您调用对应的函数完成任务。
1. 新增函数功能支持,全球早报,今日头条和微博热搜等插件服务,您也可以接入自己的第三方服务。
2. 集成微信机器人模块,可以通过微信个人收款码来完成充值,无需接入微信支付功能也可以完成收款功能。
3. 用户注册添加短信验证码功能,引入交互安全认证服务,有效防刷短信。
4. 支持配置聊天上下文深度,精确统计每轮对话所消耗的总 TOKEN 数量。
5. 修复已知的 Bug。
## v3.0.4
1. 调整项目目录结构,移除其他语言 API 目录
2. 修复 nodejs apple M1 跨平台打包,运行报错 exec format error
3. 增加用户 token 消耗统计功能
## v3.0.3
1. 优化启动参数接收处理,支持环境变量传参
2. 修复 PC 端聊天界面出现滚动条的 Bug
3. 修正前端 user_init_call 字段错误和用户注册初始化头像路径问题
4. 更改 docker 构建镜像的基础镜像,改用作者的阿里云镜像,这样打包更快一些。
## v3.0.2
1. Feat新增移动端的聊天和用户设置功能
2. Fix: 修复 markdown 换行符解析的 Bug
3. Feat: 新增头像上传功能
4. Docs: 增加容器部署支持,支持 docker-compose 一键部署
5. Fix: 增加全局错误处理 handler修复业务处理异常导致服务退出的 Bug
## v3.0.1
1. 紧急修复前端 Home 组件路由被后台管理 Home 组件路由覆盖的 Bug。
2. 增加 docker-compose 部署脚本
## v3.0.0
全新的重构版本!!!
新版的系统前后端都进行大改动的重构,后端还是用的 Gin Web 框架,但是作者整合了 fx 自动注入框架,整个后端应用结构非常简洁,特别适合二次开发。
另外,数据存储用 MySQL 替换了 leveldb, 因为要对 C 端后期会涉及到很多业务数据查询统计leveldb 已经完全不够用了。
前后台技术架构还是基于 `Vue3 + Element-Plus` ,但是页面风格已经全部变了,几乎所有页面样式代码都重写了,希望会你是希望的风格!
此次重构改版主要是为了后面功能的扩展准备了。
新版本已经实现的功能如下:
1. 引入用户体系,新增用户注册和登录功能。
2. 聊天页面改版,实现了跟 ChatGPT 官方版本一致的聊天体验。
3. 创建会话的时候可以选择聊天角色和模型。
4. 新增聊天设置功能,用户可以导入自己的 API KEY
5. 保存聊天记录,支持聊天上下文。
6. 重构后台管理模块,更友好,扩展性更好的后台管理系统。
7. 引入 ip2region 组件记录用户的登录IP和地址。
8. 支持会话搜索过滤。

139
README.md
View File

@@ -8,29 +8,33 @@
## 功能截图
### 1.PC 端聊天界面
### PC 端聊天界面
![ChatGPT Chat Page](docs/imgs/gpt.gif)
### 2. 新版聊天界面
### 新版聊天界面
![ChatGPT new Chat Page](docs/imgs/chat-new.png)
### 3. 用户设置
### 自动调用函数插件
![ChatGPT function plugin](docs/imgs/plugin.png)
### 用户设置
![ChatGPT user profle](docs/imgs/user_profile.png)
### 4. 登录页面
### 登录页面
![ChatGPT Login](docs/imgs/login.png)
### 5. 管理后台
### 管理后台
![ChatGPT admin](docs/imgs/admin_config.png)
![ChatGPT admin](docs/imgs/admin_user.png)
### 6. 移动端 Web 页面
### 移动端 Web 页面
![Mobile chat list](/docs/imgs/mobile_chat_list.png)
![Mobile chat session](/docs/imgs/mobile_chat_session.png)
@@ -78,6 +82,7 @@ ChatGPT 的服务。
6. 重构后台管理模块,更友好,扩展性更好的后台管理系统。
7. 引入 ip2region 组件记录用户的登录IP和地址。
8. 支持会话搜索过滤。
9. 支持微信支付充值
## 项目地址
@@ -88,12 +93,16 @@ ChatGPT 的服务。
* [ ] 整合 Midjourney AI 绘画 API
* [ ] 开发移动端聊天页面
* [ ] 接入微信支付功能
* [x] 接入微信支付功能
* [x] 支持 ChatGPT 函数功能,通过函数实现插件
* [ ] 接入语音和 TTS API支持语音聊天
* [ ] 开发手机 App 客户端
## Docker 快速部署
> 鉴于最新不少网友反馈在部署的时候遇到一些问题,大部分问题都是相同的,所以我这边做了一个视频教程 [五分钟部署自己的 ChatGPT 服务](https://www.bilibili.com/video/BV1H14y1B7Qw/)。
> 习惯看视频教程的朋友可以去看视频教程,视频的语速比较慢,建议 2 倍速观看。
V3.0.0 版本以后已经支持使用容器部署了,跳过所有的繁琐的环境准备,一条命令就可以轻松部署上线。
### 1. 导入数据库
@@ -126,6 +135,9 @@ Listen = "0.0.0.0:5678"
ProxyURL = ["YOUR_PROXY_URL"] # 替换成你本地代理http://127.0.0.1:7777
#ProxyURL = "" 如果你的服务器本身就在墙外,那么你直接留空就好了
MysqlDns = "root:12345678@tcp(172.22.11.200:3307)/chatgpt_plus?charset=utf8&parseTime=True&loc=Local"
StartWechatBot = false # 是否启动微信机器人,默认关闭,如果设置为 TRUE 则启动服务的时候需要微信扫码登录
EnabledMsgService = false # 注册时是否开启短信验证功能,该功能需要配合短信服务一起使用
[Session]
SecretKey = "azyehq3ivunjhbntz78isj00i4hz2mt9xtddysfucxakadq4qbfrt0b7q3lnvg80"
Name = "CHAT_SESSION_ID"
@@ -139,6 +151,18 @@ MysqlDns = "root:12345678@tcp(172.22.11.200:3307)/chatgpt_plus?charset=utf8&pars
[Manager]
Username = "admin"
Password = "admin123" # 如果是生产环境的话,这里管理员的密码记得修改
[ApiConfig] # 插件 API 服务配置,此为第三方插件服务,如需使用请联系作者开通
ApiURL = "{URL}"
AppId = "{APP_ID}"
Token = "{TOKEN}"
[SmsConfig] # 阿里云短信服务配置
AccessKey = "{YOUR_ACCESS_KEY}"
AccessSecret = "{YOUR_SECRET_KEY}"
Product = "Dysmsapi"
Domain = "dysmsapi.aliyuncs.com"
```
修改 nginx 配置文档 `docker/conf/nginx/conf.d/chatgpt-plus.conf`,把后端转发的地址改成当前主机的内网 IP 地址。
@@ -174,104 +198,9 @@ docker-compose up -d
> 输入你前面配置文档中设置的管理员用户名和密码登录。
> 然后进入 `API KEY 管理` 菜单,添加一个 OpenAI 的 API KEY 才可以正常开启 AI 对话。
## 手动安装部署
由于本项目采用的是前后端分离的开发方式,所以部署也需要前后端分开部署。我这里以 linux 系统为例,演示一下部署过程:
### 1. 导入数据库
请参考容器部署的[导入数据](#1-导入数据库)。
### 2. 修改配置文档
先拷贝项目中的 `api/config.sample.toml` 配置文档,修改代理地址和管理员密码:
如何修改请参考[修改配置文档](#2-修改配置文档)
### 3. 运行后端程序
你可以自己编译或者直接下载我打包好的后端程序运行。
```shell
# 1. 下载程序,你也可以自己编译
wget https://github.com/yangjian102621/chatgpt-plus/releases/download/v3.0.0/chatgpt-v3-amd64-linux
# 2. 添加执行权限
chmod +x chatgpt-v3-amd64-linux
# 3. 运行程序,如果配置文档不在当前目录,注意指定配置文档
./chatgpt-v3-amd64-linux
```
### 4. 前端部署
前端是 Vue 项目编译好静态资源文件,同样你也可以直接下载我编译好的文件解压。
```shell
# 1. 下载程序
wget https://github.com/yangjian102621/chatgpt-plus/releases/download/v3.0.0/dist.tar.gz
# 2. 解压
tar -xf dist.tar.gz
```
### 5. 配置 Nginx 服务
前端程序需要搭载 Web 服务器才可以运行,这里我们选择 Nginx先安装
```shell
sudo apt install nginx -y
```
建立 Nginx 配置文件:
```conf
server {
listen 443 ssl;
server_name www.chatgpt.com; #替换成你自己的域名
ssl_certificate xxx.pem; # 替换成自己的 SSL 证书
ssl_certificate_key xxx.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
# 日志地址
access_log /var/log/chatgpt/access.log;
error_log /var/log/chatgpt/error.log;
index index.html;
root /var/www/chatgpt/dist; # 这里改成前端静态页面的地址
location / {
try_files $uri $uri/ /index.html;
# 后端 API 的转发
location /api/ {
proxy_http_version 1.1;
proxy_connect_timeout 300s;
proxy_read_timeout 300s;
proxy_send_timeout 12s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_pass http://172.28.173.76:6789; # 这里改成后端服务的内网 IP 地址
}
# 静态资源转发
location /static/ {
proxy_pass http://172.28.173.76:6789; # 这里改成后端服务的内网 IP 地址
}
}
}
```
配置好之后重启 Nginx然后 []
![add API Key](docs/imgs/apikey_add.png)
最后登录前端聊天页面 [http://www.chatgpt.com/admin](http://www.chatgpt.com/admin)
最后登录前端聊天页面 [http://localhost:8080/chat](http://localhost:8080/chat)
你可以注册新用户,也可以使用系统默认有个账号:`geekmaster/12345678` 登录聊天。
祝你使用愉快!!!
@@ -342,9 +271,9 @@ npm run build
```shell
cd api
# for all platforms
make all
make clean all
# for linux only
make linux
make clean linux
```
打包后的可执行文件在 `bin` 目录下。

3
api/.gitignore vendored
View File

@@ -16,4 +16,5 @@ tmp
bin
data
config.toml
static/upload
static/upload
storage.json

View File

@@ -1,12 +1,18 @@
Listen = "0.0.0.0:5678"
ProxyURL = "YOUR_PROXY_URL"
MysqlDns = "mysql_user:mysql_pass@tcp(localhost:3306)/chatgpt_plus?charset=utf8&parseTime=True&loc=Local"
ProxyURL = "http://172.22.11.200:7777"
MysqlDns = "root:mysql_pass@tcp(localhost:3306)/chatgpt_plus?charset=utf8mb4&collation=utf8mb4_unicode_ci&parseTime=True&loc=Local"
StaticDir = "./static"
StaticUrl = "http://localhost:5678/static"
AesEncryptKey = "{YOUR_AES_KEY}"
StartWechatBot = false
EnabledMsgService = false
[Session]
SecretKey = "azyehq3ivunjhbntz78isj00i4hz2mt9xtddysfucxakadq4qbfrt0b7q3lnvg80"
Driver = "cookie"
SecretKey = "m0cjm3gsuw9jk73np1ni7r42koilybjcndlycjdmq7za3pbqn7w12fyok5pqh6q5"
Name = "CHAT_SESSION_ID"
Path = "/"
Domain = ""
Domain = "localhost"
MaxAge = 86400
Secure = false
HttpOnly = false
@@ -14,4 +20,22 @@ MysqlDns = "mysql_user:mysql_pass@tcp(localhost:3306)/chatgpt_plus?charset=utf8&
[Manager]
Username = "admin"
Password = "admin123"
Password = "admin123"
[Redis]
Host = "localhost"
Port = 6379
Password = ""
[ApiConfig]
ApiURL = "{URL}"
AppId = "{APP_ID}"
Token = "{TOKEN}"
[SmsConfig]
AccessKey = "{YOUR_ACCESS_KEY}"
AccessSecret = "{YOUR_SECRET_KEY}"
Product = "Dysmsapi"
Domain = "dysmsapi.aliyuncs.com"

View File

@@ -2,6 +2,7 @@ package core
import (
"chatplus/core/types"
"chatplus/service/function"
"chatplus/store/model"
"chatplus/utils"
"chatplus/utils/resp"
@@ -22,27 +23,39 @@ type AppServer struct {
Debug bool
Config *types.AppConfig
Engine *gin.Engine
ChatContexts *types.LMap[string, []types.Message] // 聊天上下文 Map [chatId] => []Message
ChatConfig *types.ChatConfig // 聊天配置
ChatContexts *types.LMap[string, []interface{}] // 聊天上下文 Map [chatId] => []Message
ChatConfig *types.ChatConfig // chat config cache
SysConfig *types.SystemConfig // system config cache
// 保存 Websocket 会话 UserId, 每个 UserId 只能连接一次
// 防止第三方直接连接 socket 调用 OpenAI API
ChatSession *types.LMap[string, types.ChatSession] //map[sessionId]UserId
ChatClients *types.LMap[string, *types.WsClient] // map[sessionId]Websocket 连接集合
ReqCancelFunc *types.LMap[string, context.CancelFunc] // HttpClient 请求取消 handle function
Functions map[string]function.Function
}
func NewServer(appConfig *types.AppConfig) *AppServer {
func NewServer(
appConfig *types.AppConfig,
funZaoBao function.FuncZaoBao,
funZhiHu function.FuncHeadlines,
funWeibo function.FuncWeiboHot) *AppServer {
gin.SetMode(gin.ReleaseMode)
gin.DefaultWriter = io.Discard
return &AppServer{
Debug: false,
Config: appConfig,
Engine: gin.Default(),
ChatContexts: types.NewLMap[string, []types.Message](),
ChatContexts: types.NewLMap[string, []interface{}](),
ChatSession: types.NewLMap[string, types.ChatSession](),
ChatClients: types.NewLMap[string, *types.WsClient](),
ReqCancelFunc: types.NewLMap[string, context.CancelFunc](),
Functions: map[string]function.Function{
types.FuncZaoBao: funZaoBao,
types.FuncWeibo: funWeibo,
types.FuncHeadLine: funZhiHu,
},
}
}
@@ -50,9 +63,8 @@ func (s *AppServer) Init(debug bool) {
if debug { // 调试模式允许跨域请求 API
s.Debug = debug
logger.Info("Enabled debug mode")
s.Engine.Use(corsMiddleware())
}
s.Engine.Use(corsMiddleware())
s.Engine.Use(sessionMiddleware(s.Config))
s.Engine.Use(authorizeMiddleware(s))
s.Engine.Use(errorHandler)
@@ -62,12 +74,22 @@ func (s *AppServer) Init(debug bool) {
func (s *AppServer) Run(db *gorm.DB) error {
// load chat config from database
var config model.Config
res := db.Where("marker", "chat").First(&config)
var chatConfig model.Config
res := db.Where("marker", "chat").First(&chatConfig)
if res.Error != nil {
return res.Error
}
err := utils.JsonDecode(config.Config, &s.ChatConfig)
err := utils.JsonDecode(chatConfig.Config, &s.ChatConfig)
if err != nil {
return err
}
// load system configs
var sysConfig model.Config
res = db.Where("marker", "system").First(&sysConfig)
if res.Error != nil {
return res.Error
}
err = utils.JsonDecode(sysConfig.Config, &s.SysConfig)
if err != nil {
return err
}
@@ -164,7 +186,8 @@ func authorizeMiddleware(s *AppServer) gin.HandlerFunc {
if c.Request.URL.Path == "/api/user/login" ||
c.Request.URL.Path == "/api/admin/login" ||
c.Request.URL.Path == "/api/user/register" ||
strings.HasPrefix(c.Request.URL.Path, "/api/verify/") ||
strings.HasPrefix(c.Request.URL.Path, "/api/sms/") ||
strings.HasPrefix(c.Request.URL.Path, "/api/captcha/") ||
strings.HasPrefix(c.Request.URL.Path, "/static/") ||
c.Request.URL.Path == "/api/admin/config/get" {
c.Next()

View File

@@ -33,6 +33,8 @@ func NewDefaultConfig() *types.AppConfig {
HttpOnly: false,
SameSite: http.SameSiteLaxMode,
},
ApiConfig: types.ChatPlusApiConfig{},
StartWechatBot: false,
}
}

View File

@@ -2,17 +2,17 @@ package types
// ApiRequest API 请求实体
type ApiRequest struct {
Model string `json:"model"`
Temperature float32 `json:"temperature"`
MaxTokens int `json:"max_tokens"`
Stream bool `json:"stream"`
Messages []Message `json:"messages"`
Model string `json:"model"`
Temperature float32 `json:"temperature"`
MaxTokens int `json:"max_tokens"`
Stream bool `json:"stream"`
Messages []interface{} `json:"messages"`
Functions []Function `json:"functions"`
}
type Message struct {
Role string `json:"role"`
Content string `json:"content"`
FunctionCall FunctionCall `json:"function_call"`
Role string `json:"role"`
Content string `json:"content"`
}
type ApiResponse struct {
@@ -21,8 +21,15 @@ type ApiResponse struct {
// ChoiceItem API 响应实体
type ChoiceItem struct {
Delta Message `json:"delta"`
FinishReason string `json:"finish_reason"`
Delta Delta `json:"delta"`
FinishReason string `json:"finish_reason"`
}
type Delta struct {
Role string `json:"role"`
Name string `json:"name"`
Content interface{} `json:"content"`
FunctionCall FunctionCall `json:"function_call,omitempty"`
}
// ChatSession 聊天会话对象
@@ -46,3 +53,10 @@ type ApiError struct {
const PromptMsg = "prompt" // prompt message
const ReplyMsg = "reply" // reply message
var ModelToTokens = map[string]int{
"gpt-3.5-turbo": 4096,
"gpt-3.5-turbo-16k": 16384,
"gpt-4": 8192,
"gpt-4-32k": 32768,
}

View File

@@ -6,18 +6,26 @@ import (
)
type AppConfig struct {
Path string `toml:"-"`
Listen string
Session Session
ProxyURL string
MysqlDns string // mysql 连接地址
Manager Manager // 后台管理员账户信息
StaticDir string // 静态资源目录
StaticUrl string // 静态资源 URL
Redis RedisConfig // redis 连接信息
Path string `toml:"-"`
Listen string
Session Session
ProxyURL string
MysqlDns string // mysql 连接地址
Manager Manager // 后台管理员账户信息
StaticDir string // 静态资源目录
StaticUrl string // 静态资源 URL
Redis RedisConfig // redis 连接信息
ApiConfig ChatPlusApiConfig // ChatPlus API authorization configs
AesEncryptKey string
SmsConfig AliYunSmsConfig // AliYun send message service config
StartWechatBot bool // 是否启动微信机器人
EnabledMsgService bool // 是否启用短信服务
}
AesEncryptKey string
SmsConfig AliYunSmsConfig // 短信发送配置
type ChatPlusApiConfig struct {
ApiURL string
AppId string
Token string
}
type AliYunSmsConfig struct {
@@ -72,14 +80,14 @@ type ChatConfig struct {
MaxTokens int `json:"max_tokens"`
EnableContext bool `json:"enable_context"` // 是否开启聊天上下文
EnableHistory bool `json:"enable_history"` // 是否允许保存聊天记录
ApiKey string `json:"api_key"` // OpenAI API key
ApiKey string `json:"api_key"`
ContextDeep int `json:"context_deep"` // 上下文深度
}
type SystemConfig struct {
Title string `json:"title"`
AdminTitle string `json:"admin_title"`
Models []string `json:"models"`
UserInitCalls int `json:"user_init_calls"` // 新用户注册默认总送多少次调用
Title string `json:"title"`
AdminTitle string `json:"admin_title"`
Models []string `json:"models"`
UserInitCalls int `json:"user_init_calls"` // 新用户注册默认总送多少次调用
EnabledRegister bool `json:"enabled_register"`
}
const UserInitCalls = 1000

View File

@@ -6,13 +6,71 @@ type FunctionCall struct {
}
type Function struct {
Name string
Description string
Parameters []Parameter
Name string `json:"name"`
Description string `json:"description"`
Parameters Parameters `json:"parameters"`
}
type Parameter struct {
Type string
Required []string
Properties map[string]interface{}
type Parameters struct {
Type string `json:"type"`
Required []string `json:"required"`
Properties map[string]Property `json:"properties"`
}
type Property struct {
Type string `json:"type"`
Description string `json:"description"`
}
const (
FuncZaoBao = "zao_bao" // 每日早报
FuncHeadLine = "headline" // 今日头条
FuncWeibo = "weibo_hot" // 微博热搜
)
var InnerFunctions = []Function{
{
Name: FuncZaoBao,
Description: "每日早报,获取当天全球的热门新闻事件列表",
Parameters: Parameters{
Type: "object",
Properties: map[string]Property{
"text": {
Type: "string",
Description: "",
},
},
Required: []string{},
},
},
{
Name: FuncWeibo,
Description: "新浪微博热搜榜,微博当日热搜榜单",
Parameters: Parameters{
Type: "object",
Properties: map[string]Property{
"text": {
Type: "string",
Description: "",
},
},
Required: []string{},
},
},
{
Name: FuncHeadLine,
Description: "今日头条,给用户推荐当天的头条新闻,周榜热文",
Parameters: Parameters{
Type: "object",
Properties: map[string]Property{
"text": {
Type: "string",
Description: "",
},
},
Required: []string{},
},
},
}

View File

@@ -9,7 +9,7 @@ type MKey interface {
string | int
}
type MValue interface {
*WsClient | ChatSession | []Message | context.CancelFunc
*WsClient | ChatSession | context.CancelFunc | []interface{}
}
type LMap[K MKey, T MValue] struct {
lock sync.RWMutex

View File

@@ -5,37 +5,59 @@ go 1.19
require (
github.com/BurntSushi/toml v1.1.0
github.com/aliyun/alibaba-cloud-sdk-go v1.62.405
github.com/eatmoreapple/openwechat v1.2.1
github.com/gin-contrib/sessions v0.0.5
github.com/gin-gonic/gin v1.9.0
github.com/gin-gonic/gin v1.9.1
github.com/gorilla/websocket v1.5.0
github.com/imroc/req/v3 v3.37.2
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20230415042440-a5e3d8259ae0
github.com/pkoukk/tiktoken-go v0.1.1-0.20230418101013-cae809389480
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/syndtr/goleveldb v1.0.0
go.uber.org/zap v1.23.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gorm.io/driver/mysql v1.4.7
)
require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
github.com/bytedance/sonic v1.8.0 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/dlclark/regexp2 v1.8.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gaukas/godicttls v0.0.3 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/gomodule/redigo v2.0.0+incompatible // indirect
github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/onsi/ginkgo/v2 v2.10.0 // indirect
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/quasoft/memstore v0.0.0-20191010062613-2bce066d2b0b // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect
github.com/quic-go/quic-go v0.35.1 // indirect
github.com/refraction-networking/utls v1.3.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
go.uber.org/dig v1.16.1 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/tools v0.10.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
@@ -44,21 +66,21 @@ require (
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/sessions v1.2.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/fx v1.19.3
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.6.0
golang.org/x/sys v0.7.0 // indirect
golang.org/x/crypto v0.10.0
golang.org/x/sys v0.9.0 // indirect
gorm.io/gorm v1.25.1
)

View File

@@ -2,12 +2,14 @@ github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/aliyun/alibaba-cloud-sdk-go v1.62.405 h1:cKNFQmeCQFN0WNfjScKoVrGi7vXxTVbkCvCqSrOf+P4=
github.com/aliyun/alibaba-cloud-sdk-go v1.62.405/go.mod h1:Api2AkmMgGaSUAhmk76oaFObkoeCPc/bKAqcyplPODs=
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff h1:RmdPFa+slIr4SCBg4st/l/vZWVe9QJKMXGO60Bxbe04=
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.8.0 h1:ea0Xadu+sHlu7x5O3gKhRpQ1IKiMrSiHttPF0ybECuA=
github.com/bytedance/sonic v1.8.0/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
@@ -16,35 +18,49 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.8.1 h1:6Lcdwya6GjPUNsBct8Lg/yRPwMhABj269AAzdGSiR+0=
github.com/dlclark/regexp2 v1.8.1/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/eatmoreapple/openwechat v1.2.1 h1:ez4oqF/Y2NSEX/DbPV8lvj7JlfkYqvieeo4awx5lzfU=
github.com/eatmoreapple/openwechat v1.2.1/go.mod h1:61HOzTyvLobGdgWhL68jfGNwTJEv0mhQ1miCXQrvWU8=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
github.com/gaukas/godicttls v0.0.3 h1:YNDIf0d9adcxOijiLrEzpfZGAkNwLRzPaG6OjU7EITk=
github.com/gaukas/godicttls v0.0.3/go.mod h1:l6EenT4TLWgTdwslVb4sEMOCf7Bv0JAK67deKr9/NCI=
github.com/gin-contrib/sessions v0.0.5 h1:CATtfHmLMQrMNpJRgzjWXD7worTh7g7ritsQfmF+0jE=
github.com/gin-contrib/sessions v0.0.5/go.mod h1:vYAuaUPqie3WUSsft6HUlCjlwwoJQs97miaG2+7neKY=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8=
github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k=
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU=
github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s=
github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js=
github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA=
github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 h1:hR7/MlvK23p6+lIw9SN1TigNLn9ZnF3W4SYRKq2gAHs=
github.com/google/pprof v0.0.0-20230602150820-91b7bce49751/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA=
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
@@ -54,8 +70,15 @@ github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7Fsg
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/imroc/req/v3 v3.37.2 h1:vEemuA0cq9zJ6lhe+mSRhsZm951bT0CdiSH47+KTn6I=
github.com/imroc/req/v3 v3.37.2/go.mod h1:DECzjVIrj6jcUr5n6e+z0ygmCO93rx4Jy0RjOEe1YCI=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
@@ -66,19 +89,22 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw=
github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20230415042440-a5e3d8259ae0 h1:LgmjED/yQILqmUED4GaXjrINWe7YJh4HM6z2EvEINPs=
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20230415042440-a5e3d8259ae0/go.mod h1:C5LA5UO2ZXJrLaPLYtE1wUJMiyd/nwWaCO5cw/2pSHs=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -88,12 +114,14 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
github.com/onsi/ginkgo/v2 v2.10.0 h1:sfUl4qgLdvkChZrWCYndY2EAu9BRIw1YphNAzy1VNWs=
github.com/onsi/ginkgo/v2 v2.10.0/go.mod h1:UDQOh5wbQUlMnkLfVaIUMtQ1Vus92oM+P2JX1aulgcE=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.27.7 h1:fVih9JD6ogIiHUN6ePK7HJidyEDpWGVB5mzM7cWNXoU=
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b h1:FfH+VrHHk6Lxt9HdVS0PXzSXFyS2NbZKXv33FYPol0A=
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b/go.mod h1:AC62GU6hc0BrNm+9RK9VSiwa/EUe1bkIeFORAMcHvJU=
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkoukk/tiktoken-go v0.1.1-0.20230418101013-cae809389480 h1:IFhPCcB0/HtnEN+ZoUGDT55YgFCymbFJ15kXqs3nv5w=
@@ -102,7 +130,18 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quasoft/memstore v0.0.0-20191010062613-2bce066d2b0b h1:aUNXCGgukb4gtY99imuIeoh8Vr0GSwAlYxPAhqZrpFc=
github.com/quasoft/memstore v0.0.0-20191010062613-2bce066d2b0b/go.mod h1:wTPjTepVu7uJBYgZ0SdWHQlIas582j6cn2jgk4DDdlg=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U=
github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI=
github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E=
github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM=
github.com/quic-go/quic-go v0.35.1 h1:b0kzj6b/cQAf05cT0CkQubHM31wiA+xH3IBkxP62poo=
github.com/quic-go/quic-go v0.35.1/go.mod h1:+4CVgVppm0FNjpG3UcX8Joi/frKOH7/ciD5yGcwOO1g=
github.com/refraction-networking/utls v1.3.2 h1:o+AkWB57mkcoW36ET7uJ002CpBWHu0KPxi6vzxvPnv8=
github.com/refraction-networking/utls v1.3.2/go.mod h1:fmoaOww2bxzzEpIKOebIsnBvjQpqP7L2vcm/9KUfm/E=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@@ -112,7 +151,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
@@ -121,8 +162,9 @@ github.com/uber/jaeger-client-go v2.30.0+incompatible h1:D6wyKGCecFaSRUpo8lCVbaO
github.com/uber/jaeger-client-go v2.30.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=
github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg=
github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
github.com/ugorji/go/codec v1.2.9 h1:rmenucSohSTiyL09Y+l2OCk+FrMxGMzho2+tjr5ticU=
github.com/ugorji/go/codec v1.2.9/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
@@ -135,37 +177,66 @@ go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY=
go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM=
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.10.0 h1:tvDr/iQoUqNdohiYm0LmmKcBk+q86lb9EprIUFhHHGg=
golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI=
gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

View File

@@ -48,6 +48,21 @@ func (h *ConfigHandler) Update(c *gin.Context) {
resp.ERROR(c, res.Error.Error())
return
}
// update config cache for AppServer
var cfg model.Config
h.db.Where("marker", data.Key).First(&cfg)
var err error
if data.Key == "system" {
err = utils.JsonDecode(cfg.Config, &h.App.SysConfig)
} else if data.Key == "chat" {
err = utils.JsonDecode(cfg.Config, &h.App.ChatConfig)
}
if err != nil {
resp.ERROR(c, "Failed to update config cache: "+err.Error())
return
}
logger.Infof("Update AppServer's config successfully: %v", config.Config)
}
resp.SUCCESS(c, config)

View File

@@ -0,0 +1,55 @@
package admin
import (
"chatplus/core"
"chatplus/handler"
"chatplus/store/model"
"chatplus/utils/resp"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"time"
)
type DashboardHandler struct {
handler.BaseHandler
db *gorm.DB
}
func NewDashboardHandler(app *core.AppServer, db *gorm.DB) *DashboardHandler {
h := DashboardHandler{db: db}
h.App = app
return &h
}
type statsVo struct {
Users int64 `json:"users"`
Chats int64 `json:"chats"`
Tokens int64 `json:"tokens"`
}
func (h *DashboardHandler) Stats(c *gin.Context) {
stats := statsVo{}
// new users statistic
var userCount int64
now := time.Now()
zeroTime := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
res := h.db.Model(&model.User{}).Where("created_at > ?", zeroTime).Count(&userCount)
if res.Error == nil {
stats.Users = userCount
}
// new chats statistic
var chatCount int64
res = h.db.Model(&model.ChatItem{}).Where("created_at > ?", zeroTime).Count(&chatCount)
if res.Error == nil {
stats.Chats = chatCount
}
// tokens took stats
var tokenCount int64
res = h.db.Model(&model.HistoryMessage{}).Select("sum(tokens) as tokens_total").Where("created_at > ?", zeroTime).Scan(&tokenCount)
if res.Error == nil {
stats.Tokens = tokenCount
}
resp.SUCCESS(c, stats)
}

View File

@@ -0,0 +1,57 @@
package admin
import (
"chatplus/core"
"chatplus/handler"
"chatplus/store/model"
"chatplus/store/vo"
"chatplus/utils"
"chatplus/utils/resp"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
type RewardHandler struct {
handler.BaseHandler
db *gorm.DB
}
func NewRewardHandler(app *core.AppServer, db *gorm.DB) *RewardHandler {
h := RewardHandler{db: db}
h.App = app
return &h
}
func (h *RewardHandler) List(c *gin.Context) {
var items []model.Reward
res := h.db.Find(&items)
var rewards = make([]vo.Reward, 0)
if res.Error == nil {
userIds := make([]uint, 0)
for _, v := range items {
userIds = append(userIds, v.UserId)
}
var users []model.User
h.db.Where("id IN ?", userIds).Find(&users)
var userMap = make(map[uint]model.User)
for _, u := range users {
userMap[u.Id] = u
}
for _, v := range items {
var r vo.Reward
err := utils.CopyObject(v, &r)
if err != nil {
continue
}
r.Id = v.Id
r.Username = userMap[v.UserId].Username
r.CreatedAt = v.CreatedAt.Unix()
r.UpdatedAt = v.UpdatedAt.Unix()
rewards = append(rewards, r)
}
}
resp.SUCCESS(c, rewards)
}

View File

@@ -8,6 +8,7 @@ import (
"chatplus/store/vo"
"chatplus/utils"
"chatplus/utils/resp"
"fmt"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
@@ -28,12 +29,24 @@ func NewUserHandler(app *core.AppServer, db *gorm.DB) *UserHandler {
func (h *UserHandler) List(c *gin.Context) {
page := h.GetInt(c, "page", 1)
pageSize := h.GetInt(c, "page_size", 20)
mobile := h.GetTrim(c, "mobile")
username := h.GetTrim(c, "username")
offset := (page - 1) * pageSize
var items []model.User
var users = make([]vo.User, 0)
var total int64
h.db.Model(&model.User{}).Count(&total)
res := h.db.Offset(offset).Limit(pageSize).Find(&items)
session := h.db.Session(&gorm.Session{})
if mobile != "" {
session = session.Where("mobile LIKE ?", "%"+mobile+"%")
}
if username != "" {
session = session.Where("username LIKE ?", "%"+username+"%")
}
session.Model(&model.User{}).Count(&total)
res := session.Offset(offset).Limit(pageSize).Find(&items)
if res.Error == nil {
for _, item := range items {
var user vo.User
@@ -52,9 +65,12 @@ func (h *UserHandler) List(c *gin.Context) {
resp.SUCCESS(c, pageVo)
}
func (h *UserHandler) Update(c *gin.Context) {
func (h *UserHandler) Save(c *gin.Context) {
var data struct {
Id uint `json:"id"`
Username string `json:"username"`
Password string `json:"password"`
Mobile string `json:"mobile"`
Nickname string `json:"nickname"`
Calls int `json:"calls"`
ChatRoles []string `json:"chat_roles"`
@@ -66,21 +82,82 @@ func (h *UserHandler) Update(c *gin.Context) {
return
}
var user = model.User{}
user.Id = data.Id
// 此处需要用 map 更新,用结构体无法更新 0 值
res := h.db.Model(&user).Updates(map[string]interface{}{
"nickname": data.Nickname,
"calls": data.Calls,
"status": data.Status,
"chat_roles_json": utils.JsonEncode(data.ChatRoles),
"expired_time": utils.Str2stamp(data.ExpiredTime),
})
var res *gorm.DB
var userVo vo.User
if data.Id > 0 { // 更新
user.Id = data.Id
// 此处需要用 map 更新,用结构体无法更新 0 值
res = h.db.Model(&user).Updates(map[string]interface{}{
"nickname": data.Nickname,
"mobile": data.Mobile,
"calls": data.Calls,
"status": data.Status,
"chat_roles_json": utils.JsonEncode(data.ChatRoles),
"expired_time": utils.Str2stamp(data.ExpiredTime),
})
} else {
salt := utils.RandString(8)
u := model.User{
Username: data.Username,
Password: utils.GenPassword(data.Password, salt),
Nickname: fmt.Sprintf("极客学长@%d", utils.RandomNumber(5)),
Avatar: "/images/avatar/user.png",
Salt: salt,
Status: true,
Mobile: data.Mobile,
ChatRoles: utils.JsonEncode(data.ChatRoles),
ExpiredTime: utils.Str2stamp(data.ExpiredTime),
ChatConfig: utils.JsonEncode(types.ChatConfig{
Temperature: h.App.ChatConfig.Temperature,
MaxTokens: h.App.ChatConfig.MaxTokens,
EnableContext: h.App.ChatConfig.EnableContext,
EnableHistory: true,
Model: h.App.ChatConfig.Model,
ApiKey: "",
}),
Calls: h.App.SysConfig.UserInitCalls,
}
res = h.db.Create(&u)
_ = utils.CopyObject(u, &userVo)
userVo.Id = u.Id
userVo.CreatedAt = u.CreatedAt.Unix()
userVo.UpdatedAt = u.UpdatedAt.Unix()
}
if res.Error != nil {
resp.ERROR(c, "更新数据库失败")
return
}
resp.SUCCESS(c)
resp.SUCCESS(c, userVo)
}
// ResetPass 重置密码
func (h *UserHandler) ResetPass(c *gin.Context) {
var data struct {
Id uint
Password string
}
if err := c.ShouldBindJSON(&data); err != nil {
resp.ERROR(c, types.InvalidArgs)
return
}
var user model.User
res := h.db.First(&user, data.Id)
if res.Error != nil {
resp.ERROR(c, "No user found")
return
}
password := utils.GenPassword(data.Password, user.Salt)
user.Password = password
res = h.db.Updates(&user)
if res.Error != nil {
resp.ERROR(c)
} else {
resp.SUCCESS(c)
}
}
func (h *UserHandler) Remove(c *gin.Context) {

View File

@@ -0,0 +1,47 @@
package handler
import (
"chatplus/core/types"
"chatplus/service"
"chatplus/utils/resp"
"github.com/gin-gonic/gin"
)
// 今日头条函数实现
type CaptchaHandler struct {
service *service.CaptchaService
}
func NewCaptchaHandler(s *service.CaptchaService) *CaptchaHandler {
return &CaptchaHandler{service: s}
}
func (h *CaptchaHandler) Get(c *gin.Context) {
data, err := h.service.Get()
if err != nil {
resp.ERROR(c, err.Error())
return
}
resp.SUCCESS(c, data)
}
// Check verify the captcha data
func (h *CaptchaHandler) Check(c *gin.Context) {
var data struct {
Key string `json:"key"`
Dots string `json:"dots"`
}
if err := c.ShouldBindJSON(&data); err != nil {
resp.ERROR(c, types.InvalidArgs)
return
}
if h.service.Check(data) {
resp.SUCCESS(c)
} else {
resp.ERROR(c)
}
}

View File

@@ -5,7 +5,6 @@ import (
"bytes"
"chatplus/core"
"chatplus/core/types"
"chatplus/service/function"
"chatplus/store/model"
"chatplus/store/vo"
"chatplus/utils"
@@ -30,16 +29,17 @@ const ErrorMsg = "抱歉AI 助手开小差了,请稍后再试。"
type ChatHandler struct {
BaseHandler
db *gorm.DB
funcZaoBao *function.FuncZaoBao
db *gorm.DB
}
func NewChatHandler(app *core.AppServer, db *gorm.DB, zaoBao *function.FuncZaoBao) *ChatHandler {
handler := ChatHandler{db: db, funcZaoBao: zaoBao}
func NewChatHandler(app *core.AppServer, db *gorm.DB) *ChatHandler {
handler := ChatHandler{db: db}
handler.App = app
return &handler
}
var chatConfig types.ChatConfig
// ChatHandle 处理聊天 WebSocket 请求
func (h *ChatHandler) ChatHandle(c *gin.Context) {
ws, err := (&websocket.Upgrader{CheckOrigin: func(r *http.Request) bool { return true }}).Upgrade(c.Writer, c.Request, nil)
@@ -47,6 +47,10 @@ func (h *ChatHandler) ChatHandle(c *gin.Context) {
logger.Error(err)
return
}
// 设置读写超时时间
_ = ws.SetWriteDeadline(time.Now().Add(300 * time.Second))
_ = ws.SetReadDeadline(time.Now().Add(300 * time.Second))
sessionId := c.Query("session_id")
roleId := h.GetInt(c, "role_id", 0)
chatId := c.Query("chat_id")
@@ -84,7 +88,17 @@ func (h *ChatHandler) ChatHandle(c *gin.Context) {
var chatRole model.ChatRole
res = h.db.First(&chatRole, roleId)
if res.Error != nil || !chatRole.Enable {
replyMessage(client, "当前聊天角色不存在或者未启用!!!")
replyMessage(client, "当前聊天角色不存在或者未启用,连接已关闭")
c.Abort()
return
}
// 初始化聊天配置
var config model.Config
h.db.Where("marker", "chat").First(&config)
err = utils.JsonDecode(config.Config, &chatConfig)
if err != nil {
replyMessage(client, "加载系统配置失败,连接已关闭!!!")
c.Abort()
return
}
@@ -141,8 +155,8 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession
return nil
}
if userVo.Calls <= 0 {
replyMessage(ws, "您的对话次数已经用尽,请联系管理员充值")
if userVo.Calls <= 0 && userVo.ChatConfig.ApiKey == "" {
replyMessage(ws, "您的对话次数已经用尽,请联系管理员或者点击左下角菜单加入众筹获得100次对话")
replyMessage(ws, "![](/images/wx.png)")
return nil
}
@@ -157,44 +171,68 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession
Temperature: userVo.ChatConfig.Temperature,
MaxTokens: userVo.ChatConfig.MaxTokens,
Stream: true,
Functions: types.InnerFunctions,
}
// 加载聊天上下文
var chatCtx []types.Message
var chatCtx []interface{}
if userVo.ChatConfig.EnableContext {
if h.App.ChatContexts.Has(session.ChatId) {
chatCtx = h.App.ChatContexts.Get(session.ChatId)
} else {
// 加载角色信息
// calculate the tokens of current request, to prevent to exceeding the max tokens num
tokens := req.MaxTokens
for _, f := range types.InnerFunctions {
tks, _ := utils.CalcTokens(utils.JsonEncode(f), req.Model)
tokens += tks
}
// loading the role context
var messages []types.Message
err := utils.JsonDecode(role.Context, &messages)
if err == nil {
chatCtx = messages
}
// TODO: 这里默认加载最近 4 条聊天记录作为上下文,后期应该做成可配置的
var historyMessages []model.HistoryMessage
res := h.db.Where("chat_id = ?", session.ChatId).Limit(4).Order("created_at desc").Find(&historyMessages)
if res.Error == nil {
for _, msg := range historyMessages {
ms := types.Message{Role: "user", Content: msg.Content}
if msg.Type == types.ReplyMsg {
ms.Role = "assistant"
for _, v := range messages {
tks, _ := utils.CalcTokens(v.Content, req.Model)
if tokens+tks >= types.ModelToTokens[req.Model] {
break
}
tokens += tks
chatCtx = append(chatCtx, v)
}
}
// loading recent chat history as chat context
if chatConfig.ContextDeep > 0 {
var historyMessages []model.HistoryMessage
res := h.db.Where("chat_id = ? and use_context = 1", session.ChatId).Limit(chatConfig.ContextDeep).Order("created_at desc").Find(&historyMessages)
if res.Error == nil {
for _, msg := range historyMessages {
if tokens+msg.Tokens >= types.ModelToTokens[session.Model] {
break
}
tokens += msg.Tokens
ms := types.Message{Role: "user", Content: msg.Content}
if msg.Type == types.ReplyMsg {
ms.Role = "assistant"
}
chatCtx = append(chatCtx, ms)
}
chatCtx = append(chatCtx, ms)
}
}
}
if h.App.Debug { // 调试打印聊天上下文
logger.Info("聊天上下文:", chatCtx)
}
logger.Debugf("聊天上下文:%+v", chatCtx)
}
req.Messages = append(chatCtx, types.Message{
Role: "user",
Content: prompt,
reqMgs := make([]interface{}, 0)
for _, m := range chatCtx {
reqMgs = append(reqMgs, m)
}
req.Messages = append(reqMgs, map[string]interface{}{
"role": "user",
"content": prompt,
})
var apiKey string
response, err := h.fakeRequest(ctx, userVo, &apiKey, req)
response, err := h.doRequest(ctx, userVo, &apiKey, req)
if err != nil {
if strings.Contains(err.Error(), "context canceled") {
logger.Info("用户取消了请求:", prompt)
@@ -213,176 +251,207 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession
defer response.Body.Close()
}
//contentType := response.Header.Get("Content-Type")
//if strings.Contains(contentType, "text/event-stream") || true {
if true {
replyCreatedAt := time.Now()
// 循环读取 Chunk 消息
var message = types.Message{}
var contents = make([]string, 0)
var functionCall = false
var functionName string
var arguments = make([]string, 0)
reader := bufio.NewReader(response.Body)
for {
line, err := reader.ReadString('\n')
if err != nil {
if strings.Contains(err.Error(), "context canceled") {
logger.Info("用户取消了请求:", prompt)
} else {
logger.Error(err)
}
break
}
if !strings.Contains(line, "data:") || len(line) < 30 {
continue
}
var responseBody = types.ApiResponse{}
err = json.Unmarshal([]byte(line[6:]), &responseBody)
if err != nil || len(responseBody.Choices) == 0 { // 数据解析出错
logger.Error(err, line)
replyMessage(ws, ErrorMsg)
replyMessage(ws, "![](/images/wx.png)")
break
}
fun := responseBody.Choices[0].Delta.FunctionCall
if functionCall && fun.Name == "" {
arguments = append(arguments, fun.Arguments)
continue
}
if !utils.IsEmptyValue(fun) {
functionCall = true
functionName = fun.Name
replyChunkMessage(ws, types.WsMessage{Type: types.WsStart})
replyChunkMessage(ws, types.WsMessage{Type: types.WsMiddle, Content: fmt.Sprintf("正在调用函数 %s 作答 ...\n\n", functionName)})
continue
}
if responseBody.Choices[0].FinishReason == "function_call" { // 函数调用完毕
break
}
// 初始化 role
if responseBody.Choices[0].Delta.Role != "" && message.Role == "" {
message.Role = responseBody.Choices[0].Delta.Role
replyChunkMessage(ws, types.WsMessage{Type: types.WsStart})
continue
} else if responseBody.Choices[0].FinishReason != "" {
break // 输出完成或者输出中断了
} else {
content := responseBody.Choices[0].Delta.Content
contents = append(contents, content)
replyChunkMessage(ws, types.WsMessage{
Type: types.WsMiddle,
Content: responseBody.Choices[0].Delta.Content,
})
}
} // end for
if functionCall { // 调用函数完成任务
// TODO 调用函数完成任务
data, err := h.funcZaoBao.Fetch()
if err != nil {
replyChunkMessage(ws, types.WsMessage{
Type: types.WsMiddle,
Content: "调用函数出错",
})
} else {
replyChunkMessage(ws, types.WsMessage{
Type: types.WsMiddle,
Content: data,
})
}
contents = append(contents, data)
}
// 消息发送成功
if len(contents) > 0 {
// 更新用户的对话次数
res := h.db.Model(&user).UpdateColumn("calls", gorm.Expr("calls - ?", 1))
if res.Error != nil {
return res.Error
}
if message.Role == "" {
message.Role = "assistant"
}
message.Content = strings.Join(contents, "")
useMsg := types.Message{Role: "user", Content: prompt}
// 更新上下文消息,如果是调用函数则不需要更新上下文
if userVo.ChatConfig.EnableContext && functionCall == false {
chatCtx = append(chatCtx, useMsg) // 提问消息
chatCtx = append(chatCtx, message) // 回复消息
h.App.ChatContexts.Put(session.ChatId, chatCtx)
}
// 追加聊天记录
if userVo.ChatConfig.EnableHistory {
// for prompt
token, err := utils.CalcTokens(prompt, req.Model)
contentType := response.Header.Get("Content-Type")
if strings.Contains(contentType, "text/event-stream") {
if true {
replyCreatedAt := time.Now()
// 循环读取 Chunk 消息
var message = types.Message{}
var contents = make([]string, 0)
var functionCall = false
var functionName string
var arguments = make([]string, 0)
reader := bufio.NewReader(response.Body)
for {
line, err := reader.ReadString('\n')
if err != nil {
logger.Error(err)
if strings.Contains(err.Error(), "context canceled") {
logger.Info("用户取消了请求:", prompt)
} else if err != io.EOF {
logger.Error("信息读取出错:", err)
}
break
}
historyUserMsg := model.HistoryMessage{
UserId: userVo.Id,
ChatId: session.ChatId,
RoleId: role.Id,
Type: types.PromptMsg,
Icon: user.Avatar,
Content: prompt,
Tokens: token,
}
historyUserMsg.CreatedAt = promptCreatedAt
historyUserMsg.UpdatedAt = promptCreatedAt
res := h.db.Save(&historyUserMsg)
if res.Error != nil {
logger.Error("failed to save prompt history message: ", res.Error)
if !strings.Contains(line, "data:") || len(line) < 30 {
continue
}
// for reply
token, err = utils.CalcTokens(message.Content, req.Model)
var responseBody = types.ApiResponse{}
err = json.Unmarshal([]byte(line[6:]), &responseBody)
if err != nil || len(responseBody.Choices) == 0 { // 数据解析出错
logger.Error(err, line)
replyMessage(ws, ErrorMsg)
replyMessage(ws, "![](/images/wx.png)")
break
}
fun := responseBody.Choices[0].Delta.FunctionCall
if functionCall && fun.Name == "" {
arguments = append(arguments, fun.Arguments)
continue
}
if !utils.IsEmptyValue(fun) {
functionCall = true
functionName = fun.Name
f := h.App.Functions[functionName]
replyChunkMessage(ws, types.WsMessage{Type: types.WsStart})
replyChunkMessage(ws, types.WsMessage{Type: types.WsMiddle, Content: fmt.Sprintf("正在调用函数 `%s` 作答 ...\n\n", f.Name())})
continue
}
if responseBody.Choices[0].FinishReason == "function_call" { // 函数调用完毕
break
}
// 初始化 role
if responseBody.Choices[0].Delta.Role != "" && message.Role == "" {
message.Role = responseBody.Choices[0].Delta.Role
replyChunkMessage(ws, types.WsMessage{Type: types.WsStart})
continue
} else if responseBody.Choices[0].FinishReason != "" {
break // 输出完成或者输出中断了
} else {
content := responseBody.Choices[0].Delta.Content
contents = append(contents, utils.InterfaceToString(content))
replyChunkMessage(ws, types.WsMessage{
Type: types.WsMiddle,
Content: utils.InterfaceToString(responseBody.Choices[0].Delta.Content),
})
}
} // end for
if functionCall { // 调用函数完成任务
logger.Info(functionName)
logger.Info(arguments)
f := h.App.Functions[functionName]
data, err := f.Invoke(arguments)
if err != nil {
logger.Error(err)
msg := "调用函数出错:" + err.Error()
replyChunkMessage(ws, types.WsMessage{
Type: types.WsMiddle,
Content: msg,
})
contents = append(contents, msg)
} else {
replyChunkMessage(ws, types.WsMessage{
Type: types.WsMiddle,
Content: data,
})
contents = append(contents, data)
}
historyReplyMsg := model.HistoryMessage{
UserId: userVo.Id,
ChatId: session.ChatId,
RoleId: role.Id,
Type: types.ReplyMsg,
Icon: role.Icon,
Content: message.Content,
Tokens: token,
}
historyReplyMsg.CreatedAt = replyCreatedAt
historyReplyMsg.UpdatedAt = replyCreatedAt
res = h.db.Create(&historyReplyMsg)
if res.Error != nil {
logger.Error("failed to save reply history message: ", res.Error)
}
// 统计用户 token 数量
h.db.Model(&user).UpdateColumn("tokens", gorm.Expr("tokens + ?",
historyUserMsg.Tokens+historyReplyMsg.Tokens))
}
// 保存当前会话
var chatItem model.ChatItem
res = h.db.Where("chat_id = ?", session.ChatId).First(&chatItem)
if res.Error != nil {
chatItem.ChatId = session.ChatId
chatItem.UserId = session.UserId
chatItem.RoleId = role.Id
chatItem.Model = session.Model
if utf8.RuneCountInString(prompt) > 30 {
chatItem.Title = string([]rune(prompt)[:30]) + "..."
} else {
chatItem.Title = prompt
// 消息发送成功
if len(contents) > 0 {
// 更新用户的对话次数
if userVo.ChatConfig.ApiKey == "" { // 如果用户使用的是自己绑定的 API KEY 则不扣减对话次数
res := h.db.Model(&user).UpdateColumn("calls", gorm.Expr("calls - ?", 1))
if res.Error != nil {
return res.Error
}
}
if message.Role == "" {
message.Role = "assistant"
}
message.Content = strings.Join(contents, "")
useMsg := types.Message{Role: "user", Content: prompt}
// 更新上下文消息,如果是调用函数则不需要更新上下文
if userVo.ChatConfig.EnableContext && functionCall == false {
chatCtx = append(chatCtx, useMsg) // 提问消息
chatCtx = append(chatCtx, message) // 回复消息
h.App.ChatContexts.Put(session.ChatId, chatCtx)
}
// 追加聊天记录
if userVo.ChatConfig.EnableHistory {
useContext := true
if functionCall {
useContext = false
}
// for prompt
promptToken, err := utils.CalcTokens(prompt, req.Model)
if err != nil {
logger.Error(err)
}
historyUserMsg := model.HistoryMessage{
UserId: userVo.Id,
ChatId: session.ChatId,
RoleId: role.Id,
Type: types.PromptMsg,
Icon: user.Avatar,
Content: prompt,
Tokens: promptToken,
UseContext: useContext,
}
historyUserMsg.CreatedAt = promptCreatedAt
historyUserMsg.UpdatedAt = promptCreatedAt
res := h.db.Save(&historyUserMsg)
if res.Error != nil {
logger.Error("failed to save prompt history message: ", res.Error)
}
// for reply
// 计算本次对话消耗的总 token 数量
var replyToken = 0
if functionCall { // 函数名 + 参数 token
tokens, _ := utils.CalcTokens(functionName, req.Model)
replyToken += tokens
tokens, _ = utils.CalcTokens(utils.InterfaceToString(arguments), req.Model)
replyToken += tokens
} else {
replyToken, _ = utils.CalcTokens(message.Content, req.Model)
}
historyReplyMsg := model.HistoryMessage{
UserId: userVo.Id,
ChatId: session.ChatId,
RoleId: role.Id,
Type: types.ReplyMsg,
Icon: role.Icon,
Content: message.Content,
Tokens: replyToken,
UseContext: useContext,
}
historyReplyMsg.CreatedAt = replyCreatedAt
historyReplyMsg.UpdatedAt = replyCreatedAt
res = h.db.Create(&historyReplyMsg)
if res.Error != nil {
logger.Error("failed to save reply history message: ", res.Error)
}
// 计算本次对话消耗的总 token 数量
var totalTokens = 0
if functionCall { // prompt + 函数名 + 参数 token
totalTokens = promptToken + replyToken
} else {
totalTokens = replyToken + getTotalTokens(req)
}
//replyChunkMessage(ws, types.WsMessage{Type: types.WsMiddle, Content: fmt.Sprintf("\n\n `本轮对话共消耗 Token 数量: %d`", totalTokens+11)})
if userVo.ChatConfig.ApiKey != "" { // 调用自己的 API KEY 不计算 token 消耗
h.db.Model(&user).UpdateColumn("tokens", gorm.Expr("tokens + ?",
totalTokens))
}
}
// 保存当前会话
var chatItem model.ChatItem
res = h.db.Where("chat_id = ?", session.ChatId).First(&chatItem)
if res.Error != nil {
chatItem.ChatId = session.ChatId
chatItem.UserId = session.UserId
chatItem.RoleId = role.Id
chatItem.Model = session.Model
if utf8.RuneCountInString(prompt) > 30 {
chatItem.Title = string([]rune(prompt)[:30]) + "..."
} else {
chatItem.Title = prompt
}
h.db.Create(&chatItem)
}
h.db.Create(&chatItem)
}
}
} else {
@@ -405,13 +474,9 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession
} else if strings.Contains(res.Error.Message, "You exceeded your current quota") {
replyMessage(ws, "请求 OpenAI API 失败API KEY 触发并发限制,请稍后再试。")
} else if strings.Contains(res.Error.Message, "This model's maximum context length") {
replyMessage(ws, "当前会话上下文长度超出限制,已为您删减会话上下文!")
// 只保留最近的三条记录
chatContext := h.App.ChatContexts.Get(session.ChatId)
if len(chatContext) > 3 {
chatContext = chatContext[len(chatContext)-3:]
}
h.App.ChatContexts.Put(session.ChatId, chatContext)
logger.Error(res.Error.Message)
replyMessage(ws, "当前会话上下文长度超出限制,已为您清空会话上下文!")
h.App.ChatContexts.Delete(session.ChatId)
return h.sendMessage(ctx, session, role, prompt, ws)
} else {
replyMessage(ws, "请求 OpenAI API 失败:"+res.Error.Message)
@@ -469,13 +534,6 @@ func (h *ChatHandler) doRequest(ctx context.Context, user vo.User, apiKey *strin
return client.Do(request)
}
func (h *ChatHandler) fakeRequest(ctx context.Context, user vo.User, apiKey *string, req types.ApiRequest) (*http.Response, error) {
link := "https://img.r9it.com/chatgpt/response"
client := &http.Client{}
request, _ := http.NewRequest(http.MethodGet, link, nil)
return client.Do(request)
}
// 回复客户片段端消息
func replyChunkMessage(client types.Client, message types.WsMessage) {
msg, err := json.Marshal(message)
@@ -509,6 +567,26 @@ func (h *ChatHandler) Tokens(c *gin.Context) {
resp.SUCCESS(c, tokens)
}
func getTotalTokens(req types.ApiRequest) int {
encode := utils.JsonEncode(req.Messages)
var items []map[string]interface{}
err := utils.JsonDecode(encode, &items)
if err != nil {
return 0
}
tokens := 0
for _, item := range items {
content, ok := item["content"]
if ok && !utils.IsEmptyValue(content) {
t, err := utils.CalcTokens(utils.InterfaceToString(content), req.Model)
if err == nil {
tokens += t
}
}
}
return tokens
}
// StopGenerate 停止生成
func (h *ChatHandler) StopGenerate(c *gin.Context) {
sessionId := c.Query("session_id")

View File

@@ -0,0 +1,73 @@
package handler
import (
"chatplus/core"
"chatplus/core/types"
"chatplus/store/model"
"chatplus/utils"
"chatplus/utils/resp"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
type RewardHandler struct {
BaseHandler
db *gorm.DB
}
func NewRewardHandler(server *core.AppServer, db *gorm.DB) *RewardHandler {
h := RewardHandler{db: db}
h.App = server
return &h
}
// Verify 打赏码核销
func (h *RewardHandler) Verify(c *gin.Context) {
var data struct {
TxId string `json:"tx_id"`
}
if err := c.ShouldBindJSON(&data); err != nil {
resp.ERROR(c, types.InvalidArgs)
return
}
var item model.Reward
res := h.db.Where("tx_id = ?", data.TxId).First(&item)
if res.Error != nil {
resp.ERROR(c, "无效的众筹交易流水号!")
return
}
if item.Status {
resp.ERROR(c, "当前众筹交易流水号已经被核销,请不要重复核销!")
return
}
user, err := utils.GetLoginUser(c, h.db)
if err != nil {
resp.HACKER(c)
return
}
tx := h.db.Begin()
calls := (item.Amount + 0.1) * 10
res = h.db.Model(&user).UpdateColumn("calls", gorm.Expr("calls + ?", calls))
if res.Error != nil {
resp.ERROR(c, "更新数据库失败!")
return
}
// 更新核销状态
item.Status = true
item.UserId = user.Id
res = h.db.Updates(&item)
if res.Error != nil {
tx.Rollback()
resp.ERROR(c, "更新数据库失败!")
return
}
tx.Commit()
resp.SUCCESS(c)
}

View File

@@ -0,0 +1,70 @@
package handler
import (
"chatplus/core"
"chatplus/core/types"
"chatplus/service"
"chatplus/store"
"chatplus/utils"
"chatplus/utils/resp"
"github.com/gin-gonic/gin"
)
const CodeStorePrefix = "/verify/codes/"
type SmsHandler struct {
BaseHandler
db *store.LevelDB
sms *service.AliYunSmsService
captcha *service.CaptchaService
}
func NewSmsHandler(app *core.AppServer, db *store.LevelDB, sms *service.AliYunSmsService, captcha *service.CaptchaService) *SmsHandler {
handler := &SmsHandler{db: db, sms: sms, captcha: captcha}
handler.App = app
return handler
}
// SendCode 发送验证码短信
func (h *SmsHandler) SendCode(c *gin.Context) {
var data struct {
Mobile string `json:"mobile"`
Key string `json:"key"`
Dots string `json:"dots"`
}
if err := c.ShouldBindJSON(&data); err != nil {
resp.ERROR(c, types.InvalidArgs)
return
}
if !h.captcha.Check(data) {
resp.ERROR(c, "验证码错误,请先完人机验证")
return
}
code := utils.RandomNumber(6)
err := h.sms.SendVerifyCode(data.Mobile, code)
if err != nil {
resp.ERROR(c, err.Error())
return
}
// 存储验证码,等待后面注册验证
err = h.db.Put(CodeStorePrefix+data.Mobile, code)
if err != nil {
resp.ERROR(c, "验证码保存失败")
return
}
resp.SUCCESS(c)
}
type statusVo struct {
EnabledMsgService bool `json:"enabled_msg_service"`
EnabledRegister bool `json:"enabled_register"`
}
// Status check if the message service is enabled
func (h *SmsHandler) Status(c *gin.Context) {
resp.SUCCESS(c, statusVo{EnabledMsgService: h.App.Config.EnabledMsgService, EnabledRegister: h.App.SysConfig.EnabledRegister})
}

View File

@@ -58,12 +58,14 @@ func (h *UserHandler) Register(c *gin.Context) {
// 检查验证码
key := CodeStorePrefix + data.Mobile
var code int
err := h.levelDB.Get(key, &code)
if err != nil || code != data.Code {
logger.Info(code)
resp.ERROR(c, "短信验证码错误")
return
if h.App.Config.EnabledMsgService {
var code int
err := h.levelDB.Get(key, &code)
if err != nil || code != data.Code {
logger.Info(code)
resp.ERROR(c, "短信验证码错误")
return
}
}
// check if the username is exists
@@ -106,16 +108,7 @@ func (h *UserHandler) Register(c *gin.Context) {
Model: h.App.ChatConfig.Model,
ApiKey: "",
}),
}
// 初始化调用次数
var cfg model.Config
h.db.Where("marker = ?", "system").First(&cfg)
var config types.SystemConfig
err = utils.JsonDecode(cfg.Config, &config)
if err != nil || config.UserInitCalls <= 0 {
user.Calls = types.UserInitCalls
} else {
user.Calls = config.UserInitCalls
Calls: h.App.SysConfig.UserInitCalls,
}
res = h.db.Create(&user)
if res.Error != nil {
@@ -124,7 +117,9 @@ func (h *UserHandler) Register(c *gin.Context) {
return
}
_ = h.levelDB.Delete(key) // 注册成功,删除短信验证码
if h.App.Config.EnabledMsgService {
_ = h.levelDB.Delete(key) // 注册成功,删除短信验证码
}
resp.SUCCESS(c, user)
}
@@ -139,7 +134,7 @@ func (h *UserHandler) Login(c *gin.Context) {
return
}
var user model.User
res := h.db.Where("username = ?", data.Username).First(&user)
res := h.db.Where("username = ? OR mobile = ?", data.Username, data.Username).First(&user)
if res.Error != nil {
resp.ERROR(c, "用户名不存在")
return
@@ -151,6 +146,11 @@ func (h *UserHandler) Login(c *gin.Context) {
return
}
if user.Status == false {
resp.ERROR(c, "该用户已被禁止登录,请联系管理员")
return
}
// 更新最后登录时间和IP
user.LastLoginIp = c.ClientIP()
user.LastLoginAt = time.Now().Unix()

View File

@@ -1,150 +0,0 @@
package handler
import (
"chatplus/core"
"chatplus/core/types"
"chatplus/service"
"chatplus/store"
"chatplus/utils"
"chatplus/utils/resp"
"fmt"
"time"
"github.com/gin-gonic/gin"
)
// 生成验证的控制器
type VerifyHandler struct {
BaseHandler
sms *service.AliYunSmsService
db *store.LevelDB
}
const TokenStorePrefix = "/verify/tokens/"
const CodeStorePrefix = "/verify/codes/"
const MobileStatPrefix = "/verify/stats/"
func NewVerifyHandler(app *core.AppServer, sms *service.AliYunSmsService, db *store.LevelDB) *VerifyHandler {
handler := &VerifyHandler{sms: sms, db: db}
handler.App = app
return handler
}
type VerifyToken struct {
Token string
Timestamp int64
}
// CodeStats 验证码发送统计
type CodeStats struct {
Mobile string
Count uint
Time int64
}
// Token 生成自验证 token
func (h *VerifyHandler) Token(c *gin.Context) {
// 如果不是通过浏览器访问,则返回错误的 token
if c.GetHeader("Sec-Fetch-Mode") != "cors" {
token := fmt.Sprintf("%s:%d", utils.RandString(32), time.Now().Unix())
encrypt, err := utils.AesEncrypt(h.App.Config.AesEncryptKey, []byte(token))
if err != nil {
resp.ERROR(c, "Token 加密出错")
return
}
resp.SUCCESS(c, encrypt)
return
}
token := VerifyToken{
Token: utils.RandString(32),
Timestamp: time.Now().Unix(),
}
json := utils.JsonEncode(token)
encrypt, err := utils.AesEncrypt(h.App.Config.AesEncryptKey, []byte(json))
if err != nil {
resp.ERROR(c, "Token 加密出错")
return
}
err = h.db.Put(TokenStorePrefix+token.Token, token)
if err != nil {
resp.ERROR(c, "Token 存储失败")
return
}
resp.SUCCESS(c, encrypt)
}
// SendMsg 发送验证码短信
func (h *VerifyHandler) SendMsg(c *gin.Context) {
var data struct {
Mobile string `json:"mobile"`
Token string `json:"token"`
}
if err := c.ShouldBindJSON(&data); err != nil {
resp.ERROR(c, types.InvalidArgs)
return
}
decrypt, err := utils.AesDecrypt(h.App.Config.AesEncryptKey, data.Token)
if err != nil {
resp.ERROR(c, "Token 解密失败")
return
}
var token VerifyToken
err = utils.JsonDecode(string(decrypt), &token)
if err != nil {
resp.ERROR(c, "Token 解码失败")
return
}
if time.Now().Unix()-token.Timestamp > 30 {
resp.ERROR(c, "Token 已过期,请刷新页面重试")
return
}
// 验证当前手机号发送次数24 小时内相同手机号只允许发送 2 次
var stat CodeStats
err = h.db.Get(MobileStatPrefix+data.Mobile, &stat)
if err != nil {
logger.Error(err)
stat = CodeStats{
Mobile: data.Mobile,
Count: 0,
Time: time.Now().Unix(),
}
} else if stat.Count == 2 {
if time.Now().Unix()-stat.Time > 86400 {
stat.Count = 0
stat.Time = time.Now().Unix()
} else {
resp.ERROR(c, "触发流量预警,请 24 小时后再操作!")
return
}
}
code := utils.RandomNumber(6)
err = h.sms.SendVerifyCode(data.Mobile, code)
if err != nil {
resp.ERROR(c, err.Error())
return
}
// 每个 token 用完一次立即失效
_ = h.db.Delete(TokenStorePrefix + token.Token)
// 存储验证码,等待后面注册验证
err = h.db.Put(CodeStorePrefix+data.Mobile, code)
if err != nil {
resp.ERROR(c, "验证码保存失败")
return
}
// 更新发送次数
stat.Count = stat.Count + 1
_ = h.db.Put(MobileStatPrefix+data.Mobile, stat)
logger.Infof("%+v", stat)
resp.SUCCESS(c)
}

View File

@@ -2,25 +2,73 @@ package logger
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"gopkg.in/natefinch/lumberjack.v2"
"os"
"strings"
)
var logger *zap.SugaredLogger
var logger *zap.Logger
var sugarLogger *zap.SugaredLogger
func GetLogger() *zap.SugaredLogger {
if logger != nil {
return logger
if sugarLogger != nil {
return sugarLogger
}
logLevel := zap.NewAtomicLevel()
logLevel.SetLevel(zap.InfoLevel)
log, _ := zap.Config{
Level: logLevel,
Development: false,
Encoding: "console",
EncoderConfig: zap.NewDevelopmentEncoderConfig(),
OutputPaths: []string{"stderr"},
ErrorOutputPaths: []string{"stderr"},
}.Build()
logger = log.Sugar()
return logger
logLevel := zap.NewAtomicLevelAt(getLogLevel(os.Getenv("LOG_LEVEL")))
encoder := getEncoder()
writerSyncer := getLogWriter()
fileCore := zapcore.NewCore(encoder, writerSyncer, logLevel)
consoleOutput := zapcore.Lock(os.Stdout)
consoleCore := zapcore.NewCore(
encoder,
consoleOutput,
logLevel,
)
core := zapcore.NewTee(fileCore, consoleCore)
logger = zap.New(core, zap.AddCaller())
sugarLogger = logger.Sugar()
return sugarLogger
}
// core 三个参数之 编码
func getEncoder() zapcore.Encoder {
encoderConfig := zapcore.EncoderConfig{
TimeKey: "time",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
MessageKey: "msg",
StacktraceKey: "stacktrace",
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
EncodeLevel: zapcore.CapitalLevelEncoder,
}
return zapcore.NewConsoleEncoder(encoderConfig)
}
func getLogWriter() zapcore.WriteSyncer {
lumberJackLogger := &lumberjack.Logger{
Filename: "logs/app.log",
MaxSize: 10,
MaxBackups: 5,
MaxAge: 30,
Compress: false,
}
return zapcore.AddSync(lumberJackLogger)
}
func getLogLevel(level string) zapcore.Level {
switch strings.ToUpper(level) {
case "DEBUG":
return zapcore.DebugLevel
case "WARN":
return zapcore.WarnLevel
case "ERROR":
return zapcore.ErrorLevel
default:
return zapcore.InfoLevel
}
}

View File

@@ -6,6 +6,7 @@ import (
"chatplus/handler"
"chatplus/handler/admin"
logger2 "chatplus/logger"
"chatplus/modules/wexin"
"chatplus/service"
"chatplus/service/function"
"chatplus/store"
@@ -72,6 +73,9 @@ func main() {
log.Fatal(err)
}
config.Path = configFile
if debug {
_ = core.SaveConfig(config)
}
return config
}),
// 创建应用服务
@@ -100,10 +104,26 @@ func main() {
return xdb.NewWithBuffer(cBuff)
}),
// 创建微信机器人
fx.Provide(wexin.NewWeChatBot),
fx.Invoke(func(bot *wexin.WeChatBot) {
go func() {
err := bot.Login()
if err != nil {
log.Fatal(err)
}
}()
}),
// 创建函数
fx.Provide(func() *function.FuncZaoBao {
token := os.Getenv("AL_API_TOKEN")
return function.NewZaoBao(token)
fx.Provide(func(config *types.AppConfig) (function.FuncZaoBao, error) {
return function.NewZaoBao(config.ApiConfig), nil
}),
fx.Provide(func(config *types.AppConfig) (function.FuncWeiboHot, error) {
return function.NewWeiboHot(config.ApiConfig), nil
}),
fx.Provide(func(config *types.AppConfig) (function.FuncHeadlines, error) {
return function.NewHeadLines(config.ApiConfig), nil
}),
// 创建控制器
@@ -111,16 +131,23 @@ func main() {
fx.Provide(handler.NewUserHandler),
fx.Provide(handler.NewChatHandler),
fx.Provide(handler.NewUploadHandler),
fx.Provide(handler.NewVerifyHandler),
fx.Provide(handler.NewSmsHandler),
fx.Provide(handler.NewRewardHandler),
fx.Provide(handler.NewCaptchaHandler),
fx.Provide(admin.NewConfigHandler),
fx.Provide(admin.NewAdminHandler),
fx.Provide(admin.NewApiKeyHandler),
fx.Provide(admin.NewUserHandler),
fx.Provide(admin.NewChatRoleHandler),
fx.Provide(admin.NewRewardHandler),
fx.Provide(admin.NewDashboardHandler),
// 创建服务
fx.Provide(service.NewAliYunSmsService),
fx.Provide(func(config *types.AppConfig) *service.CaptchaService {
return service.NewCaptchaService(config.ApiConfig)
}),
// 注册路由
fx.Invoke(func(s *core.AppServer, h *handler.ChatRoleHandler) {
@@ -152,10 +179,19 @@ func main() {
fx.Invoke(func(s *core.AppServer, h *handler.UploadHandler) {
s.Engine.POST("/api/upload", h.Upload)
}),
fx.Invoke(func(s *core.AppServer, h *handler.VerifyHandler) {
group := s.Engine.Group("/api/verify/")
group.GET("token", h.Token)
group.POST("sms", h.SendMsg)
fx.Invoke(func(s *core.AppServer, h *handler.SmsHandler) {
group := s.Engine.Group("/api/sms/")
group.GET("status", h.Status)
group.POST("code", h.SendCode)
}),
fx.Invoke(func(s *core.AppServer, h *handler.CaptchaHandler) {
group := s.Engine.Group("/api/captcha/")
group.GET("get", h.Get)
group.POST("check", h.Check)
}),
fx.Invoke(func(s *core.AppServer, h *handler.RewardHandler) {
group := s.Engine.Group("/api/reward/")
group.POST("verify", h.Verify)
}),
// 管理后台控制器
@@ -180,9 +216,10 @@ func main() {
fx.Invoke(func(s *core.AppServer, h *admin.UserHandler) {
group := s.Engine.Group("/api/admin/user/")
group.GET("list", h.List)
group.POST("update", h.Update)
group.POST("save", h.Save)
group.GET("remove", h.Remove)
group.GET("loginLog", h.LoginLog)
group.POST("resetPass", h.ResetPass)
}),
fx.Invoke(func(s *core.AppServer, h *admin.ChatRoleHandler) {
group := s.Engine.Group("/api/admin/role/")
@@ -191,6 +228,14 @@ func main() {
group.POST("sort", h.SetSort)
group.GET("remove", h.Remove)
}),
fx.Invoke(func(s *core.AppServer, h *admin.RewardHandler) {
group := s.Engine.Group("/api/admin/reward/")
group.GET("list", h.List)
}),
fx.Invoke(func(s *core.AppServer, h *admin.DashboardHandler) {
group := s.Engine.Group("/api/admin/dashboard/")
group.GET("stats", h.Stats)
}),
fx.Invoke(func(s *core.AppServer, db *gorm.DB) {
err := s.Run(db)

View File

@@ -0,0 +1,54 @@
package wexin
import (
"chatplus/store/model"
"github.com/eatmoreapple/openwechat"
"github.com/skip2/go-qrcode"
"gorm.io/gorm"
)
// MessageHandler 消息处理
func MessageHandler(msg *openwechat.Message, db *gorm.DB) {
sender, err := msg.Sender()
if err != nil {
return
}
// 只处理微信支付的推送消息
if sender.NickName == "微信支付" ||
msg.MsgType == openwechat.MsgTypeApp ||
msg.AppMsgType == openwechat.AppMsgTypeUrl {
// 解析支付金额
message, err := parseTransactionMessage(msg.Content)
if err == nil {
transaction := extractTransaction(message)
logger.Infof("解析到收款信息:%+v", transaction)
if transaction.Amount <= 0 {
return
}
var item model.Reward
res := db.Where("tx_id = ?", transaction.TransId).First(&item)
if res.Error == nil {
logger.Infof("当前交易 ID %s 己经存在!", transaction.TransId)
return
}
res = db.Create(&model.Reward{
TxId: transaction.TransId,
Amount: transaction.Amount,
Remark: transaction.Remark,
Status: false,
})
if res.Error != nil {
logger.Errorf("交易保存失败ID: %s", transaction.TransId)
}
}
}
}
// QrCodeCallBack 登录扫码回调,
func QrCodeCallBack(uuid string) {
logger.Info("请使用微信扫描下面二维码登录")
q, _ := qrcode.New("https://login.weixin.qq.com/l/"+uuid, qrcode.Medium)
logger.Info(q.ToString(true))
}

View File

@@ -0,0 +1,68 @@
package wexin
import (
"encoding/xml"
"strconv"
"strings"
)
// Message 转账消息
type Message struct {
XMLName xml.Name `xml:"msg"`
AppMsg struct {
Des string `xml:"des"`
Url string `xml:"url"`
} `xml:"appmsg"`
}
// Transaction 解析后的交易信息
type Transaction struct {
TransId string `json:"trans_id"` // 微信转账交易 ID
Amount float64 `json:"amount"` // 微信转账交易金额
Remark string `json:"remark"` // 转账备注
}
// 解析微信转账消息
func parseTransactionMessage(xmlData string) (*Message, error) {
var msg Message
if err := xml.Unmarshal([]byte(xmlData), &msg); err != nil {
return nil, err
}
return &msg, nil
}
// 导出交易信息
func extractTransaction(message *Message) Transaction {
var tx = Transaction{}
// 导出交易金额和备注
lines := strings.Split(message.AppMsg.Des, "\n")
for _, line := range lines {
line = strings.TrimSpace(line)
if len(line) == 0 {
continue
}
// 解析收款金额
prefix := "收款金额¥"
if strings.HasPrefix(line, prefix) {
if value, err := strconv.ParseFloat(line[len(prefix):], 64); err == nil {
tx.Amount = value
continue
}
}
// 解析收款备注
prefix = "付款方备注"
if strings.HasPrefix(line, prefix) {
tx.Remark = line[len(prefix):]
break
}
}
// 解析交易 ID
index := strings.Index(message.AppMsg.Url, "trans_id=")
if index != -1 {
end := strings.LastIndex(message.AppMsg.Url, "&")
tx.TransId = strings.TrimSpace(message.AppMsg.Url[index+9 : end])
}
return tx
}

View File

@@ -0,0 +1,49 @@
package wexin
import (
"chatplus/core/types"
logger2 "chatplus/logger"
"github.com/eatmoreapple/openwechat"
"gorm.io/gorm"
)
// 微信收款机器人服务
var logger = logger2.GetLogger()
type WeChatBot struct {
bot *openwechat.Bot
db *gorm.DB
appConfig *types.AppConfig
}
func NewWeChatBot(db *gorm.DB, config *types.AppConfig) *WeChatBot {
bot := openwechat.DefaultBot(openwechat.Desktop)
// 注册消息处理函数
bot.MessageHandler = func(msg *openwechat.Message) {
MessageHandler(msg, db)
}
// 注册登陆二维码回调
bot.UUIDCallback = QrCodeCallBack
return &WeChatBot{
bot: bot,
db: db,
appConfig: config,
}
}
func (b *WeChatBot) Login() error {
if !b.appConfig.StartWechatBot {
return nil
}
// 创建热存储容器对象
reloadStorage := openwechat.NewJsonFileHotReloadStorage("storage.json")
// 执行热登录
err := b.bot.HotLogin(reloadStorage)
if err != nil {
logger.Error("login error: %v", err)
return b.bot.Login()
}
logger.Info("微信登录成功!")
return nil
}

View File

@@ -0,0 +1,62 @@
package service
import (
"chatplus/core/types"
"errors"
"fmt"
"github.com/imroc/req/v3"
"time"
)
type CaptchaService struct {
config types.ChatPlusApiConfig
client *req.Client
}
func NewCaptchaService(config types.ChatPlusApiConfig) *CaptchaService {
return &CaptchaService{
config: config,
client: req.C().SetTimeout(10 * time.Second),
}
}
func (s *CaptchaService) Get() (interface{}, error) {
if s.config.Token == "" {
return nil, errors.New("无效的 API Token")
}
url := fmt.Sprintf("%s/api/captcha/get", s.config.ApiURL)
var res types.BizVo
r, err := s.client.R().
SetHeader("AppId", s.config.AppId).
SetHeader("Authorization", fmt.Sprintf("Bearer %s", s.config.Token)).
SetSuccessResult(&res).Get(url)
if err != nil || r.IsErrorState() {
return nil, fmt.Errorf("请求 API 失败:%v", err)
}
if res.Code != types.Success {
return nil, fmt.Errorf("请求 API 失败:%s", res.Message)
}
return res.Data, nil
}
func (s *CaptchaService) Check(data interface{}) bool {
url := fmt.Sprintf("%s/api/captcha/check", s.config.ApiURL)
var res types.BizVo
r, err := s.client.R().
SetHeader("AppId", s.config.AppId).
SetHeader("Authorization", fmt.Sprintf("Bearer %s", s.config.Token)).
SetBodyJsonMarshal(data).
SetSuccessResult(&res).Post(url)
if err != nil || r.IsErrorState() {
return false
}
if res.Code != types.Success {
return false
}
return true
}

View File

@@ -0,0 +1,24 @@
package function
import "chatplus/core/types"
type Function interface {
Invoke(...interface{}) (string, error)
Name() string
}
type resVo struct {
Code types.BizCode `json:"code"`
Message string `json:"message"`
Data struct {
Title string `json:"title"`
UpdatedAt string `json:"updated_at"`
Items []dataItem `json:"items"`
} `json:"data"`
}
type dataItem struct {
Title string `json:"title"`
Url string `json:"url"`
Remark string `json:"remark"`
}

View File

@@ -0,0 +1,59 @@
package function
import (
"chatplus/core/types"
"errors"
"fmt"
"github.com/imroc/req/v3"
"strings"
"time"
)
// 今日头条函数实现
type FuncHeadlines struct {
name string
config types.ChatPlusApiConfig
client *req.Client
}
func NewHeadLines(config types.ChatPlusApiConfig) FuncHeadlines {
return FuncHeadlines{
name: "今日头条",
config: config,
client: req.C().SetTimeout(10 * time.Second)}
}
func (f FuncHeadlines) Invoke(...interface{}) (string, error) {
if f.config.Token == "" {
return "", errors.New("无效的 API Token")
}
url := fmt.Sprintf("%s/api/headline/fetch", f.config.ApiURL)
var res resVo
r, err := f.client.R().
SetHeader("AppId", f.config.AppId).
SetHeader("Authorization", fmt.Sprintf("Bearer %s", f.config.Token)).
SetSuccessResult(&res).Get(url)
if err != nil {
return "", err
}
if r.IsErrorState() {
return "", r.Err
}
if res.Code != types.Success {
return "", errors.New(res.Message)
}
builder := make([]string, 0)
builder = append(builder, fmt.Sprintf("**%s**,最新更新:%s", res.Data.Title, res.Data.UpdatedAt))
for i, v := range res.Data.Items {
builder = append(builder, fmt.Sprintf("%d、 [%s](%s) [%s]", i+1, v.Title, v.Url, v.Remark))
}
return strings.Join(builder, "\n\n"), nil
}
func (f FuncHeadlines) Name() string {
return f.name
}

View File

@@ -0,0 +1,59 @@
package function
import (
"chatplus/core/types"
"errors"
"fmt"
"github.com/imroc/req/v3"
"strings"
"time"
)
// 微博热搜函数实现
type FuncWeiboHot struct {
name string
config types.ChatPlusApiConfig
client *req.Client
}
func NewWeiboHot(config types.ChatPlusApiConfig) FuncWeiboHot {
return FuncWeiboHot{
name: "微博热搜",
config: config,
client: req.C().SetTimeout(10 * time.Second)}
}
func (f FuncWeiboHot) Invoke(...interface{}) (string, error) {
if f.config.Token == "" {
return "", errors.New("无效的 API Token")
}
url := fmt.Sprintf("%s/api/weibo/fetch", f.config.ApiURL)
var res resVo
r, err := f.client.R().
SetHeader("AppId", f.config.AppId).
SetHeader("Authorization", fmt.Sprintf("Bearer %s", f.config.Token)).
SetSuccessResult(&res).Get(url)
if err != nil {
return "", err
}
if r.IsErrorState() {
return "", r.Err
}
if res.Code != types.Success {
return "", errors.New(res.Message)
}
builder := make([]string, 0)
builder = append(builder, fmt.Sprintf("**%s**,最新更新:%s", res.Data.Title, res.Data.UpdatedAt))
for i, v := range res.Data.Items {
builder = append(builder, fmt.Sprintf("%d、 [%s](%s) [热度:%s]", i+1, v.Title, v.Url, v.Remark))
}
return strings.Join(builder, "\n\n"), nil
}
func (f FuncWeiboHot) Name() string {
return f.name
}

View File

@@ -1,51 +1,60 @@
package function
import (
"chatplus/utils"
"chatplus/core/types"
"errors"
"fmt"
"github.com/imroc/req/v3"
"strings"
"time"
)
// 每日早报函数实现
type FuncZaoBao struct {
apiURL string
token string
name string
config types.ChatPlusApiConfig
client *req.Client
}
func NewZaoBao(token string) *FuncZaoBao {
return &FuncZaoBao{apiURL: "https://v2.alapi.cn/api/zaobao", token: token}
func NewZaoBao(config types.ChatPlusApiConfig) FuncZaoBao {
return FuncZaoBao{
name: "每日早报",
config: config,
client: req.C().SetTimeout(10 * time.Second)}
}
type resVo struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data struct {
Date string `json:"date"`
News []string `json:"news"`
WeiYu string `json:"weiyu"`
} `json:"data"`
}
func (f *FuncZaoBao) Fetch() (string, error) {
url := fmt.Sprintf("%s?format=json&token=%s", f.apiURL, f.token)
bytes, err := utils.HttpGet(url, "")
if err != nil {
return "", err
func (f FuncZaoBao) Invoke(...interface{}) (string, error) {
if f.config.Token == "" {
return "", errors.New("无效的 API Token")
}
url := fmt.Sprintf("%s/api/zaobao/fetch", f.config.ApiURL)
var res resVo
err = utils.JsonDecode(string(bytes), &res)
r, err := f.client.R().
SetHeader("AppId", f.config.AppId).
SetHeader("Authorization", fmt.Sprintf("Bearer %s", f.config.Token)).
SetSuccessResult(&res).Get(url)
if err != nil {
return "", err
}
if res.Code != 200 {
return "", fmt.Errorf("call api fail: %s", res.Msg)
if r.IsErrorState() {
return "", r.Err
}
if res.Code != types.Success {
return "", errors.New(res.Message)
}
builder := make([]string, 0)
builder = append(builder, fmt.Sprintf("**%s 早报:**", res.Data.Date))
builder = append(builder, res.Data.News...)
builder = append(builder, fmt.Sprintf("%s", res.Data.WeiYu))
builder = append(builder, fmt.Sprintf("**%s 早报:**", res.Data.UpdatedAt))
for _, v := range res.Data.Items {
builder = append(builder, v.Title)
}
builder = append(builder, fmt.Sprintf("%s", res.Data.Title))
return strings.Join(builder, "\n\n"), nil
}
func (f FuncZaoBao) Name() string {
return f.name
}

View File

@@ -2,13 +2,14 @@ package model
type HistoryMessage struct {
BaseModel
ChatId string // 会话 ID
UserId uint // 用户 ID
RoleId uint // 角色 ID
Type string
Icon string
Tokens int
Content string
ChatId string // 会话 ID
UserId uint // 用户 ID
RoleId uint // 角色 ID
Type string
Icon string
Tokens int
Content string
UseContext bool // 是否可以作为聊天上下文
}
func (HistoryMessage) TableName() string {

12
api/store/model/reward.go Normal file
View File

@@ -0,0 +1,12 @@
package model
// 用户打赏
type Reward struct {
BaseModel
UserId uint // 用户 ID
TxId string // 交易ID
Amount float64 // 打赏金额
Remark string // 打赏备注
Status bool // 核销状态
}

View File

@@ -2,13 +2,14 @@ package vo
type HistoryMessage struct {
BaseVo
ChatId string `json:"chat_id"`
UserId uint `json:"user_id"`
RoleId uint `json:"role_id"`
Type string `json:"type"`
Icon string `json:"icon"`
Tokens int `json:"tokens"`
Content string `json:"content"`
ChatId string `json:"chat_id"`
UserId uint `json:"user_id"`
RoleId uint `json:"role_id"`
Type string `json:"type"`
Icon string `json:"icon"`
Tokens int `json:"tokens"`
Content string `json:"content"`
UseContext bool `json:"use_context"`
}
func (HistoryMessage) TableName() string {

11
api/store/vo/reward.go Normal file
View File

@@ -0,0 +1,11 @@
package vo
type Reward struct {
BaseVo
UserId uint `json:"user_id"` // 用户 ID
Username string `json:"username"`
TxId string `json:"tx_id"` // 交易ID
Amount float64 `json:"amount"` // 打赏金额
Remark string `json:"remark"` // 打赏备注
Status bool `json:"status"` // 核销状态
}

View File

@@ -56,6 +56,10 @@ func Stamp2str(timestamp int64) string {
// Str2stamp 字符串转时间戳
func Str2stamp(str string) int64 {
if len(str) == 0 {
return 0
}
layout := "2006-01-02 15:04:05"
t, err := time.Parse(layout, str)
if err != nil {
@@ -81,3 +85,10 @@ func JsonEncode(value interface{}) string {
func JsonDecode(src string, dest interface{}) error {
return json.Unmarshal([]byte(src), dest)
}
func InterfaceToString(value interface{}) string {
if str, ok := value.(string); ok {
return str
}
return JsonEncode(value)
}

View File

@@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- 主机: localhost
-- 生成日期: 2023-06-27 14:14:47
-- 生成日期: 2023-07-25 17:07:04
-- 服务器版本: 8.0.33-0ubuntu0.22.04.2
-- PHP 版本: 8.1.18
@@ -55,140 +55,11 @@ CREATE TABLE `chatgpt_chat_history` (
`role_id` int NOT NULL COMMENT '角色 ID',
`content` text NOT NULL COMMENT '聊天内容',
`tokens` smallint NOT NULL COMMENT '耗费 token 数量',
`use_context` tinyint(1) NOT NULL COMMENT '是否允许作为上下文语料',
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='聊天历史记录';
--
-- 转存表中的数据 `chatgpt_chat_history`
--
INSERT INTO `chatgpt_chat_history` (`id`, `user_id`, `chat_id`, `type`, `icon`, `role_id`, `content`, `tokens`, `created_at`, `updated_at`) VALUES
(1, 4, 'ecb752e8-86ae-4989-897e-5b7ed331cb68', 'prompt', '/images/avatar/user.png', 24, '请写一段代码实现生成 Excel 文档', 12, '2023-06-12 15:51:10', '2023-06-25 18:09:47'),
(2, 4, 'ecb752e8-86ae-4989-897e-5b7ed331cb68', 'reply', '/images/avatar/programmer.jpg', 24, '好的,以下是使用 Golang 实现生成 Excel 文档的示例代码:\n\n```go\npackage main\n\nimport (\n \"fmt\"\n \"github.com/360EntSecGroup-Skylar/excelize\"\n)\n\nfunc main() {\n // 创建一个新的 Excel 文档\n f := excelize.NewFile()\n\n // 创建一个新的工作表\n index := f.NewSheet(\"Sheet1\")\n\n // 设置表头\n f.SetCellValue(\"Sheet1\", \"A1\", \"姓名\")\n f.SetCellValue(\"Sheet1\", \"B1\", \"年龄\")\n f.SetCellValue(\"Sheet1\", \"C1\", \"性别\")\n\n // 填充数据\n f.SetCellValue(\"Sheet1\", \"A2\", \"小明\")\n f.SetCellValue(\"Sheet1\", \"B2\", 18)\n f.SetCellValue(\"Sheet1\", \"C2\", \"男\")\n\n f.SetCellValue(\"Sheet1\", \"A3\", \"小红\")\n f.SetCellValue(\"Sheet1\", \"B3\", 20)\n f.SetCellValue(\"Sheet1\", \"C3\", \"女\")\n\n // 设置活动工作表\n f.SetActiveSheet(index)\n\n // 保存 Excel 文档\n if err := f.SaveAs(\"example.xlsx\"); err != nil {\n fmt.Println(err)\n }\n}\n```\n\n以上代码首先使用 excelize 包创建一个新的 Excel 文档,并创建一个名为 \"Sheet1\" 的工作表。然后使用 `SetCellValue` 函数设置表头和数据。最后将 \"Sheet1\" 工作表设置为活动工作表,并使用 `SaveAs` 函数将 Excel 文档保存到本地。', 12, '2023-06-12 15:51:10', '2023-06-25 18:09:47'),
(3, 4, 'ecb752e8-86ae-4989-897e-5b7ed331cb68', 'prompt', '/images/avatar/user.png', 24, '生成二维码', 5, '2023-06-12 17:05:10', '2023-06-25 18:09:47'),
(4, 4, 'ecb752e8-86ae-4989-897e-5b7ed331cb68', 'reply', '/images/avatar/programmer.jpg', 24, '好的,生成二维码这个需求可以使用 Go 语言的第三方库来实现。下面是一个简单的示例,使用 go-qrcode 生成一个包含字符串信息的二维码:\n\n```go\npackage main\n\nimport (\n \"bufio\"\n \"fmt\"\n \"os\"\n\n qrcode \"github.com/skip2/go-qrcode\"\n)\n\nfunc main() {\n reader := bufio.NewReader(os.Stdin)\n fmt.Print(\"请输入要生成二维码的信息:\")\n text, _ := reader.ReadString(\'\\n\')\n\n qr, _ := qrcode.New(text, qrcode.Medium)\n qr.WriteFile(256, \"qrcode.png\")\n fmt.Println(\"二维码已生成,请查看当前目录下的 qrcode.png 文件。\")\n}\n```\n\n在这个示例中我们使用了 go-qrcode 这个第三方库来生成二维码。首先,我们通过标准输入获取用户输入的字符串信息,然后调用 New 函数创建一个二维码实例,使用 qr.WriteFile 保存为 PNG 格式的图片文件。最后,程序会输出一条提示信息,告知用户二维码生成成功。\n\n当然这个示例只是一个简单的演示实际应用中可能需要考虑更多的需求比如二维码的尺寸、颜色、背景等但基本的思路是相似的。', 5, '2023-06-12 17:05:10', '2023-06-25 18:09:47'),
(5, 4, 'f7aa0fa1-4cc5-4212-b823-eb5b88844c31', 'prompt', '/images/avatar/user.png', 27, '你好', 2, '2023-06-12 18:32:05', '2023-06-25 18:09:47'),
(6, 4, 'f7aa0fa1-4cc5-4212-b823-eb5b88844c31', 'reply', '/images/avatar/psychiatrist.jpg', 27, '你好,有什么我能帮助你的吗?', 2, '2023-06-12 18:32:05', '2023-06-25 18:09:47'),
(7, 4, 'ea9d399a-6e62-4bf6-a0c0-c73faa8dcace', 'prompt', '/images/avatar/user.png', 1, 'sdasd', 2, '2023-06-13 09:12:04', '2023-06-25 18:09:47'),
(8, 4, 'ea9d399a-6e62-4bf6-a0c0-c73faa8dcace', 'reply', '/images/avatar/gpt.png', 1, 'I\'m sorry, I do not understand what you are trying to convey. Please provide more context.', 2, '2023-06-13 09:12:04', '2023-06-25 18:09:47'),
(9, 4, 'f7aa0fa1-4cc5-4212-b823-eb5b88844c31', 'prompt', '/images/avatar/user.png', 27, '', 11, '2023-06-13 09:35:02', '2023-06-25 18:09:47'),
(10, 4, 'f7aa0fa1-4cc5-4212-b823-eb5b88844c31', 'reply', '/images/avatar/psychiatrist.jpg', 27, '使', 11, '2023-06-13 09:35:02', '2023-06-25 18:09:47'),
(11, 4, 'f7aa0fa1-4cc5-4212-b823-eb5b88844c31', 'prompt', '/images/avatar/user.png', 27, '', 20, '2023-06-13 09:36:16', '2023-06-25 18:09:47'),
(12, 4, 'f7aa0fa1-4cc5-4212-b823-eb5b88844c31', 'reply', '/images/avatar/psychiatrist.jpg', 27, '\n\n认知重构法通过帮助客户辨认和纠正这些消极的认知偏差和自我评价\n\n1. \n\n2. \n\n3. \n\n4. \n\n这种方法可以帮助客户更好地理解和管理自己的思想和情感反应', 20, '2023-06-13 09:36:16', '2023-06-25 18:09:47'),
(13, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'prompt', '/images/avatar/user.png', 28, '', 16, '2023-06-13 10:00:21', '2023-06-25 18:09:47'),
(14, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'reply', '/images/avatar/lu_xun.jpg', 28, '', 127, '2023-06-13 10:00:22', '2023-06-25 18:09:47'),
(15, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'prompt', '/images/avatar/user.png', 28, '', 25, '2023-06-13 11:05:31', '2023-06-25 18:09:47'),
(16, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'reply', '/images/avatar/lu_xun.jpg', 28, '', 90, '2023-06-13 11:05:32', '2023-06-25 18:09:47'),
(17, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'prompt', '/images/avatar/user.png', 28, '', 14, '2023-06-13 11:06:06', '2023-06-25 18:09:47'),
(18, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'reply', '/images/avatar/lu_xun.jpg', 28, '1920', 214, '2023-06-13 11:06:08', '2023-06-25 18:09:47'),
(19, 4, 'ea9d399a-6e62-4bf6-a0c0-c73faa8dcace', 'prompt', '/images/avatar/user.png', 1, 'hello', 1, '2023-06-13 11:28:28', '2023-06-25 18:09:47'),
(20, 4, 'ea9d399a-6e62-4bf6-a0c0-c73faa8dcace', 'reply', '/images/avatar/gpt.png', 1, 'Hello! How may I assist you today?', 9, '2023-06-13 11:28:29', '2023-06-25 18:09:47'),
(21, 4, 'ea9d399a-6e62-4bf6-a0c0-c73faa8dcace', 'prompt', '/images/avatar/user.png', 1, 'hello', 1, '2023-06-13 11:29:31', '2023-06-25 18:09:47'),
(22, 4, 'ea9d399a-6e62-4bf6-a0c0-c73faa8dcace', 'reply', '/images/avatar/gpt.png', 1, 'Hi there! Is there anything I can help you with today?', 13, '2023-06-13 11:29:32', '2023-06-25 18:09:47'),
(23, 4, '43937f77-28b0-438a-843b-04ab5cc072a4', 'prompt', '/images/avatar/user.png', 1, 'hello', 1, '2023-06-13 11:35:48', '2023-06-25 18:09:47'),
(24, 4, '43937f77-28b0-438a-843b-04ab5cc072a4', 'reply', '/images/avatar/gpt.png', 1, 'Hello! How can I assist you today?', 9, '2023-06-13 11:35:51', '2023-06-25 18:09:47'),
(25, 4, '4385db19-bb73-4b09-a01e-d06c3645b77a', 'prompt', '/images/avatar/user.png', 1, 'hello', 1, '2023-06-13 11:38:21', '2023-06-25 18:09:47'),
(26, 4, '4385db19-bb73-4b09-a01e-d06c3645b77a', 'reply', '/images/avatar/gpt.png', 1, 'Hello! How can I assist you today?', 9, '2023-06-13 11:38:21', '2023-06-25 18:09:47'),
(27, 4, 'ceb5fab7-a2e0-449d-869b-a9ac117adf8d', 'prompt', '/images/avatar/user.png', 1, 'hello', 1, '2023-06-13 11:45:35', '2023-06-25 18:09:47'),
(28, 4, 'ceb5fab7-a2e0-449d-869b-a9ac117adf8d', 'reply', '/images/avatar/gpt.png', 1, 'Hello there, how can I assist you?', 9, '2023-06-13 11:45:36', '2023-06-25 18:09:47'),
(29, 4, '1cddfd62-3bf0-4fa9-bfd8-a0ce4663eb78', 'prompt', '/images/avatar/user.png', 1, 'hello', 1, '2023-06-13 11:46:52', '2023-06-25 18:09:47'),
(30, 4, '1cddfd62-3bf0-4fa9-bfd8-a0ce4663eb78', 'reply', '/images/avatar/gpt.png', 1, 'Hello! How can I assist you today?', 9, '2023-06-13 11:46:53', '2023-06-25 18:09:47'),
(31, 4, '0118588e-399d-4a2a-8469-36e5a1af6a93', 'prompt', '/images/avatar/user.png', 1, 'hello', 1, '2023-06-13 11:57:47', '2023-06-25 18:09:47'),
(32, 4, '0118588e-399d-4a2a-8469-36e5a1af6a93', 'reply', '/images/avatar/gpt.png', 1, 'Hello! How can I assist you today?', 9, '2023-06-13 11:57:48', '2023-06-25 18:09:47'),
(33, 4, '568f2918-33b2-46f7-8ef0-b9fa0b241bf2', 'prompt', '/images/avatar/user.png', 1, 'hello', 1, '2023-06-13 11:58:04', '2023-06-25 18:09:47'),
(34, 4, '568f2918-33b2-46f7-8ef0-b9fa0b241bf2', 'reply', '/images/avatar/gpt.png', 1, 'Hello! How can I assist you today?', 9, '2023-06-13 11:58:08', '2023-06-25 18:09:47'),
(35, 4, '568f2918-33b2-46f7-8ef0-b9fa0b241bf2', 'prompt', '/images/avatar/user.png', 1, '', 5, '2023-06-13 11:58:19', '2023-06-25 18:09:47'),
(36, 4, '568f2918-33b2-46f7-8ef0-b9fa0b241bf2', 'reply', '/images/avatar/gpt.png', 1, 'AI语言模型', 22, '2023-06-13 11:58:21', '2023-06-25 18:09:47'),
(37, 4, '568f2918-33b2-46f7-8ef0-b9fa0b241bf2', 'prompt', '/images/avatar/user.png', 1, '', 8, '2023-06-13 11:58:28', '2023-06-25 18:09:47'),
(38, 4, '568f2918-33b2-46f7-8ef0-b9fa0b241bf2', 'reply', '/images/avatar/gpt.png', 1, '', 49, '2023-06-13 11:58:29', '2023-06-25 18:09:47'),
(39, 4, '1cddfd62-3bf0-4fa9-bfd8-a0ce4663eb78', 'prompt', '/images/avatar/user.png', 1, 'hello', 1, '2023-06-13 12:03:44', '2023-06-25 18:09:47'),
(40, 4, '1cddfd62-3bf0-4fa9-bfd8-a0ce4663eb78', 'reply', '/images/avatar/gpt.png', 1, 'Hello again! Is there anything I can help you with?', 12, '2023-06-13 12:03:46', '2023-06-25 18:09:47'),
(41, 4, '3c79cfda-816b-404b-832c-04a400b816c8', 'prompt', '/images/avatar/user.png', 1, 'hello', 1, '2023-06-13 12:06:32', '2023-06-25 18:09:47'),
(42, 4, '3c79cfda-816b-404b-832c-04a400b816c8', 'reply', '/images/avatar/gpt.png', 1, 'Hello! How can I assist you today?', 9, '2023-06-13 12:06:35', '2023-06-25 18:09:47'),
(43, 4, '4f391861-1d48-430f-91b8-2782d884c10a', 'prompt', '/images/avatar/user.png', 1, '', 2, '2023-06-13 12:06:47', '2023-06-25 18:09:47'),
(44, 4, '4f391861-1d48-430f-91b8-2782d884c10a', 'reply', '/images/avatar/gpt.png', 1, '', 18, '2023-06-13 12:06:48', '2023-06-25 18:09:47'),
(45, 4, 'c5e400fc-b9a8-4bd4-a608-be955284c0a9', 'prompt', '/images/avatar/user.png', 1, 'hello', 1, '2023-06-13 16:58:26', '2023-06-25 18:09:47'),
(46, 4, 'c5e400fc-b9a8-4bd4-a608-be955284c0a9', 'reply', '/images/avatar/gpt.png', 1, 'Hello there! How can I assist you today?', 10, '2023-06-13 16:58:27', '2023-06-25 18:09:47'),
(47, 4, 'c5e400fc-b9a8-4bd4-a608-be955284c0a9', 'prompt', '/images/avatar/user.png', 1, 'hello', 1, '2023-06-13 17:02:35', '2023-06-25 18:09:47'),
(48, 4, 'c5e400fc-b9a8-4bd4-a608-be955284c0a9', 'reply', '/images/avatar/gpt.png', 1, 'Hello! How can I assist you today?', 9, '2023-06-13 17:02:36', '2023-06-25 18:09:47'),
(49, 4, 'c5e400fc-b9a8-4bd4-a608-be955284c0a9', 'prompt', '/images/avatar/user.png', 1, '', 4, '2023-06-13 17:02:48', '2023-06-25 18:09:47'),
(50, 4, 'c5e400fc-b9a8-4bd4-a608-be955284c0a9', 'reply', '/images/avatar/gpt.png', 1, ' AI ', 25, '2023-06-13 17:02:49', '2023-06-25 18:09:47'),
(51, 4, 'c5e400fc-b9a8-4bd4-a608-be955284c0a9', 'prompt', '/images/avatar/user.png', 1, '', 7, '2023-06-13 17:08:21', '2023-06-25 18:09:47'),
(52, 4, 'c5e400fc-b9a8-4bd4-a608-be955284c0a9', 'reply', '/images/avatar/gpt.png', 1, 'AI语言模型', 16, '2023-06-13 17:08:26', '2023-06-25 18:09:47'),
(53, 4, 'd5179095-a460-4c62-bfa0-59f83ab17ed7', 'prompt', '/images/avatar/user.png', 1, '', 4, '2023-06-13 17:11:25', '2023-06-25 18:09:47'),
(54, 4, 'd5179095-a460-4c62-bfa0-59f83ab17ed7', 'reply', '/images/avatar/gpt.png', 1, 'AI助手OpenAI', 13, '2023-06-13 17:11:26', '2023-06-25 18:09:47'),
(55, 4, 'd5179095-a460-4c62-bfa0-59f83ab17ed7', 'prompt', '/images/avatar/user.png', 1, '', 7, '2023-06-13 17:11:46', '2023-06-25 18:09:47'),
(56, 4, 'd5179095-a460-4c62-bfa0-59f83ab17ed7', 'reply', '/images/avatar/gpt.png', 1, '', 11, '2023-06-13 17:11:47', '2023-06-25 18:09:47'),
(57, 4, 'd5179095-a460-4c62-bfa0-59f83ab17ed7', 'prompt', '/images/avatar/user.png', 1, '', 7, '2023-06-13 17:14:25', '2023-06-25 18:09:47'),
(58, 4, 'd5179095-a460-4c62-bfa0-59f83ab17ed7', 'reply', '/images/avatar/gpt.png', 1, 'AI', 21, '2023-06-13 17:14:26', '2023-06-25 18:09:47'),
(59, 4, 'd5179095-a460-4c62-bfa0-59f83ab17ed7', 'prompt', '/images/avatar/user.png', 1, '', 17, '2023-06-13 17:16:10', '2023-06-25 18:09:47'),
(60, 4, 'd5179095-a460-4c62-bfa0-59f83ab17ed7', 'reply', '/images/avatar/gpt.png', 1, 'AI', 52, '2023-06-13 17:16:11', '2023-06-25 18:09:47'),
(61, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'prompt', '/images/avatar/user.png', 28, 'Q这个人物', 13, '2023-06-13 17:18:42', '2023-06-25 18:09:47'),
(62, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'reply', '/images/avatar/lu_xun.jpg', 28, 'QQ的存在本身就是一种寓言', 196, '2023-06-13 17:18:43', '2023-06-25 18:09:47'),
(63, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'prompt', '/images/avatar/user.png', 28, '', 11, '2023-06-13 17:23:02', '2023-06-25 18:09:47'),
(64, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'reply', '/images/avatar/lu_xun.jpg', 28, '', 239, '2023-06-13 17:23:03', '2023-06-25 18:09:47'),
(65, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'prompt', '/images/avatar/user.png', 28, '', 20, '2023-06-13 17:25:01', '2023-06-25 18:09:47'),
(66, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'reply', '/images/avatar/lu_xun.jpg', 28, '', 260, '2023-06-13 17:25:03', '2023-06-25 18:09:47'),
(67, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'prompt', '/images/avatar/user.png', 28, '', 26, '2023-06-13 17:45:06', '2023-06-25 18:09:47'),
(68, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'reply', '/images/avatar/lu_xun.jpg', 28, '', 308, '2023-06-13 17:45:07', '2023-06-25 18:09:47'),
(69, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'prompt', '/images/avatar/user.png', 28, '', 24, '2023-06-13 17:48:56', '2023-06-25 18:09:47'),
(70, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'reply', '/images/avatar/lu_xun.jpg', 28, '便', 261, '2023-06-13 17:48:57', '2023-06-25 18:09:47'),
(71, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'prompt', '/images/avatar/user.png', 28, '', 13, '2023-06-15 07:14:58', '2023-06-25 18:09:47'),
(72, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'reply', '/images/avatar/lu_xun.jpg', 28, '使\n\n至于金钱的本质AI的份上', 437, '2023-06-15 07:15:00', '2023-06-25 18:09:47'),
(77, 4, '0acd67e6-6442-4056-b10b-c7e0926ceccf', 'prompt', '/images/avatar/user.png', 35, '', 13, '2023-06-15 10:12:03', '2023-06-25 18:09:47'),
(78, 4, '0acd67e6-6442-4056-b10b-c7e0926ceccf', 'reply', '/images/avatar/girl_friend.jpg', 35, '', 185, '2023-06-15 10:12:04', '2023-06-25 18:09:47'),
(83, 9, 'd8e61f33-9287-4d63-b28f-b6e6aa891bb5', 'prompt', '/images/avatar/user.png', 1, '', 4, '2023-06-15 11:13:55', '2023-06-25 18:09:47'),
(84, 9, 'd8e61f33-9287-4d63-b28f-b6e6aa891bb5', 'reply', '/images/avatar/gpt.png', 1, 'OpenAI GPT-3', 38, '2023-06-15 11:13:55', '2023-06-25 18:09:47'),
(85, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'prompt', '/images/avatar/user.png', 1, 'hello', 1, '2023-06-16 12:19:29', '2023-06-25 18:09:47'),
(86, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'reply', '/images/avatar/gpt.png', 1, 'Hello! How can I assist you today?', 9, '2023-06-16 12:19:30', '2023-06-25 18:09:47'),
(87, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'prompt', '/images/avatar/user.png', 1, 'hello', 1, '2023-06-16 15:28:12', '2023-06-25 18:09:47'),
(88, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'reply', '/images/avatar/gpt.png', 1, 'Hello! How can I assist you today?', 9, '2023-06-16 15:28:18', '2023-06-25 18:09:47'),
(89, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'prompt', '/images/avatar/user.png', 1, '', 5, '2023-06-16 15:28:49', '2023-06-25 18:09:47'),
(90, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'reply', '/images/avatar/gpt.png', 1, 'AI语言模型', 42, '2023-06-16 15:28:50', '2023-06-25 18:09:47'),
(91, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'prompt', '/images/avatar/user.png', 1, '', 10, '2023-06-16 15:29:20', '2023-06-25 18:09:47'),
(92, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'reply', '/images/avatar/gpt.png', 1, '', 70, '2023-06-16 15:29:21', '2023-06-25 18:09:47'),
(93, 4, 'e5e6d499-7716-48c7-87cc-0b26734c51ae', 'prompt', '/images/avatar/user.png', 24, '', 9, '2023-06-16 15:30:18', '2023-06-25 18:09:47'),
(94, 4, 'e5e6d499-7716-48c7-87cc-0b26734c51ae', 'reply', '/images/avatar/programmer.jpg', 24, '\n\n- Go\n- Java\n- Python\n- C/C++\n- JavaScript\n- PHP\n\n不同的编程语言有着不同的特点和适用场景', 130, '2023-06-16 15:30:20', '2023-06-25 18:09:47'),
(95, 4, '895e142d-83b5-4695-9e52-35b4c957c4fd', 'prompt', '/images/avatar/user.png', 1, '', 2, '2023-06-21 10:33:44', '2023-06-25 18:09:47'),
(96, 4, '895e142d-83b5-4695-9e52-35b4c957c4fd', 'reply', '/images/avatar/gpt.png', 1, '', 16, '2023-06-21 10:33:47', '2023-06-25 18:09:47'),
(97, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'prompt', '/images/avatar/user.png', 28, 'hello', 1, '2023-06-26 10:57:11', '2023-06-26 10:57:11'),
(98, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'reply', '/images/avatar/lu_xun.jpg', 28, '\n\n关于拉娜的经济问题', 297, '2023-06-26 10:57:12', '2023-06-26 10:57:12'),
(99, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'prompt', '/images/avatar/user.png', 28, '', 23, '2023-06-26 11:57:32', '2023-06-26 11:57:32'),
(100, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'reply', '/images/avatar/lu_xun.jpg', 28, '', 366, '2023-06-26 11:57:34', '2023-06-26 11:57:34'),
(101, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'prompt', '/images/avatar/user.png', 28, '', 22, '2023-06-26 12:10:23', '2023-06-26 12:10:23'),
(102, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'reply', '/images/avatar/lu_xun.jpg', 28, '', 87, '2023-06-26 12:10:24', '2023-06-26 12:10:24'),
(103, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'prompt', '/images/avatar/user.png', 28, '', 32, '2023-06-26 12:10:29', '2023-06-26 12:10:29'),
(104, 4, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 'reply', '/images/avatar/lu_xun.jpg', 28, '', 247, '2023-06-26 12:10:33', '2023-06-26 12:10:33'),
(105, 4, '0acd67e6-6442-4056-b10b-c7e0926ceccf', 'prompt', '/images/avatar/user.png', 35, '', 16, '2023-06-26 15:14:30', '2023-06-26 15:14:30'),
(106, 4, '0acd67e6-6442-4056-b10b-c7e0926ceccf', 'reply', '/images/avatar/girl_friend.jpg', 35, '\n\n至于男人是否都喜欢温柔的女生', 271, '2023-06-26 15:14:32', '2023-06-26 15:14:32'),
(107, 4, 'f6623cc0-e873-4566-9d9d-854dcf08492d', 'prompt', '/images/avatar/user.png', 1, 'hello', 1, '2023-06-26 15:24:59', '2023-06-26 15:24:59'),
(108, 4, 'f6623cc0-e873-4566-9d9d-854dcf08492d', 'reply', '/images/avatar/gpt.png', 1, 'Hello! How may I assist you today?', 9, '2023-06-26 15:25:01', '2023-06-26 15:25:01'),
(109, 4, '338f78b2-2c98-4193-aced-93ea8cf29106', 'prompt', '/images/avatar/user.png', 1, '', 0, '2023-06-26 15:46:50', '2023-06-26 15:46:50'),
(110, 4, '338f78b2-2c98-4193-aced-93ea8cf29106', 'reply', '/images/avatar/gpt.png', 1, '', 0, '2023-06-26 15:46:52', '2023-06-26 15:46:52'),
(111, 4, '6413088d-d6ef-4b43-bffd-ca063d4d941a', 'prompt', '/images/avatar/user.png', 1, ' GPT4 GPT3', 11, '2023-06-26 16:30:24', '2023-06-26 16:30:24'),
(112, 4, '6413088d-d6ef-4b43-bffd-ca063d4d941a', 'reply', '/images/avatar/gpt.png', 1, ' GPT-3OpenAI的一个自然语言处理模型', 20, '2023-06-26 16:30:26', '2023-06-26 16:30:26'),
(113, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'prompt', 'http://localhost:5678/static/upload/2023/6/1687834512597.png', 1, '', 11, '2023-06-27 10:57:06', '2023-06-27 10:57:06'),
(114, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'reply', '/images/avatar/gpt.png', 1, 'AI语言模型', 45, '2023-06-27 10:57:08', '2023-06-27 10:57:08'),
(115, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'prompt', 'http://localhost:5678/static/upload/2023/6/1687834512597.png', 1, '', 20, '2023-06-27 11:18:33', '2023-06-27 11:18:33'),
(116, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'reply', '/images/avatar/gpt.png', 1, 'AI语言模型', 140, '2023-06-27 11:18:34', '2023-06-27 11:18:34'),
(117, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'prompt', 'http://localhost:5678/static/upload/2023/6/1687834512597.png', 1, '', 11, '2023-06-27 11:21:26', '2023-06-27 11:21:26'),
(118, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'reply', '/images/avatar/gpt.png', 1, 'AI语言模型', 109, '2023-06-27 11:21:28', '2023-06-27 11:21:28'),
(119, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'prompt', 'http://localhost:5678/static/upload/2023/6/1687834512597.png', 1, '', 26, '2023-06-27 11:21:49', '2023-06-27 11:21:49'),
(120, 4, 'd709cb54-5c27-44e0-a576-46837577ac7a', 'reply', '/images/avatar/gpt.png', 1, 'AI语言模型仿', 183, '2023-06-27 11:21:50', '2023-06-27 11:21:50'),
(121, 4, 'af6e0a83-c8c9-4e57-b609-a75d091df25b', 'prompt', 'http://localhost:5678/static/upload/2023/6/1687839034317.png', 1, '{\n \"data\": {\n \"交易状态\": \"银行受理成功\",\n \"付款人\": {\n \"全称\": \"东莞市百胜凯塑胶原料有限公司\",\n \"开户行\": \"中国建设银行股份有限公奇东莞樟木买振兴支行\",\n \"账号\": \"44050177925200000536\"\n },\n \"凭证号\": \"104751121652\",\n \"大写金额\": \"伍拾染柒万玖仟陆佰元整\",\n \"小写金额\": \"¥579,600.00元\",\n \"币别\": \"人民币\",\n \"收款人\": {\n \"全称\": \"东莞市盟大数据科技有限公司\",\n \"开户行\": \"中国工商银行股份有限公司东莞东城支行\",\n \"账号\": \"2010020909200321458\"\n },\n \"日期\": \"2023-02-1415:43\",\n \"用途\": \"货款\",\n \"验证码\": \"17898488862290\"\n }', 0, '2023-06-27 13:31:41', '2023-06-27 13:31:41'),
(122, 4, 'af6e0a83-c8c9-4e57-b609-a75d091df25b', 'reply', '/images/avatar/gpt.png', 1, ': \n付款人户名: \n付款人账号: 44050177925200000536\n收款人开户行: \n收款人户名: \n收款人账号: 2010020909200321458\n交易金额: 579,600.00\n业务唯一标识号: 104751121652\n交易日期: 2023-02-14 15:43', 0, '2023-06-27 13:31:44', '2023-06-27 13:31:44'),
(123, 4, 'af6e0a83-c8c9-4e57-b609-a75d091df25b', 'prompt', 'http://localhost:5678/static/upload/2023/6/1687839034317.png', 1, '使', 0, '2023-06-27 13:32:10', '2023-06-27 13:32:10'),
(124, 4, 'af6e0a83-c8c9-4e57-b609-a75d091df25b', 'reply', '/images/avatar/gpt.png', 1, '| | |\n|---------|-------------------------------------|\n| | |\n| | |\n| | 44050177925200000536 |\n| | |\n| | |\n| | 2010020909200321458 |\n| | 579,600.00 |\n| | 104751121652 |\n| | 2023-02-14 15:43 |', 0, '2023-06-27 13:32:13', '2023-06-27 13:32:13'),
(125, 4, 'a09f77b6-7bbc-48cf-b2cc-99a4e0879c19', 'prompt', 'http://localhost:5678/static/upload/2023/6/1687839034317.png', 1, 'hello', 0, '2023-06-27 13:35:47', '2023-06-27 13:35:47'),
(126, 4, 'a09f77b6-7bbc-48cf-b2cc-99a4e0879c19', 'reply', '/images/avatar/gpt.png', 1, 'Hello! How can I assist you today?', 0, '2023-06-27 13:35:48', '2023-06-27 13:35:48'),
(127, 4, 'a09f77b6-7bbc-48cf-b2cc-99a4e0879c19', 'prompt', 'http://localhost:5678/static/upload/2023/6/1687839034317.png', 1, '', 2, '2023-06-27 13:44:53', '2023-06-27 13:44:53'),
(128, 4, 'a09f77b6-7bbc-48cf-b2cc-99a4e0879c19', 'reply', '/images/avatar/gpt.png', 1, '! ', 19, '2023-06-27 13:44:55', '2023-06-27 13:44:55'),
(129, 4, 'af6e0a83-c8c9-4e57-b609-a75d091df25b', 'prompt', 'http://localhost:5678/static/upload/2023/6/1687839034317.png', 1, '', 20, '2023-06-27 13:47:05', '2023-06-27 13:47:05'),
(130, 4, 'af6e0a83-c8c9-4e57-b609-a75d091df25b', 'reply', '/images/avatar/gpt.png', 1, ': \n付款人户名: \n付款人账号: 44050177925200000536\n收款人开户行: \n收款人户名: \n收款人账号: 2010020909200321458\n交易金额: 579,600.00\n业务唯一标识号: 104751121652\n交易日期: 2023-02-1415:43', 191, '2023-06-27 13:47:06', '2023-06-27 13:47:06'),
(131, 4, 'af6e0a83-c8c9-4e57-b609-a75d091df25b', 'prompt', 'http://localhost:5678/static/upload/2023/6/1687839034317.png', 1, '', 9, '2023-06-27 13:47:27', '2023-06-27 13:47:27'),
(132, 4, 'af6e0a83-c8c9-4e57-b609-a75d091df25b', 'reply', '/images/avatar/gpt.png', 1, ': \n付款人户名: \n付款人账号: 44050177925200000536\n收款人开户行: \n收款人户名: \n收款人账号: 2010020909200321458\n交易金额: 579,600.00\n业务唯一标识号: 104751121652\n交易日期: 2023-02-1415:43', 191, '2023-06-27 13:47:29', '2023-06-27 13:47:29');
-- --------------------------------------------------------
--
@@ -207,42 +78,6 @@ CREATE TABLE `chatgpt_chat_items` (
`updated_at` datetime NOT NULL COMMENT '更新时间'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户会话列表';
--
-- 转存表中的数据 `chatgpt_chat_items`
--
INSERT INTO `chatgpt_chat_items` (`id`, `chat_id`, `user_id`, `role_id`, `title`, `model`, `created_at`, `updated_at`) VALUES
(13, 'cd4e1bfe-19aa-4379-afff-377bcbda9080', 4, 1, ' C ', 'gpt-3.5-turbo', '2023-06-07 06:46:04', '2023-06-07 06:46:04'),
(14, '7f4e6823-ef15-489b-830c-6482f6bce4cd', 4, 1, '', 'gpt-3.5-turbo', '2023-06-07 06:56:30', '2023-06-07 06:56:30'),
(15, 'ad803ca5-5543-406a-b27d-53021052bd86', 4, 1, '', 'gpt-3.5-turbo', '2023-06-07 07:00:11', '2023-06-07 07:00:11'),
(16, 'aba82444-4bc0-4107-b1db-dc14ad368f64', 4, 1, '5', 'gpt-3.5-turbo', '2023-06-07 07:02:44', '2023-06-07 07:02:44'),
(19, '60d6619d-f6dc-449d-b7bd-f493d5b0ee7f', 4, 24, '使 Go http ', 'gpt-3.5-turbo', '2023-06-07 07:14:04', '2023-06-07 07:14:04'),
(20, '9df8deaa-5c05-45d5-b92f-4309db967d79', 4, 35, '', 'gpt-3.5-turbo', '2023-06-08 06:00:05', '2023-06-08 06:00:05'),
(21, 'eb04f0af-73a8-401a-972e-ed508bb97082', 4, 36, '', 'gpt-3.5-turbo', '2023-06-08 06:01:43', '2023-06-08 06:01:43'),
(22, '38a1698b-d421-454c-b2bd-5eb5bd16f7c3', 4, 1, '', 'gpt-3.5-turbo', '2023-06-09 05:55:43', '2023-06-09 05:55:43'),
(23, '8a5b2809-b540-4eb7-bcbc-0f467e6127ae', 4, 36, 'hello', 'gpt-3.5-turbo', '2023-06-09 06:11:50', '2023-06-09 06:11:50'),
(24, 'ee0a6c64-0a62-4a5e-87da-708692d14034', 4, 1, 'hello', 'gpt-3.5-turbo', '2023-06-09 06:43:46', '2023-06-09 06:43:46'),
(25, '4404a8f4-562a-4973-b69d-9061839a249a', 4, 25, '', 'gpt-3.5-turbo', '2023-06-09 06:44:26', '2023-06-09 06:44:26'),
(26, '0251becf-eab7-4451-932f-e6f54547a530', 4, 26, '', 'gpt-3.5-turbo', '2023-06-09 06:45:50', '2023-06-09 06:45:50'),
(27, '748bfcee-d204-4510-ab0c-4341af1cf3b6', 4, 28, '', 'gpt-3.5-turbo', '2023-06-09 06:47:08', '2023-06-09 06:47:08'),
(28, 'f245f994-35bc-4c6c-8db0-87be5987465c', 4, 30, 'Rock Yang', 'gpt-3.5-turbo', '2023-06-09 06:49:29', '2023-06-09 06:49:29'),
(29, '6c8f28d2-fd2a-4146-bc99-88138331ea09', 4, 28, 'hello', 'gpt-3.5-turbo', '2023-06-09 06:50:51', '2023-06-09 06:50:51'),
(30, '219c465b-93ff-4b1f-b191-45c478af301c', 4, 25, '', 'gpt-3.5-turbo', '2023-06-09 06:54:54', '2023-06-09 06:54:54'),
(31, 'dcdbb443-38f6-4394-9157-576350c56818', 4, 27, '', 'gpt-3.5-turbo', '2023-06-09 06:55:24', '2023-06-09 06:55:24'),
(32, 'b0001927-4ff1-4e8c-be56-44ecd8176643', 4, 24, '', 'gpt-3.5-turbo', '2023-06-09 06:55:46', '2023-06-09 06:55:46'),
(33, '9585a183-0774-45e7-ae6c-801b942d11e7', 4, 24, ' js socket ', 'gpt-3.5-turbo', '2023-06-09 07:04:42', '2023-06-09 07:04:42'),
(36, '4ec38193-5572-45b4-874b-94f9054af00b', 4, 1, 'hello', 'gpt-3.5-turbo', '2023-06-09 20:14:04', '2023-06-09 20:14:04'),
(37, '6413088d-d6ef-4b43-bffd-ca063d4d941a', 4, 1, '', 'gpt-3.5-turbo', '2023-06-09 20:15:26', '2023-06-09 20:15:26'),
(38, 'e5e6d499-7716-48c7-87cc-0b26734c51ae', 4, 24, '', 'gpt-3.5-turbo', '2023-06-11 10:22:42', '2023-06-11 10:22:42'),
(39, 'f7aa0fa1-4cc5-4212-b823-eb5b88844c31', 4, 27, '', 'gpt-3.5-turbo', '2023-06-11 10:24:32', '2023-06-11 10:24:32'),
(40, 'ecb752e8-86ae-4989-897e-5b7ed331cb68', 4, 24, ' Excel ', 'gpt-3.5-turbo', '2023-06-12 15:51:10', '2023-06-12 15:51:10'),
(41, 'ea9d399a-6e62-4bf6-a0c0-c73faa8dcace', 4, 1, 'what fuck this meaning', 'gpt-3.5-turbo', '2023-06-13 09:12:04', '2023-06-13 09:12:04'),
(42, '89f4d526-fda1-401e-a946-cd3b1bc30cf2', 4, 28, '', 'gpt-3.5-turbo', '2023-06-13 10:00:28', '2023-06-13 10:00:28'),
(56, '0acd67e6-6442-4056-b10b-c7e0926ceccf', 4, 35, '', 'gpt-3.5-turbo', '2023-06-15 10:12:12', '2023-06-15 10:12:12'),
(58, 'd8e61f33-9287-4d63-b28f-b6e6aa891bb5', 9, 1, '', 'gpt-3.5-turbo', '2023-06-15 11:13:57', '2023-06-15 11:13:57'),
(59, 'd709cb54-5c27-44e0-a576-46837577ac7a', 4, 1, '', 'gpt-3.5-turbo', '2023-06-16 12:19:30', '2023-06-16 12:19:30'),
(63, 'af6e0a83-c8c9-4e57-b609-a75d091df25b', 4, 1, '...', 'gpt-3.5-turbo-16k', '2023-06-27 13:31:50', '2023-06-27 13:31:50');
-- --------------------------------------------------------
--
@@ -304,8 +139,26 @@ CREATE TABLE `chatgpt_configs` (
--
INSERT INTO `chatgpt_configs` (`id`, `marker`, `config_json`) VALUES
(1, 'system', '{\"admin_title\":\"ChatGPT-控制台\",\"init_calls\":1000,\"models\":[\"gpt-3.5-turbo\",\"gpt-3.5-turbo-16k\",\"gpt-3.5-turbo-0613\",\"gpt-3.5-turbo-16k-0613\",\"gpt-4\",\"gpt-4-0613\",\"gpt-4-32k\",\"gpt-4-32k-0613\"],\"title\":\"ChatGPT-智能助手V3\"}'),
(2, 'chat', '{\"api_url\":\"https://api.openai.com/v1/chat/completions\",\"enable_context\":true,\"enable_history\":true,\"max_tokens\":2048,\"model\":\"gpt-3.5-turbo\",\"temperature\":1}');
(1, 'system', '{\"admin_title\":\"ChatGPT-控制台\",\"init_calls\":1000,\"models\":[\"gpt-3.5-turbo\",\"gpt-3.5-turbo-16k\",\"gpt-3.5-turbo-0613\",\"gpt-3.5-turbo-16k-0613\",\"gpt-4\",\"gpt-4-0613\",\"gpt-4-32k\",\"gpt-4-32k-0613\"],\"title\":\"ChatGPT-智能助手V3\",\"user_init_calls\":10}'),
(2, 'chat', '{\"api_url\":\"https://api.openai.com/v1/chat/completions\",\"context_deep\":4,\"enable_context\":true,\"enable_history\":true,\"max_tokens\":2048,\"model\":\"gpt-3.5-turbo\",\"temperature\":1}');
-- --------------------------------------------------------
--
-- 表的结构 `chatgpt_rewards`
--
DROP TABLE IF EXISTS `chatgpt_rewards`;
CREATE TABLE `chatgpt_rewards` (
`id` int NOT NULL,
`user_id` int NOT NULL COMMENT '用户 ID',
`tx_id` char(36) NOT NULL COMMENT '交易 ID',
`amount` decimal(10,2) NOT NULL COMMENT '打赏金额',
`remark` varchar(80) NOT NULL COMMENT '备注',
`status` tinyint(1) NOT NULL COMMENT '核销状态0未核销1已核销',
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户打赏';
-- --------------------------------------------------------
@@ -317,6 +170,7 @@ DROP TABLE IF EXISTS `chatgpt_users`;
CREATE TABLE `chatgpt_users` (
`id` int NOT NULL,
`username` varchar(30) NOT NULL COMMENT '用户名',
`mobile` char(11) NOT NULL COMMENT '手机号码',
`password` char(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '密码',
`nickname` varchar(30) NOT NULL COMMENT '昵称',
`avatar` varchar(100) NOT NULL COMMENT '头像',
@@ -337,11 +191,8 @@ CREATE TABLE `chatgpt_users` (
-- 转存表中的数据 `chatgpt_users`
--
INSERT INTO `chatgpt_users` (`id`, `username`, `password`, `nickname`, `avatar`, `salt`, `tokens`, `calls`, `expired_time`, `status`, `chat_config_json`, `chat_roles_json`, `last_login_at`, `last_login_ip`, `created_at`, `updated_at`) VALUES
(4, 'geekmaster', 'ccc3fb7ab61b8b5d096a4a166ae21d121fc38c71bbd1be6173d9ab973214a63b', '@', 'http://localhost:5678/static/upload/2023/6/1687839034317.png', 'ueedue5l', 0, 940, 1688083200, 1, '{\"model\":\"gpt-3.5-turbo-0613\",\"temperature\":1,\"max_tokens\":2048,\"enable_context\":true,\"enable_history\":true,\"api_key\":\"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\"}', '[\"elon_musk\",\"girl_friend\",\"lu_xun\",\"red_book\",\"psychiatrist\",\"teacher\",\"translator\",\"weekly_report\",\"artist\",\"dou_yin\",\"good_comment\",\"english_trainer\",\"gpt\",\"kong_zi\",\"programmer\",\"seller\",\"steve_jobs\"]', 1687844693, '::1', '2023-06-12 16:47:17', '2023-06-27 13:44:53'),
(8, '11111111', '415208d99372801c4b3c22740fcfb51e4ba58c6268dd1cc6e7173821fba7e907', '@870902', '/images/avatar/user.png', 'k438y90k', 0, 1000, 1687593600, 1, '{\"model\":\"\",\"temperature\":1,\"max_tokens\":2048,\"enable_context\":true,\"enable_history\":true,\"api_key\":\"\"}', '[\"red_book\",\"seller\",\"steve_jobs\",\"teacher\",\"elon_musk\",\"programmer\",\"girl_friend\",\"psychiatrist\",\"dou_yin\",\"english_trainer\",\"kong_zi\",\"translator\",\"artist\",\"gpt\",\"weekly_report\",\"good_comment\",\"lu_xun\"]', 0, '', '2023-06-15 10:01:42', '2023-06-26 12:50:55'),
(9, '22222222', '2871c55519351ce39d571d65f1a4d33aaaf4ce4da5727ab753b4c9875cadfb37', '', '/images/avatar/user.png', 'han5xeu9', 0, 995, 1688083200, 0, '{\"model\":\"\",\"temperature\":1,\"max_tokens\":2048,\"enable_context\":true,\"enable_history\":true,\"api_key\":\"\"}', '[\"red_book\",\"artist\",\"girl_friend\",\"good_comment\",\"gpt\",\"lu_xun\",\"steve_jobs\",\"teacher\",\"kong_zi\",\"psychiatrist\",\"seller\",\"programmer\",\"translator\",\"weekly_report\",\"dou_yin\",\"elon_musk\",\"english_trainer\"]', 1686798874, '::1', '2023-06-15 10:03:43', '2023-06-26 12:50:55'),
(11, '33333333', 'c5a2756e6890a198f4d591db39e2abd0953f3f48790c591ac07ce23ec3842d6c', '@521644', '/images/avatar/user.png', 'c7mpdtnv', 0, 1000, 0, 0, '{\"model\":\"gpt-3.5-turbo\",\"temperature\":1,\"max_tokens\":2048,\"enable_context\":true,\"enable_history\":true,\"api_key\":\"\"}', '[\"elon_musk\",\"english_trainer\",\"good_comment\",\"psychiatrist\",\"steve_jobs\",\"translator\",\"girl_friend\",\"lu_xun\",\"seller\",\"teacher\",\"dou_yin\",\"gpt\",\"programmer\",\"weekly_report\",\"artist\",\"kong_zi\",\"red_book\"]', 1686799181, '::1', '2023-06-15 11:19:30', '2023-06-26 12:50:55');
INSERT INTO `chatgpt_users` (`id`, `username`, `mobile`, `password`, `nickname`, `avatar`, `salt`, `tokens`, `calls`, `expired_time`, `status`, `chat_config_json`, `chat_roles_json`, `last_login_at`, `last_login_ip`, `created_at`, `updated_at`) VALUES
(4, 'geekmaster', '18575670126', 'ccc3fb7ab61b8b5d096a4a166ae21d121fc38c71bbd1be6173d9ab973214a63b', '极客学长@本人', 'http://localhost:5678/static/upload/2023/6/1687839034317.png', 'ueedue5l', 2754, 921, 1727685036, 1, '{\"model\":\"gpt-3.5-turbo-0613\",\"temperature\":1,\"max_tokens\":2048,\"enable_context\":true,\"enable_history\":true,\"api_key\":\"\"}', '[\"elon_musk\",\"girl_friend\",\"lu_xun\",\"red_book\",\"psychiatrist\",\"teacher\",\"translator\",\"weekly_report\",\"artist\",\"dou_yin\",\"good_comment\",\"english_trainer\",\"gpt\",\"kong_zi\",\"programmer\",\"seller\",\"steve_jobs\"]', 1690264062, '::1', '2023-06-12 16:47:17', '2023-07-25 13:47:43');
-- --------------------------------------------------------
@@ -360,152 +211,24 @@ CREATE TABLE `chatgpt_user_login_logs` (
`updated_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户登录日志';
-- --------------------------------------------------------
--
-- 转存表中的数据 `chatgpt_user_login_logs`
-- 表的结构 `test`
--
INSERT INTO `chatgpt_user_login_logs` (`id`, `user_id`, `username`, `login_ip`, `login_address`, `created_at`, `updated_at`) VALUES
(1, 4, 'monda', '::1', '', '2023-06-13 18:45:46', '2023-06-13 18:45:46'),
(2, 4, 'monda', '::1', '::1', '2023-06-13 18:46:52', '2023-06-13 18:46:52'),
(3, 4, 'monda', '::1', '', '2023-06-13 18:47:44', '2023-06-13 18:47:44'),
(4, 4, 'monda', '::1', '', '2023-06-13 18:51:54', '2023-06-13 18:51:54'),
(5, 4, 'monda', '::1', '', '2023-06-13 18:52:51', '2023-06-13 18:52:51'),
(6, 4, 'monda', '::1', '', '2023-06-13 18:53:51', '2023-06-13 18:53:51'),
(7, 4, 'monda', '::1', '', '2023-06-13 18:57:25', '2023-06-13 18:57:25'),
(8, 4, 'monda', '::1', '', '2023-06-14 10:16:58', '2023-06-14 10:16:58'),
(9, 4, 'monda', '::1', '', '2023-06-14 10:21:57', '2023-06-14 10:21:57'),
(10, 4, 'monda', '::1', '', '2023-06-14 11:16:18', '2023-06-14 11:16:18'),
(11, 4, 'monda', '::1', '', '2023-06-14 11:35:15', '2023-06-14 11:35:15'),
(12, 4, 'monda', '::1', '', '2023-06-14 11:53:38', '2023-06-14 11:53:38'),
(13, 4, 'monda', '::1', '', '2023-06-14 12:01:55', '2023-06-14 12:01:55'),
(14, 4, 'monda', '::1', '', '2023-06-14 12:05:03', '2023-06-14 12:05:03'),
(15, 4, 'monda', '::1', '', '2023-06-14 15:42:47', '2023-06-14 15:42:47'),
(16, 4, 'monda', '::1', '', '2023-06-14 16:21:37', '2023-06-14 16:21:37'),
(17, 4, 'monda', '::1', '', '2023-06-14 16:51:20', '2023-06-14 16:51:20'),
(18, 4, 'monda', '::1', '', '2023-06-14 17:30:47', '2023-06-14 17:30:47'),
(19, 4, 'monda', '::1', '', '2023-06-14 17:32:48', '2023-06-14 17:32:48'),
(20, 4, 'monda', '::1', '', '2023-06-14 19:45:10', '2023-06-14 19:45:10'),
(21, 4, 'monda', '::1', '', '2023-06-14 20:23:23', '2023-06-14 20:23:23'),
(22, 4, 'monda', '::1', '', '2023-06-14 20:25:00', '2023-06-14 20:25:00'),
(23, 4, 'monda', '::1', '', '2023-06-15 06:07:49', '2023-06-15 06:07:49'),
(24, 4, 'monda', '::1', '', '2023-06-15 06:15:26', '2023-06-15 06:15:26'),
(25, 4, 'monda', '::1', '', '2023-06-15 07:02:41', '2023-06-15 07:02:41'),
(26, 4, 'monda', '::1', '', '2023-06-15 07:03:16', '2023-06-15 07:03:16'),
(27, 4, 'monda', '::1', '', '2023-06-15 07:04:13', '2023-06-15 07:04:13'),
(28, 4, 'monda', '::1', '', '2023-06-15 07:04:24', '2023-06-15 07:04:24'),
(29, 4, 'monda', '::1', '', '2023-06-15 07:04:24', '2023-06-15 07:04:24'),
(30, 4, 'monda', '::1', '', '2023-06-15 07:08:13', '2023-06-15 07:08:13'),
(31, 4, 'monda', '::1', '', '2023-06-15 07:08:20', '2023-06-15 07:08:20'),
(32, 4, 'monda', '::1', '', '2023-06-15 07:08:20', '2023-06-15 07:08:20'),
(33, 4, 'monda', '::1', '', '2023-06-15 07:08:20', '2023-06-15 07:08:20'),
(34, 4, 'monda', '::1', '', '2023-06-15 07:11:00', '2023-06-15 07:11:00'),
(35, 4, 'monda', '::1', '', '2023-06-15 07:11:06', '2023-06-15 07:11:06'),
(36, 4, 'monda', '::1', '', '2023-06-15 07:11:06', '2023-06-15 07:11:06'),
(37, 4, 'monda', '::1', '', '2023-06-15 07:11:06', '2023-06-15 07:11:06'),
(38, 4, 'monda', '::1', '', '2023-06-15 07:11:06', '2023-06-15 07:11:06'),
(39, 4, 'monda', '::1', '', '2023-06-15 07:14:44', '2023-06-15 07:14:44'),
(40, 4, 'monda', '::1', '', '2023-06-15 07:14:58', '2023-06-15 07:14:58'),
(41, 4, 'monda', '::1', '', '2023-06-15 07:14:58', '2023-06-15 07:14:58'),
(42, 4, 'monda', '::1', '', '2023-06-15 07:14:58', '2023-06-15 07:14:58'),
(43, 4, 'monda', '::1', '', '2023-06-15 07:14:58', '2023-06-15 07:14:58'),
(44, 4, 'monda', '::1', '', '2023-06-15 07:14:58', '2023-06-15 07:14:58'),
(45, 4, 'monda', '::1', '', '2023-06-15 09:20:28', '2023-06-15 09:20:28'),
(46, 4, 'geekmaster', '::1', '', '2023-06-15 09:25:08', '2023-06-15 09:25:08'),
(47, 4, 'geekmaster', '::1', '', '2023-06-15 09:43:45', '2023-06-15 09:43:45'),
(48, 4, 'geekmaster', '::1', '', '2023-06-15 09:44:27', '2023-06-15 09:44:27'),
(49, 4, 'geekmaster', '::1', '', '2023-06-15 10:10:15', '2023-06-15 10:10:15'),
(50, 9, '22222222', '::1', '', '2023-06-15 10:10:40', '2023-06-15 10:10:40'),
(51, 4, 'geekmaster', '::1', '', '2023-06-15 10:10:53', '2023-06-15 10:10:53'),
(52, 4, 'geekmaster', '::1', '', '2023-06-15 10:10:53', '2023-06-15 10:10:53'),
(53, 4, 'geekmaster', '::1', '', '2023-06-15 10:10:53', '2023-06-15 10:10:53'),
(54, 9, '22222222', '::1', '', '2023-06-15 10:10:53', '2023-06-15 10:10:53'),
(55, 4, 'geekmaster', '::1', '', '2023-06-15 10:11:22', '2023-06-15 10:11:22'),
(56, 4, 'geekmaster', '::1', '', '2023-06-15 10:11:22', '2023-06-15 10:11:22'),
(57, 4, 'geekmaster', '::1', '', '2023-06-15 10:11:22', '2023-06-15 10:11:22'),
(58, 9, '22222222', '::1', '', '2023-06-15 10:11:22', '2023-06-15 10:11:22'),
(59, 4, 'geekmaster', '::1', '', '2023-06-15 10:12:03', '2023-06-15 10:12:03'),
(60, 4, 'geekmaster', '::1', '', '2023-06-15 10:12:03', '2023-06-15 10:12:03'),
(61, 4, 'geekmaster', '::1', '', '2023-06-15 10:12:03', '2023-06-15 10:12:03'),
(62, 9, '22222222', '::1', '', '2023-06-15 10:12:03', '2023-06-15 10:12:03'),
(63, 9, '22222222', '::1', '', '2023-06-15 11:11:58', '2023-06-15 11:11:58'),
(64, 9, '22222222', '::1', '', '2023-06-15 11:13:55', '2023-06-15 11:13:55'),
(65, 4, 'geekmaster', '::1', '', '2023-06-15 11:14:03', '2023-06-15 11:14:03'),
(66, 9, '22222222', '::1', '', '2023-06-15 11:14:35', '2023-06-15 11:14:35'),
(67, 10, '33333333', '::1', '', '2023-06-15 11:18:14', '2023-06-15 11:18:14'),
(68, 11, '33333333', '::1', '', '2023-06-15 11:19:42', '2023-06-15 11:19:42'),
(69, 4, 'geekmaster', '127.0.0.1', '0-0-IP', '2023-06-15 12:09:24', '2023-06-15 12:09:24'),
(70, 4, 'geekmaster', '::1', '', '2023-06-15 14:06:53', '2023-06-15 14:06:53'),
(71, 4, 'geekmaster', '127.0.0.1', '0-0-IP', '2023-06-15 16:00:56', '2023-06-15 16:00:56'),
(72, 4, 'geekmaster', '127.0.0.1', '0-0-IP', '2023-06-15 16:07:06', '2023-06-15 16:07:06'),
(73, 4, 'geekmaster', '::1', '', '2023-06-16 09:32:32', '2023-06-16 09:32:32'),
(74, 4, 'geekmaster', '::1', '', '2023-06-16 09:45:57', '2023-06-16 09:45:57'),
(75, 4, 'geekmaster', '127.0.0.1', '0-0-IP', '2023-06-16 09:48:13', '2023-06-16 09:48:13'),
(76, 4, 'geekmaster', '::1', '', '2023-06-16 09:48:33', '2023-06-16 09:48:33'),
(77, 4, 'geekmaster', '::1', '', '2023-06-16 10:22:12', '2023-06-16 10:22:12'),
(78, 4, 'geekmaster', '::1', '', '2023-06-16 11:17:13', '2023-06-16 11:17:13'),
(79, 4, 'geekmaster', '::1', '', '2023-06-16 11:40:23', '2023-06-16 11:40:23'),
(80, 4, 'geekmaster', '::1', '', '2023-06-16 13:36:14', '2023-06-16 13:36:14'),
(81, 4, 'geekmaster', '::1', '', '2023-06-16 15:27:10', '2023-06-16 15:27:10'),
(82, 4, 'geekmaster', '::1', '', '2023-06-16 15:27:23', '2023-06-16 15:27:23'),
(83, 4, 'geekmaster', '::1', '', '2023-06-16 15:27:26', '2023-06-16 15:27:26'),
(84, 4, 'geekmaster', '::1', '', '2023-06-16 15:27:33', '2023-06-16 15:27:33'),
(85, 4, 'geekmaster', '::1', '', '2023-06-16 15:27:41', '2023-06-16 15:27:41'),
(86, 4, 'geekmaster', '::1', '', '2023-06-16 15:27:42', '2023-06-16 15:27:42'),
(87, 4, 'geekmaster', '::1', '', '2023-06-16 15:27:42', '2023-06-16 15:27:42'),
(88, 4, 'geekmaster', '::1', '', '2023-06-16 15:27:43', '2023-06-16 15:27:43'),
(89, 4, 'geekmaster', '::1', '', '2023-06-16 15:27:43', '2023-06-16 15:27:43'),
(90, 4, 'geekmaster', '::1', '', '2023-06-16 15:27:43', '2023-06-16 15:27:43'),
(91, 4, 'geekmaster', '::1', '', '2023-06-16 15:28:12', '2023-06-16 15:28:12'),
(92, 4, 'geekmaster', '::1', '', '2023-06-16 15:28:49', '2023-06-16 15:28:49'),
(93, 4, 'geekmaster', '::1', '', '2023-06-16 15:29:20', '2023-06-16 15:29:20'),
(94, 4, 'geekmaster', '::1', '', '2023-06-16 15:30:18', '2023-06-16 15:30:18'),
(95, 4, 'geekmaster', '::1', '', '2023-06-16 16:17:22', '2023-06-16 16:17:22'),
(96, 4, 'geekmaster', '::1', '', '2023-06-16 16:22:13', '2023-06-16 16:22:13'),
(97, 4, 'geekmaster', '::1', '', '2023-06-16 16:48:44', '2023-06-16 16:48:44'),
(98, 4, 'geekmaster', '::1', '', '2023-06-16 17:13:31', '2023-06-16 17:13:31'),
(99, 4, 'geekmaster', '::1', '', '2023-06-16 17:16:44', '2023-06-16 17:16:44'),
(100, 4, 'geekmaster', '::1', '', '2023-06-16 17:18:16', '2023-06-16 17:18:16'),
(101, 4, 'geekmaster', '::1', '', '2023-06-16 17:19:38', '2023-06-16 17:19:38'),
(102, 4, 'geekmaster', '::1', '', '2023-06-16 17:20:40', '2023-06-16 17:20:40'),
(103, 4, 'geekmaster', '::1', '', '2023-06-16 17:23:15', '2023-06-16 17:23:15'),
(104, 4, 'geekmaster', '::1', '', '2023-06-16 17:26:33', '2023-06-16 17:26:33'),
(105, 4, 'geekmaster', '::1', '', '2023-06-16 17:27:12', '2023-06-16 17:27:12'),
(106, 4, 'geekmaster', '::1', '', '2023-06-16 17:33:39', '2023-06-16 17:33:39'),
(107, 4, 'geekmaster', '::1', '', '2023-06-19 10:22:31', '2023-06-19 10:22:31'),
(108, 4, 'geekmaster', '::1', '', '2023-06-19 10:37:26', '2023-06-19 10:37:26'),
(109, 4, 'geekmaster', '::1', '', '2023-06-19 11:08:18', '2023-06-19 11:08:18'),
(110, 4, 'geekmaster', '::1', '', '2023-06-19 15:36:17', '2023-06-19 15:36:17'),
(111, 4, 'geekmaster', '::1', '', '2023-06-20 08:51:06', '2023-06-20 08:51:06'),
(112, 4, 'geekmaster', '::1', '', '2023-06-21 10:11:54', '2023-06-21 10:11:54'),
(113, 4, 'geekmaster', '::1', '', '2023-06-21 10:12:49', '2023-06-21 10:12:49'),
(114, 4, 'geekmaster', '::1', '', '2023-06-21 10:16:53', '2023-06-21 10:16:53'),
(115, 4, 'geekmaster', '::1', '', '2023-06-21 10:17:17', '2023-06-21 10:17:17'),
(116, 4, 'geekmaster', '::1', '', '2023-06-21 10:19:40', '2023-06-21 10:19:40'),
(117, 4, 'geekmaster', '::1', '', '2023-06-21 10:32:01', '2023-06-21 10:32:01'),
(118, 4, 'geekmaster', '::1', '', '2023-06-21 13:31:38', '2023-06-21 13:31:38'),
(119, 4, 'geekmaster', '::1', '', '2023-06-21 14:21:22', '2023-06-21 14:21:22'),
(120, 4, 'geekmaster', '::1', '', '2023-06-25 09:24:08', '2023-06-25 09:24:08'),
(121, 4, 'geekmaster', '::1', '', '2023-06-25 09:30:15', '2023-06-25 09:30:15'),
(122, 4, 'geekmaster', '::1', '', '2023-06-25 12:40:02', '2023-06-25 12:40:02'),
(123, 4, 'geekmaster', '::1', '', '2023-06-25 12:40:41', '2023-06-25 12:40:41'),
(124, 4, 'geekmaster', '::1', '', '2023-06-25 12:42:10', '2023-06-25 12:42:10'),
(125, 4, 'geekmaster', '::1', '', '2023-06-25 12:47:46', '2023-06-25 12:47:46'),
(126, 4, 'geekmaster', '::1', '', '2023-06-25 12:48:19', '2023-06-25 12:48:19'),
(127, 4, 'geekmaster', '::1', '', '2023-06-25 14:17:08', '2023-06-25 14:17:08'),
(128, 4, 'geekmaster', '::1', '', '2023-06-26 08:23:17', '2023-06-26 08:23:17'),
(129, 4, 'geekmaster', '::1', '', '2023-06-26 15:16:10', '2023-06-26 15:16:10'),
(130, 4, 'geekmaster', '::1', '', '2023-06-26 15:30:19', '2023-06-26 15:30:19'),
(131, 4, 'geekmaster', '::1', '', '2023-06-26 15:30:55', '2023-06-26 15:30:55'),
(132, 4, 'geekmaster', '::1', '', '2023-06-26 15:33:22', '2023-06-26 15:33:22'),
(133, 4, 'geekmaster', '::1', '', '2023-06-26 15:33:38', '2023-06-26 15:33:38'),
(134, 4, 'geekmaster', '::1', '', '2023-06-26 17:45:40', '2023-06-26 17:45:40'),
(135, 4, 'geekmaster', '::1', '', '2023-06-27 08:26:59', '2023-06-27 08:26:59'),
(136, 4, 'geekmaster', '::1', '', '2023-06-27 10:08:32', '2023-06-27 10:08:32'),
(137, 4, 'geekmaster', '::1', '', '2023-06-27 13:31:28', '2023-06-27 13:31:28'),
(138, 4, 'geekmaster', '::1', '', '2023-06-27 13:31:41', '2023-06-27 13:31:41'),
(139, 4, 'geekmaster', '::1', '', '2023-06-27 13:32:10', '2023-06-27 13:32:10'),
(140, 4, 'geekmaster', '::1', '', '2023-06-27 13:44:45', '2023-06-27 13:44:45'),
(141, 4, 'geekmaster', '::1', '', '2023-06-27 13:44:53', '2023-06-27 13:44:53');
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`id` int NOT NULL,
`content` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
--
-- 转存表中的数据 `test`
--
INSERT INTO `test` (`id`, `content`) VALUES
(1, '找到属于你的幸福!💑💛');
--
-- 转储表的索引
@@ -546,6 +269,13 @@ ALTER TABLE `chatgpt_configs`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `marker` (`marker`);
--
-- 表的索引 `chatgpt_rewards`
--
ALTER TABLE `chatgpt_rewards`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `tx_id` (`tx_id`);
--
-- 表的索引 `chatgpt_users`
--
@@ -558,6 +288,12 @@ ALTER TABLE `chatgpt_users`
ALTER TABLE `chatgpt_user_login_logs`
ADD PRIMARY KEY (`id`);
--
-- 表的索引 `test`
--
ALTER TABLE `test`
ADD PRIMARY KEY (`id`);
--
-- 在导出的表使用AUTO_INCREMENT
--
@@ -572,13 +308,13 @@ ALTER TABLE `chatgpt_api_keys`
-- 使用表AUTO_INCREMENT `chatgpt_chat_history`
--
ALTER TABLE `chatgpt_chat_history`
MODIFY `id` bigint NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=133;
MODIFY `id` bigint NOT NULL AUTO_INCREMENT;
--
-- 使用表AUTO_INCREMENT `chatgpt_chat_items`
--
ALTER TABLE `chatgpt_chat_items`
MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=65;
MODIFY `id` int NOT NULL AUTO_INCREMENT;
--
-- 使用表AUTO_INCREMENT `chatgpt_chat_roles`
@@ -592,17 +328,29 @@ ALTER TABLE `chatgpt_chat_roles`
ALTER TABLE `chatgpt_configs`
MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
--
-- 使用表AUTO_INCREMENT `chatgpt_rewards`
--
ALTER TABLE `chatgpt_rewards`
MODIFY `id` int NOT NULL AUTO_INCREMENT;
--
-- 使用表AUTO_INCREMENT `chatgpt_users`
--
ALTER TABLE `chatgpt_users`
MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=81;
MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=83;
--
-- 使用表AUTO_INCREMENT `chatgpt_user_login_logs`
--
ALTER TABLE `chatgpt_user_login_logs`
MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=142;
MODIFY `id` int NOT NULL AUTO_INCREMENT;
--
-- 使用表AUTO_INCREMENT `test`
--
ALTER TABLE `test`
MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

View File

@@ -1 +0,0 @@
ALTER TABLE `chatgpt_users` ADD `mobile` CHAR(11) NOT NULL COMMENT '手机号码' AFTER `username`;

24
database/update.sql Normal file
View File

@@ -0,0 +1,24 @@
ALTER TABLE `chatgpt_chat_history` ADD `use_context` TINYINT(1) NOT NULL COMMENT '是否允许作为上下文语料' AFTER `tokens`;
ALTER TABLE `chatgpt_users` ADD `mobile` CHAR(11) NOT NULL COMMENT '手机号码' AFTER `username`;
CREATE TABLE `chatgpt_rewards` (
`id` int NOT NULL,
`tx_id` char(36) NOT NULL COMMENT '交易 ID',
`amount` decimal(10,2) NOT NULL COMMENT '打赏金额',
`remark` varchar(80) NOT NULL COMMENT '备注',
`status` tinyint(1) NOT NULL COMMENT '核销状态0未核销1已核销',
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户打赏';
ALTER TABLE `chatgpt_rewards`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `tx_id` (`tx_id`);
ALTER TABLE `chatgpt_rewards`
MODIFY `id` int NOT NULL AUTO_INCREMENT;
update chatgpt_users set calls=0
ALTER TABLE `chatgpt_rewards` ADD `user_id` INT(11) NOT NULL COMMENT '用户 ID' AFTER `id`;

View File

@@ -2,29 +2,21 @@
version=$1
# build go api
cd ../api/go
cd ../api
make clean linux
# build web app
cd ../../web
cd ../web
npm run build
cd ../docker
# remove docker image if exists
docker rmi -f registry.cn-hangzhou.aliyuncs.com/geekmaster/chatgpt-plus-go:$version
docker rmi -f chatgpt-plus-go:$version
# build docker image for chatgpt-plus-go
docker build -t chatgpt-plus-go:$version -f dockerfile-api-go ../
docker build -t registry.cn-hangzhou.aliyuncs.com/geekmaster/chatgpt-plus-go:$version -f dockerfile-api-go ../
# build docker image for chatgpt-plus-vue
docker rmi -f registry.cn-hangzhou.aliyuncs.com/geekmaster/chatgpt-plus-vue:$version
docker rmi -f chatgpt-plus-vue:$version
docker build --platform linux/amd64 -t chatgpt-plus-vue:$version -f dockerfile-vue ../
# add tag for aliyum docker registry
goImageId=`docker images |grep chatgpt-plus-go |grep $version |awk '{print $3}'`
docker tag $goImageId registry.cn-hangzhou.aliyuncs.com/geekmaster/chatgpt-plus-go:$version
vueImageId=`docker images |grep chatgpt-plus-vue |grep $version |awk '{print $3}'`
docker tag $vueImageId registry.cn-hangzhou.aliyuncs.com/geekmaster/chatgpt-plus-vue:$version
docker build --platform linux/amd64 -t registry.cn-hangzhou.aliyuncs.com/geekmaster/chatgpt-plus-vue:$version -f dockerfile-vue ../

View File

@@ -1,15 +1,18 @@
Listen = "0.0.0.0:5678"
ProxyURL = "http://172.22.11.200:7777"
MysqlDns = "root:12345678@tcp(172.28.173.76:3307)/chatgpt_plus?charset=utf8mb4&collation=utf8mb4_unicode_ci&parseTime=True&loc=Local"
MysqlDns = "root:mysql_pass@tcp(localhost:3306)/chatgpt_plus?charset=utf8mb4&collation=utf8mb4_unicode_ci&parseTime=True&loc=Local"
StaticDir = "./static"
StaticUrl = "http://localhost:8080/static"
StaticUrl = "http://localhost:5678/static"
AesEncryptKey = "{YOUR_AES_KEY}"
StartWechatBot = false
EnabledMsgService = false
[Session]
Driver = "cookie"
SecretKey = "8k0c67y2or1n7kbmn1w1c86ygqscguoktuf9t524jm64ls585z8uibpdssiy128s"
Name = "CHAT_PLUS_SESSION"
SecretKey = "m0cjm3gsuw9jk73np1ni7r42koilybjcndlycjdmq7za3pbqn7w12fyok5pqh6q5"
Name = "CHAT_SESSION_ID"
Path = "/"
Domain = ""
Domain = "localhost"
MaxAge = 86400
Secure = false
HttpOnly = false
@@ -23,3 +26,16 @@ StaticUrl = "http://localhost:8080/static"
Host = "localhost"
Port = 6379
Password = ""
[ApiConfig]
ApiURL = "{URL}"
AppId = "{APP_ID}"
Token = "{TOKEN}"
[SmsConfig]
AccessKey = "{YOUR_ACCESS_KEY}"
AccessSecret = "{YOUR_SECRET_KEY}"
Product = "Dysmsapi"
Domain = "dysmsapi.aliyuncs.com"

View File

@@ -35,12 +35,12 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_pass http://172.28.173.76:6789; # 这里改成后端服务的内网 IP 地址
proxy_pass http://172.22.11.47:5678; # 这里改成后端服务的内网 IP 地址
}
# 静态资源转发
location /static/ {
proxy_pass http://172.28.173.76:6789; # 这里改成后端服务的内网 IP 地址
proxy_pass http://172.22.11.47:5678; # 这里改成后端服务的内网 IP 地址
}
}
}
}

View File

@@ -2,23 +2,22 @@ version: '3'
services:
# 后端 API 程序
chatgpt-plus-go:
image: registry.cn-hangzhou.aliyuncs.com/geekmaster/chatgpt-plus-go:v3.0.4
# image: chatgpt-plus-go:v3.0.2
image: registry.cn-hangzhou.aliyuncs.com/geekmaster/chatgpt-plus-go:v3.0.5.2
container_name: chatgpt-plus-go
restart: always
environment:
- DEBUG=false
- CONFIG_FILE=config.toml
ports:
- "6789:5678"
- "5678:5678"
volumes:
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
- ./conf/config.toml:/var/www/app/config.toml
- ./static:/var/www/app/static
# 前端应用
chatgpt-vue:
image: registry.cn-hangzhou.aliyuncs.com/geekmaster/chatgpt-plus-vue:v3.0.4
# image: chatgpt-plus-vue:v3.0.2
image: registry.cn-hangzhou.aliyuncs.com/geekmaster/chatgpt-plus-vue:v3.0.5.2
container_name: chatgpt-plus-vue
restart: always
ports:

View File

@@ -1,10 +1,10 @@
# GO api docker 镜像创建
FROM registry.cn-hangzhou.aliyuncs.com/geekmaster/ubuntu-ca:22.04
FROM alpine:3.18.2
MAINTAINER yangjian<yangjian102621@163.com>
WORKDIR /var/www/app
COPY ./api/go/bin/chatgpt-v3-amd64-linux /var/www/app
COPY ./api/bin/chatgpt-v3-amd64-linux /var/www/app
EXPOSE 5678

View File

@@ -1,5 +1,5 @@
# 前端 Vue 项目构建
FROM nginx:1.20.2
FROM nginx:1.20
MAINTAINER yangjian<yangjian102621@163.com>

BIN
docs/imgs/plugin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

30
web/package-lock.json generated
View File

@@ -17,6 +17,7 @@
"good-storage": "^1.1.1",
"highlight.js": "^11.7.0",
"json-bigint": "^1.0.0",
"lodash": "^4.17.21",
"markdown-it": "^13.0.1",
"md-editor-v3": "^2.2.1",
"pinia": "^2.1.4",
@@ -24,7 +25,8 @@
"sortablejs": "^1.15.0",
"vant": "^4.5.0",
"vue": "^3.2.13",
"vue-router": "^4.0.15"
"vue-router": "^4.0.15",
"vue-schart": "^2.0.0"
},
"devDependencies": {
"@babel/core": "7.18.6",
@@ -9365,6 +9367,11 @@
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==",
"dev": true
},
"node_modules/schart.js": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/schart.js/-/schart.js-3.0.4.tgz",
"integrity": "sha512-uylb2u9rrHX1jyAuSAJUQON8XTfyDKI9kWj1J3fUlCQCkLVZ4HG4+IiV8qm//Z71dqvLI78QZ/fCBw0reB22Zw=="
},
"node_modules/schema-utils": {
"version": "2.7.1",
"resolved": "https://registry.npmmirror.com/schema-utils/-/schema-utils-2.7.1.tgz",
@@ -10693,6 +10700,14 @@
"vue": "^3.2.0"
}
},
"node_modules/vue-schart": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/vue-schart/-/vue-schart-2.0.0.tgz",
"integrity": "sha512-qAu3e5wfMcq26wK1xeHExEWfGpnjfoN1R/9QXblNi+AsU/p52X7tTwhi+Fw7H/otfEufhEY2X7z7emaoF4QO+g==",
"dependencies": {
"schart.js": "^3.0.0"
}
},
"node_modules/vue-style-loader": {
"version": "4.1.3",
"resolved": "https://registry.npmmirror.com/vue-style-loader/-/vue-style-loader-4.1.3.tgz",
@@ -18620,6 +18635,11 @@
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==",
"dev": true
},
"schart.js": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/schart.js/-/schart.js-3.0.4.tgz",
"integrity": "sha512-uylb2u9rrHX1jyAuSAJUQON8XTfyDKI9kWj1J3fUlCQCkLVZ4HG4+IiV8qm//Z71dqvLI78QZ/fCBw0reB22Zw=="
},
"schema-utils": {
"version": "2.7.1",
"resolved": "https://registry.npmmirror.com/schema-utils/-/schema-utils-2.7.1.tgz",
@@ -19685,6 +19705,14 @@
"@vue/devtools-api": "^6.0.0"
}
},
"vue-schart": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/vue-schart/-/vue-schart-2.0.0.tgz",
"integrity": "sha512-qAu3e5wfMcq26wK1xeHExEWfGpnjfoN1R/9QXblNi+AsU/p52X7tTwhi+Fw7H/otfEufhEY2X7z7emaoF4QO+g==",
"requires": {
"schart.js": "^3.0.0"
}
},
"vue-style-loader": {
"version": "4.1.3",
"resolved": "https://registry.npmmirror.com/vue-style-loader/-/vue-style-loader-4.1.3.tgz",

View File

@@ -24,6 +24,7 @@
"sortablejs": "^1.15.0",
"vant": "^4.5.0",
"vue": "^3.2.13",
"lodash": "^4.17.21",
"vue-router": "^4.0.15"
},
"devDependencies": {

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View File

@@ -20,6 +20,8 @@ html, body {
#app {
margin: 0 !important;
padding: 0 !important;
font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}
</style>

View File

@@ -1,6 +1,3 @@
.admin-home .header {
background-color: #242f42;
}
.admin-home .login-wrap {
background: #324157;
}

View File

@@ -1,6 +1,6 @@
.admin-home {
.header {
background-color: #242f42;
}
.login-wrap {

View File

@@ -11,7 +11,9 @@ body,
overflow: hidden;
}
body {
font-family: 'PingFang SC', "Helvetica Neue", Helvetica, "microsoft yahei", arial, STHeiTi, sans-serif;
font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}
.admin-home a {
text-decoration: none;
@@ -20,7 +22,7 @@ body {
position: absolute;
left: 250px;
right: 0;
top: 70px;
top: 0;
bottom: 0;
padding-bottom: 30px;
-webkit-transition: left 0.3s ease-in-out;

View File

@@ -13,7 +13,9 @@ body,
}
body {
font-family: 'PingFang SC', "Helvetica Neue", Helvetica, "microsoft yahei", arial, STHeiTi, sans-serif;
font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}
.admin-home {
@@ -25,7 +27,7 @@ body {
position: absolute;
left: 250px;
right: 0;
top: 70px;
top: 0;
bottom: 0;
padding-bottom: 30px;
-webkit-transition: left .3s ease-in-out;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 824 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -0,0 +1,369 @@
<template>
<div class="wg-cap-wrap" :style="{width: width}">
<div class="wg-cap-wrap__header">
<span>请在下图<em>依次</em>点击</span>
<img class="wg-cap-wrap__thumb" v-if="thumbBase64Code" :src="thumbBase64Code" alt=" ">
</div>
<div class="wg-cap-wrap__body">
<img class="wg-cap-wrap__picture" v-if="imageBase64Code" :src="imageBase64Code" alt=" " @click="handleClickPos($event)">
<img class="wg-cap-wrap__loading" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBzdHlsZT0ibWFyZ2luOiBhdXRvOyBiYWNrZ3JvdW5kOiByZ2JhKDI0MSwgMjQyLCAyNDMsIDApOyBkaXNwbGF5OiBibG9jazsgc2hhcGUtcmVuZGVyaW5nOiBhdXRvOyIgd2lkdGg9IjY0cHgiIGhlaWdodD0iNjRweCIgdmlld0JveD0iMCAwIDEwMCAxMDAiIHByZXNlcnZlQXNwZWN0UmF0aW89InhNaWRZTWlkIj4KICA8Y2lyY2xlIGN4PSI1MCIgY3k9IjM2LjgxMDEiIHI9IjEzIiBmaWxsPSIjM2U3Y2ZmIj4KICAgIDxhbmltYXRlIGF0dHJpYnV0ZU5hbWU9ImN5IiBkdXI9IjFzIiByZXBlYXRDb3VudD0iaW5kZWZpbml0ZSIgY2FsY01vZGU9InNwbGluZSIga2V5U3BsaW5lcz0iMC40NSAwIDAuOSAwLjU1OzAgMC40NSAwLjU1IDAuOSIga2V5VGltZXM9IjA7MC41OzEiIHZhbHVlcz0iMjM7Nzc7MjMiPjwvYW5pbWF0ZT4KICA8L2NpcmNsZT4KPC9zdmc+" alt="正在加载中...">
<div v-for="(dot, key) in dots" :key="key" class="wg-cap-wrap__dot" :style="`top: ${dot.y}px; left:${dot.x}px;`">
<span>{{ dot.index }}</span>
</div>
</div>
<div class="wg-cap-wrap__footer">
<div class="wg-cap-wrap__ico">
<img @click="handleCloseEvent"
src="data:image/svg+xml;base64,PHN2ZyB0PSIxNjI2NjE0NDM5NDIzIiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9Ijg2NzUiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj48cGF0aCBkPSJNNTEyIDIzLjI3MjcyN2MyNjkuOTE3MDkxIDAgNDg4LjcyNzI3MyAyMTguODEwMTgyIDQ4OC43MjcyNzMgNDg4LjcyNzI3M2E0ODYuNjMyNzI3IDQ4Ni42MzI3MjcgMCAwIDEtODQuOTQ1NDU1IDI3NS40MDk0NTUgNDYuNTQ1NDU1IDQ2LjU0NTQ1NSAwIDAgMS03Ni44NDY1NDUtNTIuNTI2NTQ2QTM5My41NDE4MTggMzkzLjU0MTgxOCAwIDAgMCA5MDcuNjM2MzY0IDUxMmMwLTIxOC41MDc2MzYtMTc3LjEyODcyNy0zOTUuNjM2MzY0LTM5NS42MzYzNjQtMzk1LjYzNjM2NFMxMTYuMzYzNjM2IDI5My40OTIzNjQgMTE2LjM2MzYzNiA1MTJzMTc3LjEyODcyNyAzOTUuNjM2MzY0IDM5NS42MzYzNjQgMzk1LjYzNjM2NGEzOTUuMTcwOTA5IDM5NS4xNzA5MDkgMCAwIDAgMTI1LjQ0LTIwLjI5MzgxOSA0Ni41NDU0NTUgNDYuNTQ1NDU1IDAgMCAxIDI5LjQ4NjU0NSA4OC4yOTY3MjhBNDg4LjI2MTgxOCA0ODguMjYxODE4IDAgMCAxIDUxMiAxMDAwLjcyNzI3M0MyNDIuMDgyOTA5IDEwMDAuNzI3MjczIDIzLjI3MjcyNyA3ODEuOTE3MDkxIDIzLjI3MjcyNyA1MTJTMjQyLjA4MjkwOSAyMy4yNzI3MjcgNTEyIDIzLjI3MjcyN3ogbS0xMTUuMiAzMDcuNzEyTDUxMiA0NDYuMTM4MTgybDExNS4yLTExNS4yYTQ2LjU0NTQ1NSA0Ni41NDU0NTUgMCAxIDEgNjUuODE1MjczIDY1Ljg2MTgxOEw1NzcuODYxODE4IDUxMmwxMTUuMiAxMTUuMmE0Ni41NDU0NTUgNDYuNTQ1NDU1IDAgMSAxLTY1Ljg2MTgxOCA2NS44MTUyNzNMNTEyIDU3Ny44NjE4MThsLTExNS4yIDExNS4yYTQ2LjU0NTQ1NSA0Ni41NDU0NTUgMCAxIDEtNjUuODE1MjczLTY1Ljg2MTgxOEw0NDYuMTM4MTgyIDUxMmwtMTE1LjItMTE1LjJhNDYuNTQ1NDU1IDQ2LjU0NTQ1NSAwIDEgMSA2NS44NjE4MTgtNjUuODE1MjczeiIgcC1pZD0iODY3NiIgZmlsbD0iIzcwNzA3MCI+PC9wYXRoPjwvc3ZnPg=="
alt="关闭">
<img @click="handleRefreshEvent"
src="data:image/svg+xml;base64,PHN2ZyB0PSIxNjI2NjE0NDk5NjM4IiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjEzNjAiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj48cGF0aCBkPSJNMTg3LjQ1NiA0MjUuMDI0YTMzNiAzMzYgMCAwIDAgMzY4LjM4NCA0MjAuMjI0IDQ4IDQ4IDAgMCAxIDEyLjU0NCA5NS4xNjggNDMyIDQzMiAwIDAgMS00NzMuNjY0LTU0MC4xNmwtNTcuMjgtMTUuMzZhMTIuOCAxMi44IDAgMCAxLTYuMjcyLTIwLjkyOGwxNTkuMTY4LTE3OS40NTZhMTIuOCAxMi44IDAgMCAxIDIyLjE0NCA1Ljg4OGw0OC4wNjQgMjM1LjA3MmExMi44IDEyLjggMCAwIDEtMTUuODA4IDE0LjkxMmwtNTcuMjgtMTUuMzZ6TTgzNi40OCA1OTkuMDRhMzM2IDMzNiAwIDAgMC0zNjguMzg0LTQyMC4yMjQgNDggNDggMCAxIDEtMTIuNTQ0LTk1LjE2OCA0MzIgNDMyIDAgMCAxIDQ3My42NjQgNTQwLjE2bDU3LjI4IDE1LjM2YTEyLjggMTIuOCAwIDAgMSA2LjI3MiAyMC45MjhsLTE1OS4xNjggMTc5LjQ1NmExMi44IDEyLjggMCAwIDEtMjIuMTQ0LTUuODg4bC00OC4wNjQtMjM1LjA3MmExMi44IDEyLjggMCAwIDEgMTUuODA4LTE0LjkxMmw1Ny4yOCAxNS4zNnoiIGZpbGw9IiM3MDcwNzAiIHAtaWQ9IjEzNjEiPjwvcGF0aD48L3N2Zz4="
alt="刷新">
</div>
<div class="wg-cap-wrap__btn">
<button @click="handleConfirmEvent">确认</button>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'CaptchaPlus',
mounted() {
this.$emit('refresh')
},
props: {
value: Boolean,
width: {
type: String,
default: '300px'
},
calcPosType: {
type: String,
default: 'dom',
validator: value => ['dom', 'screen'].includes(value)
},
maxDot: {
type: Number,
default: 5
// validator: value => value > 10
},
imageBase64: String,
thumbBase64: String
},
data() {
return {
dots: [],
imageBase64Code: '',
thumbBase64Code: ''
}
},
watch: {
value() {
this.dots = []
this.imageBase64Code = ''
this.thumbBase64Code = ''
},
imageBase64(val) {
this.dots = []
this.imageBase64Code = val
},
thumbBase64(val) {
this.dots = []
this.thumbBase64Code = val
}
},
methods: {
/**
* @Description: 处理关闭事件
*/
handleCloseEvent() {
this.$emit('close')
// this.dots = []
// this.imageBase64Code = ''
// this.thumbBase64Code = ''
},
/**
* @Description: 处理刷新事件
*/
handleRefreshEvent() {
this.dots = []
this.$emit('refresh')
},
/**
* @Description: 处理确认事件
*/
handleConfirmEvent() {
this.$emit('confirm', this.dots)
},
/**
* @Description: 处理dot
* @param ev
*/
handleClickPos(ev) {
if (this.dots.length >= this.maxDot) {
return
}
const e = ev || window.event
e.preventDefault()
const dom = e.currentTarget
const {domX, domY} = this.getDomXY(dom)
// ===============================================
// @notice 如 getDomXY 不准确可尝试使用 calcLocationLeft 或 calcLocationTop
// const domX = this.calcLocationLeft(dom)
// const domY = this.calcLocationTop(dom)
// ===============================================
let mouseX = (navigator.vendor === 'Netscape') ? e.pageX : e.x + document.body.offsetTop
let mouseY = (navigator.vendor === 'Netscape') ? e.pageY : e.y + document.body.offsetTop
if (this.calcPosType === 'screen') {
mouseX = (navigator.vendor === 'Netscape') ? e.clientX : e.x
mouseY = (navigator.vendor === 'Netscape') ? e.clientY : e.y
}
// 计算点击的相对位置
const xPos = mouseX - domX
const yPos = mouseY - domY
// 转整形
const xp = parseInt(xPos.toString())
const yp = parseInt(yPos.toString())
// 减去点的一半
this.dots.push({
x: xp - 11,
y: yp - 11,
index: this.dots.length + 1
})
return false
},
/**
* @Description: 找到元素的屏幕位置
* @param el
*/
calcLocationLeft(el) {
let tmp = el.offsetLeft
let val = el.offsetParent
while (val != null) {
tmp += val.offsetLeft
val = val.offsetParent
}
return tmp
},
/**
* @Description: 找到元素的屏幕位置
* @param el
*/
calcLocationTop(el) {
let tmp = el.offsetTop
let val = el.offsetParent
while (val != null) {
tmp += val.offsetTop
val = val.offsetParent
}
return tmp
},
/**
* @Description: 找到元素的屏幕位置
* @param dom
*/
getDomXY(dom){
let x = 0
let y = 0
if (dom.getBoundingClientRect) {
let box = dom.getBoundingClientRect();
let D = document.documentElement;
x = box.left + Math.max(D.scrollLeft, document.body.scrollLeft) - D.clientLeft;
y = box.top + Math.max(D.scrollTop, document.body.scrollTop) - D.clientTop
}
else{
while (dom !== document.body) {
x += dom.offsetLeft
y += dom.offsetTop
dom = dom.offsetParent
}
}
return {
domX: x,
domY: y
}
}
}
}
</script>
<style>
.wg-cap-wrap{
background: #ffffff;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.wg-cap-wrap__header{
height: 50px;
width: 100%;
font-size: 15px;
display:-webkit-box;
display:-webkit-flex;
display:-ms-flexbox;
display:flex;
-webkit-box-align:center;
-webkit-align-items:center;
-ms-flex-align:center;
align-items: center;
}
.wg-cap-wrap__header span{
padding-right: 5px;
}
.wg-cap-wrap__header span em{
padding: 0 3px;
font-weight: bold;
color: #3e7cff;
font-style: normal;
}
.wg-cap-wrap__header .wg-cap-wrap__image{
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
overflow: hidden;
text-align: center;
line-height: 1;
}
.wg-cap-wrap__header .wg-cap-wrap__thumb{
min-width: 150px;
text-align: center;
line-height: 1;
max-height: 100%;
}
.wg-cap-wrap__header .wg-cap-wrap__thumb.wg-cap-wrap__hidden{
display: none;
}
.wg-cap-wrap__body{
position: relative;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
background: #34383e;
margin: auto;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
overflow: hidden;
}
.wg-cap-wrap__body .wg-cap-wrap__picture{
position: relative;
z-index: 10;
width: 100%;
/*height: 100%;*/
/*max-width: 100%;*/
/*max-height: 100%;*/
/*object-fit: cover;*/
/*text-align: center;*/
}
.wg-cap-wrap__body .wg-cap-wrap__picture.wg-cap-wrap__hidden{
display: none;
}
.wg-cap-wrap__body .wg-cap-wrap__loading{
position: absolute;
z-index: 9;
top: 50%;
left: 50%;
width: 68px;
height: 68px;
margin-left: -34px;
margin-top: -34px;
line-height: 68px;
text-align: center;
}
.wg-cap-wrap__body .wg-cap-wrap__dot{
position: absolute;
z-index: 10;
width: 22px;
height: 22px;
color: #cedffe;
background: #3e7cff;
border: 2px solid #f7f9fb;
line-height: 20px;
text-align: center;
-webkit-border-radius: 22px;
-moz-border-radius: 22px;
border-radius: 22px;
cursor: default;
}
.wg-cap-wrap__footer {
width: 100%;
height: 40px;
color: #34383e;
display:-webkit-box;
display:-webkit-flex;
display:-ms-flexbox;
display:flex;
-webkit-box-align:center;
-webkit-align-items:center;
-ms-flex-align:center;
align-items: center;
padding-top: 15px;
}
.wg-cap-wrap__footer .wg-cap-wrap__ico{
flex: 1;
}
.wg-cap-wrap__footer .wg-cap-wrap__ico img{
width: 24px;
height: 24px;
color: #34383e;
margin: 0 5px;
cursor: pointer;
}
.wg-cap-wrap__footer .wg-cap-wrap__btn{
width: 120px;
height: 40px;
}
.wg-cap-wrap__footer .wg-cap-wrap__btn button{
width: 100%;
height: 40px;
letter-spacing: 2px;
text-align: center;
padding: 9px 15px;
font-size: 15px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
display: inline-block;
line-height: 1;
white-space: nowrap;
cursor: pointer;
color: #fff;
background-color: #409eff;
border: 1px solid #409eff;
-webkit-appearance: none;
box-sizing: border-box;
outline: none;
margin: 0;
transition: .1s;
font-weight: 500;
-moz-user-select: none;
-webkit-user-select: none;
}
.wg-cap-wrap__footer .wg-cap-wrap__btn button:hover {
background: #66b1ff;
border-color: #66b1ff;
color: #fff;
}
</style>

View File

@@ -0,0 +1,75 @@
<template>
<el-dialog
v-model="showDialog"
:close-on-click-modal="false"
:show-close="mobile !== ''"
:before-close="close"
:title="title"
>
<div class="form" id="bind-mobile-form">
<el-alert v-if="mobile !== ''" type="info" show-icon :closable="false" style="margin-bottom: 20px;">
<p>请输入您参与众筹的微信支付转账单号兑换相应的对话次数</p>
</el-alert>
<el-form :model="form" label-width="120px">
<el-form-item label="转账单号">
<el-input v-model="form.tx_id"/>
</el-form-item>
</el-form>
</div>
<template #footer>
<span class="dialog-footer">
<el-button type="primary" @click="save">
确认核销
</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup>
import {computed, ref} from "vue";
import {ElMessage} from "element-plus";
import {httpPost} from "@/utils/http";
const props = defineProps({
show: Boolean,
mobile: String
});
const showDialog = computed(() => {
return props.show
})
const title = ref('众筹码核销')
const form = ref({
tx_id: '',
})
const emits = defineEmits(['hide']);
const save = () => {
if (form.value.tx_id === '') {
return ElMessage.error({message: "请输入微信支付转账单号"});
}
httpPost('/api/reward/verify', form.value).then(() => {
ElMessage.success({
message: '核销成功',
duration: 1000,
onClose: () => emits('hide', false)
})
}).catch(e => {
ElMessage.error({message: "核销失败:" + e.message});
})
}
const close = function () {
emits('hide', false);
}
</script>
<style scoped>
</style>

View File

@@ -1,16 +1,40 @@
<template>
<el-button type="primary" :disabled="!canSend" :size="props.size" @click="sendMsg" plain>{{
btnText
}}
</el-button>
<el-container>
<el-popover
:visible="showCaptcha"
:hide-after="0"
placement="top"
:width="325"
trigger="click"
content="this is content, this is content, this is content"
>
<captcha-plus
v-if="showCaptcha"
:max-dot="maxDot"
:image-base64="imageBase64"
:thumb-base64="thumbBase64"
@close="showCaptcha = false"
@refresh="handleRequestCaptCode"
@confirm="handleConfirm"
/>
<template #reference>
<el-button type="primary" :size="props.size" :disabled="!canSend" @click="loadCaptcha" plain>
{{ btnText }}
</el-button>
</template>
</el-popover>
</el-container>
</template>
<script setup>
// 发送短信验证码组件
import {ref} from "vue";
import lodash from 'lodash'
import {validateMobile} from "@/utils/validate";
import {ElMessage} from "element-plus";
import {httpGet, httpPost} from "@/utils/http";
import CaptchaPlus from "@/components/CaptchaPlus.vue";
const props = defineProps({
mobile: String,
@@ -18,37 +42,80 @@ const props = defineProps({
});
const btnText = ref('发送验证码')
const canSend = ref(true)
const showCaptcha = ref(false)
const maxDot = ref(5)
const imageBase64 = ref('')
const thumbBase64 = ref('')
const captKey = ref('')
const dots = ref(null)
const handleRequestCaptCode = () => {
httpGet('/api/captcha/get').then(res => {
const data = res.data
console.log(res)
imageBase64.value = data.image
thumbBase64.value = data.thumb
captKey.value = data.key
}).catch(e => {
ElMessage.error('获取人机验证数据失败:' + e.message)
})
}
const handleConfirm = (dots) => {
if (lodash.size(dots) <= 0) {
return ElMessage.error('请进行人机验证再操作')
}
let dotArr = []
lodash.forEach(dots, (dot) => {
dotArr.push(dot.x, dot.y)
})
dots.value = dotArr.join(',')
httpPost('/api/captcha/check', {
dots: dots.value,
key: captKey.value
}).then(() => {
showCaptcha.value = false
sendMsg()
}).catch(() => {
ElMessage.error('人机验证失败')
handleRequestCaptCode()
})
}
const loadCaptcha = () => {
if (!validateMobile(props.mobile)) {
return ElMessage.error("请输入合法的手机号")
}
showCaptcha.value = true
handleRequestCaptCode() // 每次点开都刷新验证码
}
const sendMsg = () => {
if (!canSend.value) {
return
}
if (!validateMobile(props.mobile)) {
return ElMessage.error("请输入合法的手机号")
}
canSend.value = false
httpGet('/api/verify/token').then(res => {
httpPost('/api/verify/sms', {token: res.data, mobile: props.mobile}).then(() => {
ElMessage.success('短信发送成功')
let time = 120
btnText.value = time
const handler = setInterval(() => {
time = time - 1
if (time <= 0) {
clearInterval(handler)
btnText.value = '重新发送'
canSend.value = true
} else {
btnText.value = time
}
}, 1000)
}).catch(e => {
canSend.value = true
ElMessage.error('短信发送失败:' + e.message)
})
httpPost('/api/sms/code', {mobile: props.mobile, key: captKey.value, dots: dots.value}).then(() => {
ElMessage.success('短信发送成功')
let time = 120
btnText.value = time
const handler = setInterval(() => {
time = time - 1
if (time <= 0) {
clearInterval(handler)
btnText.value = '重新发送'
canSend.value = true
} else {
btnText.value = time
}
}, 1000)
}).catch(e => {
console.log('failed to fetch token: ' + e.message)
canSend.value = true
ElMessage.error('短信发送失败:' + e.message)
})
}

View File

@@ -1,9 +1,5 @@
<template>
<div class="header admin-header">
<div class="logo">
<el-image :src="logo"/>
<span class="text">{{ title }}</span>
</div>
<!-- 折叠按钮 -->
<div class="collapse-btn" @click="collapseChange">
<el-icon v-if="sidebar.collapse">
@@ -13,6 +9,12 @@
<Fold/>
</el-icon>
</div>
<div class="breadcrumb">
<el-breadcrumb :separator-icon="ArrowRight">
<el-breadcrumb-item v-for="item in breadcrumb">{{ item.title }}</el-breadcrumb-item>
</el-breadcrumb>
</div>
<div class="header-right">
<div class="header-user-con">
<!-- 消息中心 -->
@@ -26,12 +28,10 @@
</el-tooltip>
<span class="btn-bell-badge" v-if="message"></span>
</div>
<!-- 用户头像 -->
<el-avatar class="user-avatar" :size="30" :src="avatar"/>
<!-- 用户名下拉菜单 -->
<el-dropdown class="user-name" :hide-on-click="true" trigger="click">
<span class="el-dropdown-link">
{{ username }}
<el-avatar class="user-avatar" :size="30" :src="avatar"/>
<el-icon class="el-icon--right">
<arrow-down/>
</el-icon>
@@ -77,28 +77,68 @@
</template>
<script setup>
import {onMounted, ref} from 'vue';
import {useSidebarStore} from '@/store/sidebar';
import {getMenuItems, useSidebarStore} from '@/store/sidebar';
import {useRouter} from 'vue-router';
import {ArrowDown, Expand, Fold} from "@element-plus/icons-vue";
import {ArrowDown, ArrowRight, Expand, Fold} from "@element-plus/icons-vue";
import {httpGet} from "@/utils/http";
import {ElMessage} from "element-plus";
const message = ref(5);
const username = ref('极客学长')
const avatar = ref('/images/user-info.jpg')
const donateImg = ref('/images/wechat-pay.png')
const showDialog = ref(false)
const sidebar = useSidebarStore();
const title = ref('Chat-Plus 控制台')
const logo = ref('/images/logo.png')
const router = useRouter();
const breadcrumb = ref([])
// 加载系统配置
httpGet('/api/admin/config/get?key=system').then(res => {
title.value = res.data['admin_title'];
}).catch(e => {
ElMessage.error("加载系统配置失败: " + e.message)
router.afterEach((to, from) => {
initBreadCrumb(to.path)
});
onMounted(() => {
initBreadCrumb(router.currentRoute.value.path)
})
// 初始化面包屑导航
const initBreadCrumb = (path) => {
breadcrumb.value = [{title: "首页"}]
const items = getMenuItems()
if (items) {
let bk = false
for (let i = 0; i < items.length; i++) {
if (items[i].index === path) {
breadcrumb.value.push({
title: items[i].title,
path: items[i].index
})
break
}
if (bk) {
break
}
if (items[i]['subs']) {
const subs = items[i]['subs']
for (let j = 0; j < subs.length; j++) {
if (subs[j].index === path) {
breadcrumb.value.push({
title: items[i].title,
path: items[i].index
})
breadcrumb.value.push({
title: subs[j].title,
path: subs[j].index
})
bk = true
break
}
}
}
}
}
}
// 侧边栏折叠
const collapseChange = () => {
sidebar.handleCollapse();
@@ -110,7 +150,6 @@ onMounted(() => {
}
});
const router = useRouter();
const logout = function () {
httpGet("/api/admin/logout").then(() => {
router.replace('/admin/login')
@@ -123,10 +162,12 @@ const logout = function () {
.header {
position: relative;
box-sizing: border-box;
width: 100%;
height: 70px;
overflow hidden
height: 50px;
font-size: 22px;
color: #fff;
color: #303133;
background-color #ffffff
border-bottom 1px solid #eaecef
.collapse-btn {
display: flex;
@@ -134,19 +175,19 @@ const logout = function () {
align-items: center;
height: 100%;
float: left;
padding: 0 21px;
padding: 0 10px;
cursor: pointer;
&:hover {
background-color #eaecef
}
}
.logo {
float: left;
padding-left 10px;
.breadcrumb {
float left
display flex
.text {
line-height: 66px;
margin-left 10px;
}
align-items center
height 50px
}
.header-right {
@@ -155,7 +196,7 @@ const logout = function () {
.header-user-con {
display: flex;
height: 70px;
height: 50px;
align-items: center;
.btn-bell {
@@ -176,7 +217,7 @@ const logout = function () {
height: 8px;
border-radius: 4px;
background: #f56c6c;
color: #fff;
color: #303133;
}
.icon-bell {
@@ -186,10 +227,14 @@ const logout = function () {
.user-name {
margin-left: 10px;
.el-icon {
color: #303133;
}
}
.user-avatar {
margin-left: 20px;
}
}
}
@@ -227,15 +272,7 @@ const logout = function () {
}
.admin-header {
.logo {
.el-image {
padding-top 10px
.el-image__inner {
height 40px
}
}
}
}
</style>

View File

@@ -1,5 +1,10 @@
<template>
<div class="sidebar">
<div class="logo">
<el-image :src="logo"/>
<span class="text" v-show="!sidebar.collapse">{{ title }}</span>
</div>
<el-menu
class="sidebar-el-menu"
:default-active="onRoutes"
@@ -47,15 +52,27 @@
</template>
<script setup>
import {computed} from 'vue';
import {useSidebarStore} from '@/store/sidebar';
import {computed, ref} from 'vue';
import {setMenuItems, useSidebarStore} from '@/store/sidebar';
import {useRoute} from 'vue-router';
import {httpGet} from "@/utils/http";
import {ElMessage} from "element-plus";
const title = ref('Chat-Plus-Admin')
const logo = ref('/images/logo.png')
// 加载系统配置
httpGet('/api/admin/config/get?key=system').then(res => {
title.value = res.data['admin_title'];
}).catch(e => {
ElMessage.error("加载系统配置失败: " + e.message)
})
const items = [
{
icon: 'home',
index: '/admin/welcome',
title: '系统首页',
index: '/admin/dashboard',
title: '仪表盘',
},
{
icon: 'config',
@@ -79,6 +96,11 @@ const items = [
index: '/admin/apikey',
title: 'API-KEY 管理',
},
{
icon: 'reward',
index: '/admin/reward',
title: '众筹管理',
},
{
icon: 'log',
index: '/admin/loginLog',
@@ -115,6 +137,7 @@ const onRoutes = computed(() => {
});
const sidebar = useSidebarStore();
setMenuItems(items)
</script>
<style scoped lang="stylus">
@@ -122,10 +145,35 @@ const sidebar = useSidebarStore();
display: block;
position: absolute;
left: 0;
top: 70px;
top: 0;
bottom: 0;
overflow-y: scroll;
.logo {
display flex
width 219px
background-color #324157
padding 6px 15px;
.el-image {
width 30px;
height 30px;
padding-top 5px;
border-radius 100%
.el-image__inner {
height 40px
}
}
.text {
color #ffffff
font-weight bold
padding 12px 0 12px 10px;
transition: width 2s ease;
}
}
ul {
height: 100%;
@@ -135,6 +183,10 @@ const sidebar = useSidebarStore();
margin-right 5px;
}
}
.el-menu-item.is-active {
background-color rgb(40, 52, 70)
}
}
.sidebar-el-menu:not(.el-menu--collapse) {

View File

@@ -15,7 +15,7 @@
</ul>
<div class="tags-close-box">
<el-dropdown @command="handleTags">
<el-button size="small" type="primary">
<el-button size="small" type="info">
标签选项
<el-icon class="el-icon--right">
<arrow-down/>
@@ -115,7 +115,8 @@ const handleTags = (command) => {
overflow: hidden;
background: #fff;
padding-right: 120px;
box-shadow: 0 5px 10px #ddd;
-webkit-box-shadow: 0 1px 4px rgba(0, 21, 41, .08);
box-shadow: 0 1px 4px rgba(0, 21, 41, .08);
}
.tags ul {
@@ -168,14 +169,13 @@ const handleTags = (command) => {
.tags-close-box {
position: absolute;
right: 0;
top: 0;
top: 2px;
box-sizing: border-box;
padding-top: 1px;
text-align: center;
width: 110px;
height: 30px;
background: #fff;
box-shadow: -3px 0 15px 3px rgba(0, 0, 0, 0.1);
z-index: 10;
//box-shadow: -3px 0 15px 3px rgba(0, 0, 0, 0.1); z-index: 10;
}
</style>

View File

@@ -35,15 +35,15 @@ const routes = [
{
name: 'admin',
path: '/admin',
redirect: '/admin/welcome',
redirect: '/admin/dashboard',
component: () => import("@/views/admin/Home.vue"),
meta: {title: 'ChatGPT-Plus 管理后台'},
children: [
{
path: '/admin/welcome',
name: 'admin-home',
meta: {title: '系统首页'},
component: () => import('@/views/admin/Welcome.vue'),
path: '/admin/dashboard',
name: 'admin-dashboard',
meta: {title: '仪表盘'},
component: () => import('@/views/admin/Dashboard.vue'),
},
{
path: '/admin/system',
@@ -69,6 +69,12 @@ const routes = [
meta: {title: 'API-KEY 管理'},
component: () => import('@/views/admin/ApiKey.vue'),
},
{
path: '/admin/reward',
name: 'admin-reward',
meta: {title: '众筹管理'},
component: () => import('@/views/admin/RewardList.vue'),
},
{
path: '/admin/loginLog',
name: 'admin-loginLog',

View File

@@ -1,4 +1,5 @@
import {defineStore} from 'pinia';
import Storage from "good-storage";
export const useSidebarStore = defineStore('sidebar', {
state: () => {
@@ -13,3 +14,13 @@ export const useSidebarStore = defineStore('sidebar', {
}
}
});
const MENU_STORE_KEY = "admin_menu_items"
export function getMenuItems() {
return Storage.get(MENU_STORE_KEY)
}
export function setMenuItems(items) {
return Storage.set(MENU_STORE_KEY, items)
}

View File

@@ -67,6 +67,20 @@
<span>绑定手机号</span>
</el-dropdown-item>
<el-dropdown-item @click="showRewardDialog = true">
<el-icon>
<Present/>
</el-icon>
<span>加入众筹</span>
</el-dropdown-item>
<el-dropdown-item @click="showRewardVerifyDialog = true">
<el-icon>
<Checked/>
</el-icon>
<span>众筹核销</span>
</el-dropdown-item>
<el-dropdown-item @click="clearAllChats">
<el-icon>
<Delete/>
@@ -94,6 +108,7 @@
<el-main v-loading="loading" element-loading-background="rgba(122, 122, 122, 0.3)">
<div class="chat-head">
<div class="chat-config">
<span class="role-select-label">聊天角色</span>
<el-select v-model="roleId" filterable placeholder="角色" class="role-select">
<el-option
v-for="item in roles"
@@ -197,6 +212,26 @@
<bind-mobile v-if="isLogin" :show="showBindMobileDialog" :mobile="loginUser.mobile"
@hide="showBindMobileDialog = false"/>
<reward-verify v-if="isLogin" :show="showRewardVerifyDialog" @hide="showRewardVerifyDialog = false"/>
<el-dialog
v-model="showRewardDialog"
:show-close="true"
custom-class="donate-dialog"
width="400px"
top="5vh"
title="参与众筹"
>
<el-alert type="info" :closable="false">
<p>您好ChatGPT-Plus 项目目前已经运行了快半年了一直免费给大家使用的然而免费服务始终难以维持服务器即将到期免费的
API KEY 也全部用完了因此我们准备开启众筹模式只需要打赏9.9就可以兑换 100 次对话以此来覆盖我们的 OpenAI
账单和服务器的费用</p>
</el-alert>
<p style="text-align: center">
<el-image :src="rewardImg"/>
</p>
</el-dialog>
</div>
@@ -208,10 +243,13 @@ import ChatReply from "@/components/ChatReply.vue";
import {
ArrowDown,
Check,
Checked,
Close,
Delete,
Edit, Iphone,
Edit,
Iphone,
Plus,
Present,
Promotion,
RefreshRight,
Search,
@@ -230,11 +268,13 @@ import ConfigDialog from "@/components/ConfigDialog.vue";
import PasswordDialog from "@/components/PasswordDialog.vue";
import {checkSession} from "@/action/session";
import BindMobile from "@/components/BindMobile.vue";
import RewardVerify from "@/components/RewardVerify.vue";
const title = ref('ChatGPT-智能助手');
const logo = 'images/logo.png';
const rewardImg = ref('images/reward.png')
const models = ref([])
const model = ref('gpt-3.5-turbo')
const model = ref('gpt-3.5-turbo-16k')
const chatData = ref([]);
const allChats = ref([]); // 会话列表
const chatList = ref(allChats.value);
@@ -251,6 +291,8 @@ const router = useRouter();
const showConfigDialog = ref(false);
const showPasswordDialog = ref(false);
const showBindMobileDialog = ref(false);
const showRewardDialog = ref(false);
const showRewardVerifyDialog = ref(false);
const isLogin = ref(false)
if (isMobile()) {
@@ -262,9 +304,6 @@ onMounted(() => {
checkSession().then((user) => {
loginUser.value = user
isLogin.value = true
if (user.mobile === '') {
showBindMobileDialog.value = true
}
// 加载角色列表
httpGet(`/api/role/list?user_id=${user.id}`).then((res) => {
roles.value = res.data;
@@ -920,6 +959,10 @@ $borderColor = #4676d0;
justify-content center;
padding-top 10px;
.role-select-label {
color #ffffff
}
.el-select {
//max-width 150px;
margin-right 10px;
@@ -996,9 +1039,9 @@ $borderColor = #4676d0;
justify-content: center;
align-items: center;
box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
padding 0 15px;
.input-container {
max-width 600px;
width 100%
margin: 0;
border: none;
@@ -1008,7 +1051,6 @@ $borderColor = #4676d0;
position relative
.el-textarea {
max-width 600px;
.el-textarea__inner::-webkit-scrollbar {
width: 0;

View File

@@ -9,7 +9,7 @@
<div class="header">{{ title }}</div>
<div class="content">
<div class="block">
<el-input placeholder="手机号/邮箱" size="large" v-model="username" autocomplete="off">
<el-input placeholder="手机号/用户名" size="large" v-model="username" autocomplete="off">
<template #prefix>
<el-icon>
<UserFilled/>

View File

@@ -1,101 +1,111 @@
<template>
<div>
<div class="bg"></div>
<div class="main">
<div class="contain">
<div class="logo">
<el-image src="images/logo.png" fit="cover"/>
</div>
<div class="register-page">
<div class="page-inner">
<div class="contain" v-if="enableRegister">
<div class="logo">
<el-image src="images/logo.png" fit="cover"/>
</div>
<div class="header">{{ title }}</div>
<div class="content">
<el-form :model="formData" label-width="120px" ref="formRef">
<div class="block">
<el-input placeholder="请输入用户名(4-30位)"
size="large" maxlength="30"
v-model="formData.username"
autocomplete="off">
<template #prefix>
<el-icon>
<UserFilled/>
</el-icon>
</template>
</el-input>
</div>
<div class="header">{{ title }}</div>
<div class="content">
<el-form :model="formData" label-width="120px" ref="formRef">
<div class="block">
<el-input placeholder="请输入用户名(4-30位)"
size="large" maxlength="30"
v-model="formData.username"
autocomplete="off">
<template #prefix>
<el-icon>
<UserFilled/>
</el-icon>
</template>
</el-input>
</div>
<div class="block">
<el-input placeholder="请输入密码(8-16位)"
maxlength="16" size="large"
v-model="formData.password" show-password
autocomplete="off">
<template #prefix>
<el-icon>
<Lock/>
</el-icon>
</template>
</el-input>
</div>
<div class="block">
<el-input placeholder="请输入密码(8-16位)"
maxlength="16" size="large"
v-model="formData.password" show-password
autocomplete="off">
<template #prefix>
<el-icon>
<Lock/>
</el-icon>
</template>
</el-input>
</div>
<div class="block">
<el-input placeholder="重复密码(8-16位)"
size="large" maxlength="16" v-model="formData.repass" show-password
autocomplete="off">
<template #prefix>
<el-icon>
<Lock/>
</el-icon>
</template>
</el-input>
</div>
<div class="block">
<el-input placeholder="重复密码(8-16位)"
size="large" maxlength="16" v-model="formData.repass" show-password
autocomplete="off">
<template #prefix>
<el-icon>
<Lock/>
</el-icon>
</template>
</el-input>
</div>
<div class="block">
<el-input placeholder="手机号码"
size="large" maxlength="11"
v-model="formData.mobile"
autocomplete="off">
<template #prefix>
<el-icon>
<Iphone/>
</el-icon>
</template>
</el-input>
</div>
<div class="block" v-if="enableMsg">
<el-input placeholder="手机号码"
size="large" maxlength="11"
v-model="formData.mobile"
autocomplete="off">
<template #prefix>
<el-icon>
<Iphone/>
</el-icon>
</template>
</el-input>
</div>
<div class="block">
<el-row :gutter="10">
<el-col :span="12">
<el-input placeholder="手机验证码"
size="large" maxlength="30"
v-model.number="formData.code"
autocomplete="off">
<template #prefix>
<el-icon>
<Checked/>
</el-icon>
</template>
</el-input>
</el-col>
<el-col :span="12">
<send-msg size="large" :mobile="formData.mobile"/>
</el-col>
<div class="block" v-if="enableMsg">
<el-row :gutter="10">
<el-col :span="12">
<el-input placeholder="手机验证码"
size="large" maxlength="30"
v-model.number="formData.code"
autocomplete="off">
<template #prefix>
<el-icon>
<Checked/>
</el-icon>
</template>
</el-input>
</el-col>
<el-col :span="12">
<send-msg size="large" :mobile="formData.mobile"/>
</el-col>
</el-row>
</div>
<el-row class="btn-row">
<el-button class="login-btn" size="large" type="primary" @click="register">注册</el-button>
</el-row>
</div>
<el-row class="btn-row">
<el-button class="login-btn" size="large" type="primary" @click="register">注册</el-button>
</el-row>
<el-row class="text-line">
已经有账号
<el-link type="primary" @click="router.push('login')">登录</el-link>
</el-row>
</el-form>
<el-row class="text-line">
已经有账号
<el-link type="primary" @click="router.push('login')">登录</el-link>
</el-row>
</el-form>
</div>
</div>
</div>
<footer class="footer">
<footer-bar/>
</footer>
<div class="tip-result" v-else>
<el-result icon="error" title="注册功能已关闭">
<template #sub-title>
<p>抱歉系统已关闭注册功能请联系管理员添加账号</p>
</template>
</el-result>
</div>
<footer class="footer">
<footer-bar/>
</footer>
</div>
</div>
</div>
</template>
@@ -104,7 +114,7 @@
import {ref} from "vue";
import {Checked, Iphone, Lock, UserFilled} from "@element-plus/icons-vue";
import {httpPost} from "@/utils/http";
import {httpGet, httpPost} from "@/utils/http";
import {ElMessage} from "element-plus";
import {useRouter} from "vue-router";
import FooterBar from "@/components/FooterBar.vue";
@@ -120,6 +130,15 @@ const formData = ref({
repass: '',
})
const formRef = ref(null)
const enableMsg = ref(false)
const enableRegister = ref(true)
httpGet('/api/sms/status').then(res => {
if (res.data) {
enableMsg.value = res.data['enabled_msg_service']
enableRegister.value = res.data['enabled_register']
}
})
const register = function () {
if (formData.value.username.length < 4) {
@@ -132,6 +151,9 @@ const register = function () {
return ElMessage.error('两次输入密码不一致');
}
if (formData.value.code === '') {
formData.value.code = 0
}
httpPost('/api/user/register', formData.value).then(() => {
ElMessage.success({"message": "注册成功,即将跳转到登录页...", onClose: () => router.push("login")})
}).catch((e) => {
@@ -156,76 +178,108 @@ const register = function () {
//filter: blur(10px); /* 调整模糊程度,可以根据需要修改值 */
}
.main {
.contain {
position fixed
left 50%
top 40%
width 90%
max-width 400px
transform translate(-50%, -50%)
padding 20px 40px;
color #ffffff
border-radius 10px;
background rgba(255, 255, 255, 0.3)
.register-page {
display flex
justify-content center
.logo {
text-align center
.page-inner {
max-width 450px
height 100vh
display flex
justify-content center
align-items center
.el-image {
width 120px;
.contain {
padding 0 40px 20px 40px;
color #ffffff
border-radius 10px;
z-index 10
background-color rgba(255, 255, 255, 0.3)
.logo {
text-align center
.el-image {
width 120px;
}
}
}
.header {
width 100%
margin-bottom 24px
font-size 24px
color $white_v1
letter-space 2px
text-align center
}
.header {
width 100%
margin-bottom 24px
font-size 24px
color $white_v1
letter-space 2px
text-align center
}
.content {
width 100%
height: auto
border-radius 3px
.content {
width 100%
height: auto
border-radius 3px
.block {
margin-bottom 16px
.block {
margin-bottom 16px
.el-input__inner {
border 1px solid $gray-v6 !important
.el-input__inner {
border 1px solid $gray-v6 !important
.el-icon-user, .el-icon-lock {
font-size 20px
.el-icon-user, .el-icon-lock {
font-size 20px
}
}
}
}
.btn-row {
padding-top 10px;
.btn-row {
padding-top 10px;
.login-btn {
width 100%
font-size 16px
letter-spacing 2px
.login-btn {
width 100%
font-size 16px
letter-spacing 2px
}
}
.text-line {
justify-content center
padding-top 10px;
font-size 14px;
}
}
}
.text-line {
justify-content center
padding-top 10px;
font-size 14px;
.tip-result {
z-index 10
}
.footer {
color #ffffff;
.container {
padding 20px;
}
}
}
.footer {
color #ffffff;
}
</style>
.container {
padding 20px;
<style lang="stylus">
.register-page {
.el-result {
border-radius 10px;
background-color rgba(14, 25, 30, 0.6)
border 1px solid #666
.el-result__title p {
color #ffffff
}
.el-result__subtitle p {
color #c1c1c1
}
}
}

View File

@@ -1,373 +0,0 @@
<template>
<div class="admin-body common-layout">
<el-container>
<el-container>
<el-aside
:style="{
height: winHeight + 'px',
width: sideWidth + 'px',
}"
>
<div :class="showSidebar?'title':'title hide'">
<el-image :src="logo" class="logo"/>
<span class="text">{{ title }}</span>
<span
class="fold"
@click="showSidebar = !showSidebar"
:style="{ right: foldIconRight + 'px' }"
>
<el-icon>
<Fold/>
</el-icon>
</span>
</div>
<ul class="nav-list">
<li
v-for="nav in navs"
:key="nav.id"
:style="{ paddingLeft: nodeListPaddingLeft + 'px' }"
:class="nav.active?'active':''"
@click="addTab(nav)"
>
<el-tooltip
class="box-item"
effect="light"
:content="nav.title"
placement="right"
>
<el-icon>
<Menu/>
</el-icon>
</el-tooltip>
<span v-if="showSidebar">{{ nav.title }}</span>
</li>
</ul>
<el-row class="nav-footer">
<div class="source">
<i class="iconfont icon-github"></i>
<el-link href="https://github.com/yangjian102621/chatgpt-plus" target="_blank">ChatGPT-Plus-V3</el-link>
</div>
<div class="logout" @click="logout">
<i class="iconfont icon-logout"></i>
<span>退出登录</span>
</div>
</el-row>
</el-aside>
<el-main>
<div
class="main-container"
:style="{ height: winHeight + 'px' }"
>
<x-welcome v-if="curTab==='welcome'"/>
<div v-else>
<el-tabs
v-model="curTab"
class="content-tabs"
type="card"
closable
@tab-remove="removeTab"
@tab-change="changeTab"
>
<el-tab-pane label="系统配置" name="config" v-if="arrayContains(tabs, 'config')">
<sys-config v-if="curTab==='config'"/>
</el-tab-pane>
<el-tab-pane label="用户管理" name="user" v-if="arrayContains(tabs, 'user')">
<user-list v-if="curTab==='user'"/>
</el-tab-pane>
<el-tab-pane label="角色管理" name="role" v-if="arrayContains(tabs, 'role')">
<role-list v-if="curTab==='role'"/>
</el-tab-pane>
<el-tab-pane label="API KEY" name="apikey" v-if="arrayContains(tabs, 'apikey')">
<api-key v-if="curTab==='apikey'"/>
</el-tab-pane>
<el-tab-pane label="登录日志" name="loginLog" v-if="arrayContains(tabs, 'loginLog')">
<login-log v-if="curTab==='loginLog'"/>
</el-tab-pane>
</el-tabs>
</div>
</div>
</el-main>
</el-container>
</el-container>
</div>
</template>
<script setup>
import {computed, onMounted, ref} from 'vue'
import {Fold, Menu} from "@element-plus/icons-vue"
import XWelcome from "@/views/admin/Welcome.vue";
import SysConfig from "@/views/admin/SysConfig.vue";
import {arrayContains, removeArrayItem} from "@/utils/libs";
import UserList from "@/views/admin/UserList.vue";
import RoleList from "@/views/admin/RoleList.vue";
import {httpGet} from "@/utils/http";
import {ElMessage} from "element-plus";
import {useRouter} from "vue-router";
import ApiKey from "@/views/admin/ApiKey.vue";
import LoginLog from "@/views/admin/LoginLog.vue";
const title = ref('Chat-Plus 控制台')
const logo = ref('images/logo.png')
const navs = ref([
{
id: 1,
title: '系统配置',
tab: 'config',
active: false,
},
{
id: 2,
title: '用户管理',
tab: 'user',
active: false,
},
{
id: 3,
title: '角色管理',
tab: 'role',
active: false,
},
{
id: 4,
title: 'API KEY',
tab: 'apikey',
active: false,
},
{
id: 5,
title: '登录日志',
tab: 'loginLog',
active: false,
}
])
const tabs = ref([])
const curNav = ref(null)
const curTab = ref('welcome')
const winHeight = ref(window.innerHeight)
const showSidebar = ref(true)
const sideWidth = computed(() => {
return showSidebar.value ? 250 : 30
})
const foldIconRight = computed(() => {
return showSidebar.value ? 3 : 0
})
const nodeListPaddingLeft = computed(() => {
return showSidebar.value ? 20 : 5
})
const router = useRouter()
// 获取会话信息
httpGet("/api/admin/session").then(() => {
// 加载系统配置
httpGet('/api/admin/config/get?key=system').then(res => {
title.value = res.data['admin_title'];
}).catch(e => {
ElMessage.error("加载系统配置失败: " + e.message)
})
}).catch(() => {
router.push('/admin/login')
})
onMounted(() => {
window.addEventListener("resize", function () {
winHeight.value = window.innerHeight
})
})
const logout = function () {
httpGet("/api/admin/logout").then(() => {
router.push('/admin/login')
}).catch((e) => {
ElMessage.error("注销失败: " + e.message);
})
}
// 添加 tab 窗口
const addTab = function (nav) {
if (curNav.value) {
curNav.value.active = false
}
nav.active = true
curNav.value = nav;
curTab.value = nav.tab;
if (!arrayContains(tabs.value, nav.tab)) {
this.tabs.push(nav.tab);
}
}
// 切换 tab 窗口
const changeTab = function (name) {
for (let i = 0; i < navs.value.length; i++) {
let _nav = navs.value[i]
if (_nav.tab === name) {
curNav.value.active = false // 取消上一个 active 窗口的激活状态
_nav.active = true
curNav.value = _nav;
break;
}
}
}
// 删除 tab 窗口
const removeTab = function (name) {
tabs.value = removeArrayItem(tabs.value, name);
if (tabs.value.length === 0) {
curTab.value = 'welcome';
return;
}
for (let i = 0; i < navs.value.length; i++) {
if (navs.value[i].tab === tabs.value[tabs.value.length - 1]) {
addTab(navs.value[i]);
}
}
}
</script>
<style scoped lang="stylus">
$sideBgColor = #252526;
$borderColor = #4676d0;
.admin-body {
.el-aside {
background-color: $sideBgColor;
.title {
text-align: center;
line-height: 60px;
color: #fff;
font-size: 20px;
border-bottom: 2px solid #333841;
display flex
flex-direction row
.logo {
background-color #ffffff
border-radius 50%;
width 32px;
height 32px;
margin: 12px 5px 0 5px;
}
.fold {
cursor: pointer;
position: relative;
top: 2px;
margin-left 10px;
}
}
.title.hide {
.text {
display none
}
.logo {
display none
}
.fold {
margin-left 5px;
}
}
.nav-list {
list-style: none;
position: relative;
margin: 0;
padding-left: 0;
text-align: left;
li {
line-height: 40px;
color: #ffffff;
font-size: 14px;
cursor: pointer;
padding: 0 10px 0 10px;
border-bottom: 1px dashed #333841;
i {
margin-right: 6px;
position: relative;
top: 1px;
}
.delete {
float: right;
}
}
li.active {
background-color: #363535
}
}
.nav-footer {
flex-direction column
div {
padding 10px 20px;
font-size 14px;
color #aaaaaa
.el-link {
color #aaaaaa
}
.iconfont {
margin-right 5px
position relative
top 1px
}
}
.logout {
cursor pointer
}
}
}
.el-main {
--el-main-padding: 0;
margin: 0;
.main-container {
display: flex;
flex-flow: column;
.el-tabs {
background: #ffffff;
padding 10px 20px;
}
}
}
}
</style>
<style lang="stylus">
.pagination {
padding-top 20px;
display flex
justify-content center
width 100%
}
.el-tabs__item {
height 35px
line-height 35px
}
.el-tabs__content {
padding-bottom 20px;
}
</style>

View File

@@ -132,7 +132,7 @@ const save = function () {
const remove = function (row) {
httpGet('/api/admin/apikey/remove?id=' + row.id).then(() => {
ElMessage.success("删除成功")
item.value = removeArrayItem(items.value, row, (v1, v2) => {
items.value = removeArrayItem(items.value, row, (v1, v2) => {
return v1.id === v2.id
})
}).catch((e) => {

View File

@@ -0,0 +1,120 @@
<template>
<div class="dashboard">
<el-row class="mgb20" :gutter="20">
<el-col :span="8">
<el-card shadow="hover" :body-style="{ padding: '0px' }">
<div class="grid-content grid-con-1">
<el-icon class="grid-con-icon">
<User/>
</el-icon>
<div class="grid-cont-right">
<div class="grid-num">{{ stats.users }}</div>
<div>今日新增用户</div>
</div>
</div>
</el-card>
</el-col>
<el-col :span="8">
<el-card shadow="hover" :body-style="{ padding: '0px' }">
<div class="grid-content grid-con-2">
<el-icon class="grid-con-icon">
<ChatDotRound/>
</el-icon>
<div class="grid-cont-right">
<div class="grid-num">{{ stats.chats }}</div>
<div>今日新增对话</div>
</div>
</div>
</el-card>
</el-col>
<el-col :span="8">
<el-card shadow="hover" :body-style="{ padding: '0px' }">
<div class="grid-content grid-con-3">
<el-icon class="grid-con-icon">
<TrendCharts/>
</el-icon>
<div class="grid-cont-right">
<div class="grid-num">{{ stats.tokens }}</div>
<div>今日消耗 Tokens</div>
</div>
</div>
</el-card>
</el-col>
</el-row>
</div>
</template>
<script setup>
import {ref} from 'vue';
import {ChatDotRound, TrendCharts, User} from "@element-plus/icons-vue";
import {httpGet} from "@/utils/http";
import {ElMessage} from "element-plus";
const stats = ref({users: 0, chats: 0, tokens: 0})
httpGet('/api/admin/dashboard/stats').then((res) => {
stats.value.users = res.data.users
stats.value.chats = res.data.chats
stats.value.tokens = res.data.tokens
}).catch((e) => {
ElMessage.error("获取统计数据失败:" + e.message)
})
</script>
<style scoped lang="stylus">
.dashboard {
.grid-content {
display: flex;
align-items: center;
height: 100px;
}
.grid-cont-right {
flex: 1;
text-align: center;
font-size: 14px;
color: #999;
}
.grid-num {
font-size: 30px;
font-weight: bold;
}
.grid-con-icon {
font-size: 50px;
width: 100px;
height: 100px;
text-align: center;
line-height: 100px;
color: #fff;
}
.grid-con-1 .grid-con-icon {
background: rgb(45, 140, 240);
}
.grid-con-1 .grid-num {
color: rgb(45, 140, 240);
}
.grid-con-2 .grid-con-icon {
background: rgb(100, 213, 114);
}
.grid-con-2 .grid-num {
color: rgb(100, 213, 114);
}
.grid-con-3 .grid-con-icon {
background: rgb(242, 94, 67);
}
.grid-con-3 .grid-num {
color: rgb(242, 94, 67);
}
}
</style>

View File

@@ -1,8 +1,8 @@
<template>
<div class="admin-home" v-if="isLogin">
<admin-header/>
<admin-sidebar/>
<div class="content-box" :class="{ 'content-collapse': sidebar.collapse }">
<admin-header/>
<admin-tags/>
<div class="content">
<router-view v-slot="{ Component }">

View File

@@ -1,11 +1,7 @@
<template>
<div class="admin-login">
<div class="bg"></div>
<div class="main">
<div class="contain">
<div class="logo">
<el-image src="../images/logo.png" fit="cover"/>
</div>
<div class="header">{{ title }}</div>
<div class="content">
<div class="block">
@@ -53,7 +49,7 @@ import {useRouter} from "vue-router";
import FooterBar from "@/components/FooterBar.vue";
const router = useRouter();
const title = ref('ChatGPT-PLUS 控制台登录');
const title = ref('ChatGPT Plus Admin');
const username = ref(process.env.VUE_APP_ADMIN_USER);
const password = ref(process.env.VUE_APP_ADMIN_PASS);
@@ -86,51 +82,29 @@ const login = function () {
<style lang="stylus" scoped>
.admin-login {
.bg {
position fixed
left 0
right 0
top 0
bottom 0
background-color #313237
background-image url("~@/assets/img/admin-login-bg.jpg")
background-size cover
background-position center
background-repeat no-repeat
filter: blur(10px); /* 调整模糊程度,可以根据需要修改值 */
}
display flex
justify-content center
width: 100%
background #2D3A4B
.main {
width 400px;
display flex
justify-content center
align-items center
height 100vh
.contain {
position fixed
left 50%
top 40%
width 90%
max-width 400px;
transform translate(-50%, -50%)
width 100%
padding 20px 40px;
color #ffffff
border-radius 10px;
background rgba(255, 255, 255, 0.3)
.logo {
text-align center
.el-image {
width 120px;
.el-image__inner {
height 100%
}
}
}
.header {
width 100%
margin-bottom 24px
margin-bottom 20px
font-size 24px
color $white_v1
letter-space 2px
text-align center
}
@@ -169,6 +143,7 @@ const login = function () {
}
}
.footer {
color #ffffff;

View File

@@ -46,7 +46,6 @@ onMounted(() => {
// 获取数据
const fetchList = function (_page, _pageSize) {
console.log(_page, _pageSize)
httpGet(`/api/admin/user/loginLog?page=${_page}&page_size=${_pageSize}`).then((res) => {
if (res.data) {
items.value = res.data.items

View File

@@ -0,0 +1,75 @@
<template>
<div class="container list" v-loading="loading">
<el-row>
<el-table :data="items" :row-key="row => row.id">
<el-table-column prop="username" label="用户名"/>
<el-table-column prop="tx_id" label="转账单号"/>
<el-table-column prop="amount" label="转账金额"/>
<el-table-column label="转账时间">
<template #default="scope">
<span>{{ dateFormat(scope.row['created_at']) }}</span>
</template>
</el-table-column>
<el-table-column label="核销时间">
<template #default="scope">
<span v-if="scope.row['status']">{{ dateFormat(scope.row['updated_at']) }}</span>
<el-tag v-else>未核销</el-tag>
</template>
</el-table-column>
</el-table>
</el-row>
</div>
</template>
<script setup>
import {reactive, ref} from "vue";
import {httpGet, httpPost} from "@/utils/http";
import {ElMessage} from "element-plus";
import {dateFormat, disabledDate, removeArrayItem} from "@/utils/libs";
import {Plus} from "@element-plus/icons-vue";
// 变量定义
const items = ref([])
const loading = ref(true)
// 获取数据
httpGet('/api/admin/reward/list').then((res) => {
if (res.data) {
// 初始化数据
const arr = res.data;
for (let i = 0; i < arr.length; i++) {
arr[i].last_used_at = dateFormat(arr[i].last_used_at)
}
items.value = arr
}
loading.value = false
}).catch(() => {
ElMessage.error("获取数据失败");
})
</script>
<style lang="stylus" scoped>
.list {
.opt-box {
padding-bottom: 10px;
display flex;
justify-content flex-end
.el-icon {
margin-right: 5px;
}
}
.el-select {
width: 100%
}
}
</style>

View File

@@ -36,7 +36,7 @@
</template>
</el-table-column>
<el-table-column label="打招呼信息" prop="hello_msg"/>
<el-table-column label="操作" width="180" align="right">
<el-table-column label="操作" width="150" align="right">
<template #default="scope">
<el-button size="small" type="primary" @click="rowEdit(scope.$index, scope.row)">编辑</el-button>
<el-popconfirm title="确定要删除当前角色吗?" @confirm="removeRole(scope.row)">

View File

@@ -12,6 +12,9 @@
<el-form-item label="注册赠送次数" prop="init_calls">
<el-input v-model.number="system['user_init_calls']" placeholder="新用户注册赠送对话次数"/>
</el-form-item>
<el-form-item label="开放用户注册" prop="init_calls">
<el-switch v-model="system['enabled_register']"/>
</el-form-item>
<el-alert type="info" show-icon :closable="false">
<p>在这里维护前端聊天页面可用的 GPT 模型列表</p>
</el-alert>
@@ -65,6 +68,14 @@
<el-switch v-model="chat['enable_history']"/>
</el-form-item>
<el-alert type="info" show-icon :closable="false">
<p>会话上下文深度在老会话中继续会话默认加载多少条聊天记录作为上下文如果设置为 0
则不加载聊天记录仅仅使用当前角色的上下文该配置参数最好设置为 2 的整数倍</p>
</el-alert>
<el-form-item label="会话上下文深度">
<el-input-number v-model="chat['context_deep']" :min="0" :max="10"/>
</el-form-item>
<el-form-item style="text-align: right">
<el-button type="primary" @click="save('chat')">保存</el-button>
</el-form-item>
@@ -178,6 +189,10 @@ const addModel = function () {
font-size 16px;
}
}
.tip-text {
padding-left 10px;
}
}
}

View File

@@ -1,10 +1,19 @@
<template>
<div class="container user-list" v-loading="loading">
<div class="handle-box">
<el-input v-model="query.username" placeholder="用户名" class="handle-input mr10"></el-input>
<el-input v-model="query.mobile" placeholder="手机号码" class="handle-input mr10"></el-input>
<el-button type="primary" :icon="Search" @click="handleSearch">搜索</el-button>
<el-button type="success" :icon="Plus" @click="addUser">新增用户</el-button>
</div>
<el-row>
<el-table :data="users.items" border class="table" :row-key="row => row.id"
@selection-change="handleSelectionChange">
<el-table-column type="selection" width="38"/>
<el-table-column prop="username" label="用户名"/>
<el-table-column prop="mobile" label="手机号"/>
<el-table-column prop="nickname" label="昵称"/>
<el-table-column prop="calls" label="提问次数" width="100"/>
<el-table-column label="状态" width="80">
@@ -26,10 +35,13 @@
</template>
</el-table-column>
<el-table-column label="操作" width="180">
<el-table-column fixed="right" label="操作" width="200">
<template #default="scope">
<el-button size="small" type="primary" @click="userEdit(scope.row)">编辑</el-button>
<el-button size="small" type="danger" @click="removeUser(scope.row)">删除</el-button>
<el-button-group class="ml-4">
<el-button size="small" type="primary" @click="userEdit(scope.row)">编辑</el-button>
<el-button size="small" type="danger" @click="removeUser(scope.row)">删除</el-button>
<el-button size="small" type="success" @click="resetPass(scope.row)">重置密码</el-button>
</el-button-group>
</template>
</el-table-column>
</el-table>
@@ -49,14 +61,24 @@
<el-dialog
v-model="showUserEditDialog"
title="编辑用户"
:title="title"
width="50%"
>
<el-form :model="user" label-width="100px" ref="userEditFormRef" :rules="rules">
<el-form-item label="昵称" prop="nickname">
<el-form-item v-if="add" label="用户名" prop="username">
<el-input v-model="user.username" autocomplete="off"/>
</el-form-item>
<el-form-item v-else label="昵称" prop="nickname">
<el-input v-model="user.nickname" autocomplete="off"/>
</el-form-item>
<el-form-item v-if="add" label="密码" prop="password">
<el-input v-model="user.password" autocomplete="off"/>
</el-form-item>
<el-form-item label="手机号" prop="mobile">
<el-input v-model="user.mobile" autocomplete="off"/>
</el-form-item>
<el-form-item label="提问次数" prop="calls">
<el-input v-model.number="user.calls" autocomplete="off" placeholder="0"/>
</el-form-item>
@@ -96,10 +118,33 @@
<template #footer>
<span class="dialog-footer">
<el-button @click="showUserEditDialog = false">取消</el-button>
<el-button type="primary" @click="updateUser">提交</el-button>
<el-button type="primary" @click="saveUser">提交</el-button>
</span>
</template>
</el-dialog>
<el-dialog
v-model="showResetPassDialog"
title="重置密码"
width="50%"
>
<el-form label-width="100px" ref="userEditFormRef">
<el-form-item label="用户名">
<el-input v-model="pass.username" autocomplete="off" readonly disabled/>
</el-form-item>
<el-form-item label="新密码">
<el-input v-model="pass.password" autocomplete="off"/>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button type="primary" @click="doResetPass">提交</el-button>
</span>
</template>
</el-dialog>
</div>
</template>
@@ -108,15 +153,24 @@ import {nextTick, onMounted, reactive, ref} from "vue";
import {httpGet, httpPost} from "@/utils/http";
import {ElMessage, ElMessageBox} from "element-plus";
import {dateFormat, disabledDate, removeArrayItem} from "@/utils/libs";
import {Plus, Search} from "@element-plus/icons-vue";
// 变量定义
const users = ref({page: 1, page_size: 15})
const users = ref({page: 1, page_size: 15, items: []})
const query = ref({username: '', mobile: '', page: 1, page_size: 15})
const title = ref('添加用户')
const add = ref(true)
const user = ref({chat_roles: []})
const pass = ref({username: '', password: '', id: 0})
const roles = ref([])
const showUserEditDialog = ref(false)
const showResetPassDialog = ref(false)
const rules = reactive({
username: [{required: true, message: '请输入用户名', trigger: 'change',}],
nickname: [{required: true, message: '请输入昵称', trigger: 'change',}],
password: [{required: true, message: '请输入密码', trigger: 'change',}],
mobile: [{required: true, message: '请输入手机号码', trigger: 'change',}],
calls: [
{required: true, message: '请输入提问次数'},
{type: 'number', message: '请输入有效数字'},
@@ -142,7 +196,9 @@ onMounted(() => {
})
const fetchUserList = function (page, pageSize) {
httpGet('/api/admin/user/list', {page: page, page_size: pageSize}).then((res) => {
query.value.page = page
query.value.page_size = pageSize
httpGet('/api/admin/user/list', query.value).then((res) => {
if (res.data) {
// 初始化数据
const arr = res.data.items;
@@ -159,6 +215,10 @@ const fetchUserList = function (page, pageSize) {
})
}
const handleSearch = () => {
fetchUserList(users.value.page, users.value.page_size)
}
// 删除用户
const removeUser = function (user) {
ElMessageBox.confirm(
@@ -169,35 +229,44 @@ const removeUser = function (user) {
cancelButtonText: '取消',
type: 'warning',
}
)
.then(() => {
httpGet('/api/admin/user/remove', {id: user.id}).then(() => {
ElMessage.success('操作成功!')
users.value.items = removeArrayItem(users.value.items, user, function (v1, v2) {
return v1.id === v2.id
})
}).catch((e) => {
ElMessage.error('操作失败,' + e.message)
})
})
.catch(() => {
ElMessage.info('操作被取消')
).then(() => {
httpGet('/api/admin/user/remove', {id: user.id}).then(() => {
ElMessage.success('操作成功!')
users.value.items = removeArrayItem(users.value.items, user, function (v1, v2) {
return v1.id === v2.id
})
}).catch((e) => {
ElMessage.error('操作失败,' + e.message)
})
}).catch(() => {
ElMessage.info('操作被取消')
})
}
const userEdit = function (_user) {
user.value = _user
const userEdit = function (row) {
user.value = row
title.value = '编辑用户'
showUserEditDialog.value = true
add.value = false
}
// 更新口令
const updateUser = function () {
const addUser = () => {
user.value = {}
title.value = '添加用户'
showUserEditDialog.value = true
add.value = true
}
const saveUser = function () {
userEditFormRef.value.validate((valid) => {
if (valid) {
showUserEditDialog.value = false
httpPost('/api/admin/user/update', user.value).then(() => {
httpPost('/api/admin/user/save', user.value).then((res) => {
ElMessage.success('操作成功!')
if (add.value) {
users.value.items.push(res.data)
}
}).catch((e) => {
ElMessage.error('操作失败,' + e.message)
})
@@ -211,11 +280,38 @@ const handleSelectionChange = function (rows) {
// TODO: 批量删除操作
console.log(rows)
}
const resetPass = (row) => {
showResetPassDialog.value = true
pass.value.id = row.id
pass.value.username = row.username
}
const doResetPass = () => {
httpPost('/api/admin/user/resetPass', pass.value).then(() => {
ElMessage.success('操作成功!')
showResetPassDialog.value = false
}).catch((e) => {
ElMessage.error('操作失败,' + e.message)
})
}
</script>
<style lang="stylus" scoped>
.user-list {
.handle-box {
.handle-input {
max-width 150px;
margin-right 10px;
}
}
.table {
width 100%
}
.opt-box {
padding-bottom: 10px;

View File

@@ -1,25 +0,0 @@
<template>
<div class="welcome">
<h1>ChatGPT-PLUS 控制台</h1>
</div>
</template>
<script setup></script>
<style lang="stylus" scoped>
.welcome {
display: flex;
justify-content: center;
align-items: center;
color: #202020;
background-color: #282c34;
height 100%;
h1 {
font-size: 300%;
font-weight: bold;
letter-spacing: 0.1em;
text-shadow: -1px -1px 1px #111111, 2px 2px 1px #363636;
}
}
</style>

View File

@@ -11,8 +11,8 @@
<el-button type="primary" :icon="Search" @click="handleSearch">搜索</el-button>
<el-button type="primary" :icon="Plus">新增</el-button>
</div>
<el-table :data="tableData" border class="table" ref="multipleTable" header-cell-class-name="table-header">
<el-table-column prop="id" label="ID" width="55" align="center"></el-table-column>
<el-table :data="tableData" border class="table" style="width: 100%" header-cell-class-name="table-header">
<el-table-column prop="id" fixed label="ID" width="55" align="center"></el-table-column>
<el-table-column prop="name" label="姓名"></el-table-column>
<el-table-column label="头像(查看大图)" align="center">
<template #default="scope">
@@ -38,7 +38,7 @@
</el-table-column>
<el-table-column prop="date" label="注册时间"></el-table-column>
<el-table-column label="操作" width="220" align="center">
<el-table-column label="操作" fixed="right" align="center">
<template #default="scope">
<el-button text :icon="Edit" @click="handleEdit(scope.$index, scope.row)">
编辑

View File

@@ -97,9 +97,6 @@ const showBindMobileDialog = ref(false)
checkSession().then((user) => {
loginUser.value = user
isLogin.value = true
if (user.mobile === '') {
showBindMobileDialog.value = true
}
// 加载角色列表
httpGet(`/api/role/list?user_id=${user.id}`).then((res) => {
if (res.data) {