Update README.md

This commit is contained in:
analogpvt 2023-05-19 22:29:14 +05:30 committed by GitHub
parent ef9dca28f5
commit 8c01296a34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

190
README.md
View File

@ -1,12 +1,12 @@
<p align="center"> <p align="center">
<a href="https://github.com/songquanpeng/one-api"><img src="https://raw.githubusercontent.com/songquanpeng/one-api/main/web/public/logo.png" width="150" height="150" alt="one-api logo"></a> <a href="https://github.com/songquanpeng/one-api"><img src="https://raw.githubusercontent.com/songquanpeng/one-api/main/web/public/logo.png " width="150" height="150" alt="one-api logo"></a>
</p> </p>
<div align="center"> <div align="center">
# One API # One API
_✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用✨_ _✨All in one's OpenAI interface, integrating various API access methods, out of the box✨_
</div> </div>
@ -29,25 +29,25 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用
</p> </p>
<p align="center"> <p align="center">
<a href="https://github.com/songquanpeng/one-api/releases">程序下载</a> <a href="https://github.com/songquanpeng/one-api/releases">Program Download</a>
· ·
<a href="https://github.com/songquanpeng/one-api#部署">部署教程</a> <a href="https://github.com/songquanpeng/one-api#deployment">Deployment Tutorial</a>
· ·
<a href="https://github.com/songquanpeng/one-api/issues">意见反馈</a> <a href="https://github.com/songquanpeng/one-api/issues">Feedback</a>
· ·
<a href="https://github.com/songquanpeng/one-api#截图展示">截图展示</a> <a href="https://github.com/songquanpeng/one-api#Screenshot display">Screenshot display</a>
· ·
<a href="https://openai.justsong.cn/">在线演示</a> <a href="https://openai.justsong.cn/">Online Demo</a>
· ·
<a href="https://github.com/songquanpeng/one-api#常见问题">常见问题</a> <a href="https://github.com/songquanpeng/one-api#FAQ">FAQ</a>
</p> </p>
> **Warning**:从 `v0.2` 版本升级到 `v0.3` 版本需要手动迁移数据库,请手动执行[数据库迁移脚本](./bin/migration_v0.2-v0.3.sql)。 > **Warning**: Upgrading from `v0.2` to `v0.3` requires manual database migration, please manually execute [database migration script](./bin/migration_v0.2-v0.3.sql) .
## 功能 ## Function
1. 支持多种 API 访问渠道,欢迎 PR 或提 issue 添加更多渠道: 1. Multiple API access channels are supported. PRs or issues are welcome to add more channels:
+ [x] OpenAI 官方通道 + [x] OpenAI official channel
+ [x] **Azure OpenAI API** + [x] **Azure OpenAI API**
+ [x] [API2D](https://api2d.com/r/197971) + [x] [API2D](https://api2d.com/r/197971)
+ [x] [OhMyGPT](https://aigptx.top?aff=uFpUl2Kf) + [x] [OhMyGPT](https://aigptx.top?aff=uFpUl2Kf)
@ -55,41 +55,41 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用
+ [x] [OpenAI Max](https://openaimax.com) + [x] [OpenAI Max](https://openaimax.com)
+ [x] [OpenAI-SB](https://openai-sb.com) + [x] [OpenAI-SB](https://openai-sb.com)
+ [x] [CloseAI](https://console.openai-asia.com) + [x] [CloseAI](https://console.openai-asia.com)
+ [x] 自定义渠道:例如使用自行搭建的 OpenAI 代理 + [x] Custom channels: e.g. using a self-built OpenAI agent
2. 支持通过**负载均衡**的方式访问多个渠道。 2. Support access to multiple channels through **load balancing**.
3. 支持 **stream 模式**,可以通过流式传输实现打字机效果。 3. Support **stream mode**, you can achieve typewriter effect through streaming.
4. 支持**多机部署**[详见此处](#多机部署)。 4. Support **multi-machine deployment**, [see here for details](#multi-machine deployment).
5. 支持**令牌管理**,设置令牌的过期时间和使用次数。 5. Support **token management**, set the expiration time and usage times of the token.
6. 支持**兑换码管理**,支持批量生成和导出兑换码,可使用兑换码为账户进行充值。 6. Supports **redemption code management**, supports batch generation and export of redemption codes, and can use redemption codes to recharge accounts.
7. 支持**通道管理**,批量创建通道。 7. Support **channel management**, create channels in batches.
8. 支持发布公告,设置充值链接,设置新用户初始额度。 8. Support for publishing announcements, setting recharge links, and setting initial quotas for new users.
9. 支持丰富的**自定义**设置, 9. Support rich **custom** settings,
1. 支持自定义系统名称logo 以及页脚。 1. Support custom system name, logo and footer.
2. 支持自定义首页和关于页面,可以选择使用 HTML & Markdown 代码进行自定义,或者使用一个单独的网页通过 iframe 嵌入。 2. Support custom homepage and about page, you can choose to use HTML & Markdown code to customize, or use a separate webpage to embed through iframe.
10. 支持通过系统访问令牌访问管理 API。 10. Support accessing management API through system access token.
11. 支持用户管理,支持**多种用户登录注册方式** 11. Support user management, support **multiple user login and registration methods**:
+ 邮箱登录注册以及通过邮箱进行密码重置。 + Email login registration and password reset through email.
+ [GitHub 开放授权](https://github.com/settings/applications/new)。 + [GitHub Open License](https://github.com/settings/applications/new).
+ 微信公众号授权(需要额外部署 [WeChat Server](https://github.com/songquanpeng/wechat-server))。 + WeChat official account authorization (requires additional deployment of [WeChat Server](https://github.com/songquanpeng/wechat-server)).
12. 未来其他大模型开放 API 后,将第一时间支持,并将其封装成同样的 API 访问方式。 12. In the future, after other large models open their APIs, they will be supported as soon as possible and encapsulated into the same API access method.
## 部署 ## deployment
### 基于 Docker 进行部署 ### Deploy based on Docker
执行:`docker run -d --restart always -p 3000:3000 -v /home/ubuntu/data/one-api:/data justsong/one-api` Execution: `docker run -d --restart always -p 3000:3000 -v /home/ubuntu/data/one-api:/data justsong/one-api`
`-p 3000:3000` 中的第一个 `3000` 是宿主机的端口,可以根据需要进行修改。 The first `3000` in `-p 3000:3000` is the port of the host machine, which can be modified as needed.
数据将会保存在宿主机的 `/home/ubuntu/data/one-api` 目录,请确保该目录存在且具有写入权限,或者更改为合适的目录。 The data will be saved in the `/home/ubuntu/data/one-api` directory of the host machine, please make sure the directory exists and has write permission, or change to a suitable directory.
Nginx 的参考配置: Reference configuration of Nginx:
``` ```
server{ server {
server_name openai.justsong.cn; # 请根据实际情况修改你的域名 server_name openai.justsong.cn; # Please modify your domain name according to the actual situation
location / { location / {
client_max_body_size 64m; client_max_body_size 64m;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_pass http://localhost:3000; # 请根据实际情况修改你的端口 proxy_pass http://localhost:3000; # Please modify your port according to the actual situation
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-For $remote_addr;
proxy_cache_bypass $http_upgrade; proxy_cache_bypass $http_upgrade;
@ -98,99 +98,99 @@ server{
} }
``` ```
之后使用 Let's Encrypt 的 certbot 配置 HTTPS Then configure HTTPS with Let's Encrypt's certbot:
```bash ```bash
# Ubuntu 安装 certbot # Ubuntu install certbot:
sudo snap install --classic certbot sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot sudo ln -s /snap/bin/certbot /usr/bin/certbot
# 生成证书 & 修改 Nginx 配置 # Generate certificate & modify Nginx configuration
sudo certbot --nginx sudo certbot --nginx
# 根据指示进行操作 # Follow instructions
# 重启 Nginx # restart nginx
sudo service nginx restart sudo service nginx restart
``` ```
### 手动部署 ### Manual deployment
1. 从 [GitHub Releases](https://github.com/songquanpeng/one-api/releases/latest) 下载可执行文件或者从源码编译: 1. Download the executable from [GitHub Releases](https://github.com/songquanpeng/one-api/releases/latest) or compile from source:
```shell ```shell
git clone https://github.com/songquanpeng/one-api.git git clone https://github.com/songquanpeng/one-api.git
# 构建前端 # Build the front end
cd one-api/web cd one-api/web
npm install npm install
npm run build npm run build
# 构建后端 # Build the backend
cd .. cd..
go mod download go mod download
go build -ldflags "-s -w" -o one-api go build -ldflags "-s -w" -o one-api
```` ````
2. 运行: 2. Run:
```shell ```shell
chmod u+x one-api chmod u+x one-api
./one-api --port 3000 --log-dir ./logs ./one-api --port 3000 --log-dir ./logs
``` ```
3. 访问 [http://localhost:3000/](http://localhost:3000/) 并登录。初始账号用户名为 `root`,密码为 `123456` 3. Visit [http://localhost:3000/](http://localhost:3000/) and log in. The initial account username is `root`, and the password is `123456`.
更加详细的部署教程[参见此处](https://iamazing.cn/page/how-to-deploy-a-website)。 A more detailed deployment tutorial [see here](https://iamazing.cn/page/how-to-deploy-a-website).
### 多机部署 ### Multi-machine deployment
1. 所有服务器 `SESSION_SECRET` 设置一样的值。 1. All servers `SESSION_SECRET` set the same value.
2. 必须设置 `SQL_DSN`,使用 MySQL 数据库而非 SQLite请自行配置主备数据库同步。 2. `SQL_DSN` must be set, use the MySQL database instead of SQLite, please configure the synchronization of the main and standby databases by yourself.
3. 所有从服务器必须设置 `SYNC_FREQUENCY`,以定期从数据库同步配置。 3. All slave servers must set `SYNC_FREQUENCY` to periodically synchronize configuration from the database.
4. 从服务器可以选择设置 `FRONTEND_BASE_URL`,以重定向页面请求到主服务器。 4. The slave server can optionally set `FRONTEND_BASE_URL` to redirect page requests to the master server.
环境变量的具体使用方法详见[此处](#环境变量)。 For details on how to use environment variables, see [here](#environment variables).
## 配置 ## configuration
系统本身开箱即用。 The system itself works out of the box.
你可以通过设置环境变量或者命令行参数进行配置。 You can configure it by setting environment variables or command line parameters.
等到系统启动后,使用 `root` 用户登录系统并做进一步的配置。 After the system starts, use `root` user to log in to the system and do further configuration.
## 使用方式 ## How to use
在`渠道`页面中添加你的 API Key之后在`令牌`页面中新增一个访问令牌。 Add your API Key in the `Channels` page, and then add an access token in the `Tokens` page.
之后就可以使用你的令牌访问 One API 了,使用方式与 [OpenAI API](https://platform.openai.com/docs/api-reference/introduction) 一致。 Then you can use your token to access the One API in the same way as [OpenAI API](https://platform.openai.com/docs/api-reference/introduction).
可以通过在令牌后面添加渠道 ID 的方式指定使用哪一个渠道处理本次请求,例如:`Authorization: Bearer ONE_API_KEY-CHANNEL_ID`。 You can specify which channel to use to process this request by adding the channel ID after the token, for example: `Authorization: Bearer ONE_API_KEY-CHANNEL_ID`.
注意,需要是管理员用户创建的令牌才能指定渠道 ID。 Note that a token created by an admin user is required to specify a channel ID.
不加的话将会使用负载均衡的方式使用多个渠道。 If not added, multiple channels will be used in a load balancing manner.
### 环境变量 ### Environment variables
1. `REDIS_CONN_STRING`:设置之后将使用 Redis 作为请求频率限制的存储,而非使用内存存储。 1. `REDIS_CONN_STRING`: After setting, Redis will be used as the storage for request frequency limit instead ofUse memory storage.
+ 例子:`REDIS_CONN_STRING=redis://default:redispw@localhost:49153` + Example: `REDIS_CONN_STRING=redis://default:redispw@localhost:49153`
2. `SESSION_SECRET`:设置之后将使用固定的会话密钥,这样系统重新启动后已登录用户的 cookie 将依旧有效。 2. `SESSION_SECRET`: After setting, a fixed session key will be used, so that the logged-in user's cookie will still be valid after the system restarts.
+ 例子:`SESSION_SECRET=random_string` + Example: `SESSION_SECRET=random_string`
3. `SQL_DSN`:设置之后将使用指定数据库而非 SQLite。 3. `SQL_DSN`: After setting, the specified database will be used instead of SQLite.
+ 例子:`SQL_DSN=root:123456@tcp(localhost:3306)/one-api` + Example: `SQL_DSN=root:123456@tcp(localhost:3306)/one-api`
4. `FRONTEND_BASE_URL`:设置之后将使用指定的前端地址,而非后端地址。 4. `FRONTEND_BASE_URL`: After setting, the specified front-end address will be used instead of the back-end address.
+ 例子:`FRONTEND_BASE_URL=https://openai.justsong.cn` + Example: `FRONTEND_BASE_URL=https://openai.justsong.cn`
5. `SYNC_FREQUENCY`:设置之后将定期与数据库同步配置,单位为秒,未设置则不进行同步。 5. `SYNC_FREQUENCY`: After setting, the configuration will be periodically synchronized with the database, in seconds, if not set, no synchronization will be performed.
+ 例子:`SYNC_FREQUENCY=60` + Example: `SYNC_FREQUENCY=60`
### 命令行参数 ### Command Line Arguments
1. `--port <port_number>`: 指定服务器监听的端口号,默认为 `3000` 1. `--port <port_number>`: Specify the port number that the server listens to, the default is `3000`.
+ 例子:`--port 3000` + Example: `--port 3000`
2. `--log-dir <log_dir>`: 指定日志文件夹,如果没有设置,日志将不会被保存。 2. `--log-dir <log_dir>`: Specify the log folder, if not set, the log will not be saved.
+ 例子:`--log-dir ./logs` + Example: `--log-dir ./logs`
3. `--version`: 打印系统版本号并退出。 3. `--version`: Print system version number and exit.
4. `--help`: 查看命令的使用帮助和参数说明。 4. `--help`: View the help and parameter description of the command.
## 演示 ## Demo
### 在线演示 ### Online Demo
注意,该演示站不提供对外服务: Note that this demo site does not provide external services:
https://openai.justsong.cn https://openai.justsong.cn
### 截图展示 ### Screenshot display
![channel](https://user-images.githubusercontent.com/39998050/233837954-ae6683aa-5c4f-429f-a949-6645a83c9490.png) ![channel](https://user-images.githubusercontent.com/39998050/233837954-ae6683aa-5c4f-429f-a949-6645a83c9490.png)
![token](https://user-images.githubusercontent.com/39998050/233837971-dab488b7-6d96-43af-b640-a168e8d1c9bf.png) ![token](https://user-images.githubusercontent.com/39998050/233837971-dab488b7-6d96-43af-b640-a168e8d1c9bf.png)
## 常见问题 ## common problem
1. 账户额度足够为什么提示额度不足? 1. Why is it prompted that the account limit is insufficient?
+ 请检查你的令牌额度是否足够,这个和账户额度是分开的。 + Please check whether your token limit is sufficient, this is separate from the account limit.
+ 令牌额度仅供用户设置最大使用量,用户可自由设置。 + The token quota is only for the user to set the maximum usage, and the user can set it freely.
2. 宝塔部署后访问出现空白页面? 2. A blank page appears after the pagoda is deployed?
+ 自动配置的问题,详见[#97](https://github.com/songquanpeng/one-api/issues/97)。 + For automatic configuration issues, see [#97](https://github.com/songquanpeng/one-api/issues/97) for details.