From 21111126a298055b9f60c37f75194e4b64bb7a55 Mon Sep 17 00:00:00 2001 From: JustSong Date: Sat, 17 Jun 2023 11:30:31 +0800 Subject: [PATCH 1/4] docs: update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4ce1eec7..f3576165 100644 --- a/README.md +++ b/README.md @@ -55,10 +55,10 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用 + [x] [API2D](https://api2d.com/r/197971) + [x] [OhMyGPT](https://aigptx.top?aff=uFpUl2Kf) + [x] [AI Proxy](https://aiproxy.io/?i=OneAPI) (邀请码:`OneAPI`) - + [x] [AI.LS](https://ai.ls) - + [x] [OpenAI Max](https://openaimax.com) + [x] [OpenAI-SB](https://openai-sb.com) + [x] [CloseAI](https://console.openai-asia.com/r/2412) + + [x] [AI.LS](https://ai.ls) + + [x] [OpenAI Max](https://openaimax.com) + [x] 自定义渠道:例如各种未收录的第三方代理服务 2. 支持通过**负载均衡**的方式访问多个渠道。 3. 支持 **stream 模式**,可以通过流式传输实现打字机效果。 From d754620ef7eb98855456d2d8103766ed20ebf1e6 Mon Sep 17 00:00:00 2001 From: JustSong Date: Sat, 17 Jun 2023 12:07:58 +0800 Subject: [PATCH 2/4] docs: update README --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f3576165..746cc52b 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,9 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用 ## 部署 ### 基于 Docker 进行部署 -执行:`docker run -d --restart always -p 3000:3000 -v /home/ubuntu/data/one-api:/data justsong/one-api` +部署命令:`docker run -d --restart always -p 3000:3000 -v /home/ubuntu/data/one-api:/data justsong/one-api` + +更新命令:`docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -cR` `-p 3000:3000` 中的第一个 `3000` 是宿主机的端口,可以根据需要进行修改。 @@ -208,7 +210,7 @@ graph LR + 例子:`REDIS_CONN_STRING=redis://default:redispw@localhost:49153` 2. `SESSION_SECRET`:设置之后将使用固定的会话密钥,这样系统重新启动后已登录用户的 cookie 将依旧有效。 + 例子:`SESSION_SECRET=random_string` -3. `SQL_DSN`:设置之后将使用指定数据库而非 SQLite。 +3. `SQL_DSN`:设置之后将使用指定数据库而非 SQLite,请使用 MySQL 8.0 版本。 + 例子:`SQL_DSN=root:123456@tcp(localhost:3306)/one-api` 4. `FRONTEND_BASE_URL`:设置之后将使用指定的前端地址,而非后端地址。 + 例子:`FRONTEND_BASE_URL=https://openai.justsong.cn` From 6dcffca06521f03d97e3002616fe51e5195a2fd8 Mon Sep 17 00:00:00 2001 From: JustSong Date: Sat, 17 Jun 2023 12:55:48 +0800 Subject: [PATCH 3/4] docs: update README --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 746cc52b..495039b8 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用 ## 部署 ### 基于 Docker 进行部署 -部署命令:`docker run -d --restart always -p 3000:3000 -v /home/ubuntu/data/one-api:/data justsong/one-api` +部署命令:`docker run --name one-api -d --restart always -p 3000:3000 -v /home/ubuntu/data/one-api:/data justsong/one-api` 更新命令:`docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -cR` @@ -154,6 +154,26 @@ sudo service nginx restart 环境变量的具体使用方法详见[此处](#环境变量)。 +### 部署第三方服务配合 One API 使用 +> 欢迎 PR 添加更多示例。 + +#### ChatGPT Next Web +项目主页:https://github.com/Yidadaa/ChatGPT-Next-Web + +```bash +docker run --name chat-next-web -d -p 3001:3000 -e BASE_URL=https://openai.justsong.cn yidadaa/chatgpt-next-web +``` + +注意修改端口号和 `BASE_URL`。 + +#### ChatGPT Web +项目主页:https://github.com/Chanzhaoyu/chatgpt-web + +```bash +docker run --name chatgpt-web -d -p 3002:3002 -e OPENAI_API_BASE_URL=https://openai.justsong.cn -e OPENAI_API_KEY=sk-xxx chenzhaoyu94/chatgpt-web +``` + +注意修改端口号、`OPENAI_API_BASE_URL` 和 `OPENAI_API_KEY`。 ### 部署到第三方平台
From 46c43396d8f8c23ad2c3f2f5a669475ea7a3794c Mon Sep 17 00:00:00 2001 From: Miniers Date: Sat, 17 Jun 2023 14:56:03 +0800 Subject: [PATCH 4/4] feat: add token name to log (#172) * add token name to log * chore: update expression --------- Co-authored-by: JustSong --- controller/relay.go | 3 ++- middleware/auth.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/controller/relay.go b/controller/relay.go index cf01f180..6d957a0a 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -259,8 +259,9 @@ func relayHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode { if err != nil { common.SysError("Error consuming token remain quota: " + err.Error()) } + tokenName := c.GetString("token_name") userId := c.GetInt("id") - model.RecordLog(userId, model.LogTypeConsume, fmt.Sprintf("使用模型 %s 消耗 %d 点额度(模型倍率 %.2f,分组倍率 %.2f)", textRequest.Model, quota, modelRatio, groupRatio)) + model.RecordLog(userId, model.LogTypeConsume, fmt.Sprintf("通过令牌「%s」使用模型 %s 消耗 %d 点额度(模型倍率 %.2f,分组倍率 %.2f)", tokenName, textRequest.Model, quota, modelRatio, groupRatio)) model.UpdateUserUsedQuotaAndRequestCount(userId, quota) channelId := c.GetInt("channel_id") model.UpdateChannelUsedQuota(channelId, quota) diff --git a/middleware/auth.go b/middleware/auth.go index f652f058..c172078c 100644 --- a/middleware/auth.go +++ b/middleware/auth.go @@ -112,6 +112,7 @@ func TokenAuth() func(c *gin.Context) { } c.Set("id", token.UserId) c.Set("token_id", token.Id) + c.Set("token_name", token.Name) requestURL := c.Request.URL.String() consumeQuota := true if strings.HasPrefix(requestURL, "/v1/models") {