Optimize the source code format of the README file

This commit is contained in:
Mrered Cio 2024-03-06 03:11:39 +08:00 committed by GitHub
parent 4fb22ad4ce
commit 6891a23094
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

122
README.md
View File

@ -63,6 +63,7 @@ _✨ 通过标准的 OpenAI API 格式访问所有的大模型,开箱即用
> 使用 root 用户初次登录系统后,务必修改默认密码 `123456` > 使用 root 用户初次登录系统后,务必修改默认密码 `123456`
## 功能 ## 功能
1. 支持多种大模型: 1. 支持多种大模型:
+ [x] [OpenAI ChatGPT 系列模型](https://platform.openai.com/docs/guides/gpt/chat-completions-api)(支持 [Azure OpenAI API](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference) + [x] [OpenAI ChatGPT 系列模型](https://platform.openai.com/docs/guides/gpt/chat-completions-api)(支持 [Azure OpenAI API](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference)
+ [x] [Anthropic Claude 系列模型](https://anthropic.com) + [x] [Anthropic Claude 系列模型](https://anthropic.com)
@ -107,12 +108,20 @@ _✨ 通过标准的 OpenAI API 格式访问所有的大模型,开箱即用
23. 支持主题切换,设置环境变量 `THEME` 即可,默认为 `default`,欢迎 PR 更多主题,具体参考[此处](./web/README.md)。 23. 支持主题切换,设置环境变量 `THEME` 即可,默认为 `default`,欢迎 PR 更多主题,具体参考[此处](./web/README.md)。
## 部署 ## 部署
### 基于 Docker 进行部署 ### 基于 Docker 进行部署
```shell
# 使用 SQLite 的部署命令: - 使用 SQLite 的部署命令:
```sh
docker run --name one-api -d --restart always -p 3000:3000 -e TZ=Asia/Shanghai -v /home/ubuntu/data/one-api:/data justsong/one-api docker run --name one-api -d --restart always -p 3000:3000 -e TZ=Asia/Shanghai -v /home/ubuntu/data/one-api:/data justsong/one-api
# 使用 MySQL 的部署命令,在上面的基础上添加 `-e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi"`,请自行修改数据库连接参数,不清楚如何修改请参见下面环境变量一节。 ```
# 例如:
- 使用 MySQL 的部署命令:
在上面的基础上添加 `-e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi"`,请自行修改数据库连接参数,不清楚如何修改请参见下面环境变量一节。例如:
```sh
docker run --name one-api -d --restart always -p 3000:3000 -e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi" -e TZ=Asia/Shanghai -v /home/ubuntu/data/one-api:/data justsong/one-api docker run --name one-api -d --restart always -p 3000:3000 -e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi" -e TZ=Asia/Shanghai -v /home/ubuntu/data/one-api:/data justsong/one-api
``` ```
@ -129,6 +138,7 @@ docker run --name one-api -d --restart always -p 3000:3000 -e SQL_DSN="root:1234
更新命令:`docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -cR` 更新命令:`docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -cR`
Nginx 的参考配置: Nginx 的参考配置:
``` ```
server{ server{
server_name openai.justsong.cn; # 请根据实际情况修改你的域名 server_name openai.justsong.cn; # 请根据实际情况修改你的域名
@ -147,57 +157,82 @@ server{
``` ```
之后使用 Let's Encrypt 的 certbot 配置 HTTPS 之后使用 Let's Encrypt 的 certbot 配置 HTTPS
```bash
# Ubuntu 安装 certbot - Ubuntu 安装 certbot
```sh
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 配置 ```
- 生成证书 & 修改 Nginx 配置
```sh
sudo certbot --nginx sudo certbot --nginx
# 根据指示进行操作 ```
# 重启 Nginx
- 根据指示进行操作
- 重启 Nginx
```sh
sudo service nginx restart sudo service nginx restart
``` ```
初始账号用户名为 `root`,密码为 `123456` 初始账号用户名为 `root`,密码为 `123456`
### 基于 Docker Compose 进行部署 ### 基于 Docker Compose 进行部署
> 仅启动方式不同,参数设置不变,请参考基于 Docker 部署部分 > 仅启动方式不同,参数设置不变,请参考基于 Docker 部署部分
```shell - 目前支持 MySQL 启动,数据存储在 ./data/mysql 文件夹内
# 目前支持 MySQL 启动,数据存储在 ./data/mysql 文件夹内
docker-compose up -d
# 查看部署状态 ```sh
docker-compose up -d
```
- 查看部署状态
```sh
docker-compose ps docker-compose ps
``` ```
### 手动部署 ### 手动部署
1. 从 [GitHub Releases](https://github.com/songquanpeng/one-api/releases/latest) 下载可执行文件或者从源码编译: 1. 从 [GitHub Releases](https://github.com/songquanpeng/one-api/releases/latest) 下载可执行文件或者从源码编译:
```shell
git clone https://github.com/songquanpeng/one-api.git ```sh
git clone https://github.com/songquanpeng/one-api.git
# 构建前端 ```
cd one-api/web/default
npm install 2. 构建前端
npm run build
```sh
# 构建后端 cd one-api/web/default
cd ../.. npm install
go mod download npm run build
go build -ldflags "-s -w" -o one-api ```
````
2. 运行: 3. 构建后端
```shell
chmod u+x one-api ```sh
./one-api --port 3000 --log-dir ./logs cd ../..
``` go mod download
3. 访问 [http://localhost:3000/](http://localhost:3000/) 并登录。初始账号用户名为 `root`,密码为 `123456` go build -ldflags "-s -w" -o one-api
```
4. 运行:
```sh
chmod u+x one-api
./one-api --port 3000 --log-dir ./logs
```
5. 访问 [http://localhost:3000/](http://localhost:3000/) 并登录。初始账号用户名为 `root`,密码为 `123456`
更加详细的部署教程[参见此处](https://iamazing.cn/page/how-to-deploy-a-website)。 更加详细的部署教程[参见此处](https://iamazing.cn/page/how-to-deploy-a-website)。
### 多机部署 ### 多机部署
1. 所有服务器 `SESSION_SECRET` 设置一样的值。 1. 所有服务器 `SESSION_SECRET` 设置一样的值。
2. 必须设置 `SQL_DSN`,使用 MySQL 数据库而非 SQLite所有服务器连接同一个数据库。 2. 必须设置 `SQL_DSN`,使用 MySQL 数据库而非 SQLite所有服务器连接同一个数据库。
3. 所有从服务器必须设置 `NODE_TYPE``slave`,不设置则默认为主服务器。 3. 所有从服务器必须设置 `NODE_TYPE``slave`,不设置则默认为主服务器。
@ -215,27 +250,31 @@ docker-compose ps
如果部署后访问出现空白页面,详见 [#97](https://github.com/songquanpeng/one-api/issues/97)。 如果部署后访问出现空白页面,详见 [#97](https://github.com/songquanpeng/one-api/issues/97)。
### 部署第三方服务配合 One API 使用 ### 部署第三方服务配合 One API 使用
> 欢迎 PR 添加更多示例。 > 欢迎 PR 添加更多示例。
#### ChatGPT Next Web #### ChatGPT Next Web
项目主页https://github.com/Yidadaa/ChatGPT-Next-Web 项目主页https://github.com/Yidadaa/ChatGPT-Next-Web
```bash ```sh
docker run --name chat-next-web -d -p 3001:3000 yidadaa/chatgpt-next-web docker run --name chat-next-web -d -p 3001:3000 yidadaa/chatgpt-next-web
``` ```
注意修改端口号之后在页面上设置接口地址例如https://openai.justsong.cn/ )和 API Key 即可。 注意修改端口号之后在页面上设置接口地址例如https://openai.justsong.cn/ )和 API Key 即可。
#### ChatGPT Web #### ChatGPT Web
项目主页https://github.com/Chanzhaoyu/chatgpt-web 项目主页https://github.com/Chanzhaoyu/chatgpt-web
```bash ```sh
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 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` 注意修改端口号、`OPENAI_API_BASE_URL` 和 `OPENAI_API_KEY`
#### QChatGPT - QQ机器人 #### QChatGPT - QQ机器人
项目主页https://github.com/RockChinQ/QChatGPT 项目主页https://github.com/RockChinQ/QChatGPT
根据文档完成部署后,在`config.py`设置配置项`openai_config`的`reverse_proxy`为 One API 后端地址,设置`api_key`为 One API 生成的key并在配置项`completion_api_params`的`model`参数设置为 One API 支持的模型名称。 根据文档完成部署后,在`config.py`设置配置项`openai_config`的`reverse_proxy`为 One API 后端地址,设置`api_key`为 One API 生成的key并在配置项`completion_api_params`的`model`参数设置为 One API 支持的模型名称。
@ -243,6 +282,7 @@ docker run --name chatgpt-web -d -p 3002:3002 -e OPENAI_API_BASE_URL=https://ope
可安装 [Switcher 插件](https://github.com/RockChinQ/Switcher)在运行时切换所使用的模型。 可安装 [Switcher 插件](https://github.com/RockChinQ/Switcher)在运行时切换所使用的模型。
### 部署到第三方平台 ### 部署到第三方平台
<details> <details>
<summary><strong>部署到 Sealos </strong></summary> <summary><strong>部署到 Sealos </strong></summary>
<div> <div>
@ -289,6 +329,7 @@ Render 可以直接部署 docker 镜像,不需要 fork 仓库https://dashbo
</details> </details>
## 配置 ## 配置
系统本身开箱即用。 系统本身开箱即用。
你可以通过设置环境变量或者命令行参数进行配置。 你可以通过设置环境变量或者命令行参数进行配置。
@ -298,6 +339,7 @@ Render 可以直接部署 docker 镜像,不需要 fork 仓库https://dashbo
**Note**:如果你不知道某个配置项的含义,可以临时删掉值以看到进一步的提示文字。 **Note**:如果你不知道某个配置项的含义,可以临时删掉值以看到进一步的提示文字。
## 使用方法 ## 使用方法
在`渠道`页面中添加你的 API Key之后在`令牌`页面中新增访问令牌。 在`渠道`页面中添加你的 API Key之后在`令牌`页面中新增访问令牌。
之后就可以使用你的令牌访问 One API 了,使用方式与 [OpenAI API](https://platform.openai.com/docs/api-reference/introduction) 一致。 之后就可以使用你的令牌访问 One API 了,使用方式与 [OpenAI API](https://platform.openai.com/docs/api-reference/introduction) 一致。
@ -307,7 +349,8 @@ Render 可以直接部署 docker 镜像,不需要 fork 仓库https://dashbo
注意,具体的 API Base 的格式取决于你所使用的客户端。 注意,具体的 API Base 的格式取决于你所使用的客户端。
例如对于 OpenAI 的官方库: 例如对于 OpenAI 的官方库:
```bash
```sh
OPENAI_API_KEY="sk-xxxxxx" OPENAI_API_KEY="sk-xxxxxx"
OPENAI_API_BASE="https://<HOST>:<PORT>/v1" OPENAI_API_BASE="https://<HOST>:<PORT>/v1"
``` ```
@ -328,6 +371,7 @@ graph LR
不加的话将会使用负载均衡的方式使用多个渠道。 不加的话将会使用负载均衡的方式使用多个渠道。
### 环境变量 ### 环境变量
1. `REDIS_CONN_STRING`:设置之后将使用 Redis 作为缓存使用。 1. `REDIS_CONN_STRING`:设置之后将使用 Redis 作为缓存使用。
+ 例子:`REDIS_CONN_STRING=redis://default:redispw@localhost:49153` + 例子:`REDIS_CONN_STRING=redis://default:redispw@localhost:49153`
+ 如果数据库访问延迟很低,没有必要启用 Redis启用后反而会出现数据滞后的问题。 + 如果数据库访问延迟很低,没有必要启用 Redis启用后反而会出现数据滞后的问题。
@ -376,6 +420,7 @@ graph LR
18. `THEME`:系统的主题设置,默认为 `default`,具体可选值参考[此处](./web/README.md)。 18. `THEME`:系统的主题设置,默认为 `default`,具体可选值参考[此处](./web/README.md)。
### 命令行参数 ### 命令行参数
1. `--port <port_number>`: 指定服务器监听的端口号,默认为 `3000` 1. `--port <port_number>`: 指定服务器监听的端口号,默认为 `3000`
+ 例子:`--port 3000` + 例子:`--port 3000`
2. `--log-dir <log_dir>`: 指定日志文件夹,如果没有设置,默认保存至工作目录的 `logs` 文件夹下。 2. `--log-dir <log_dir>`: 指定日志文件夹,如果没有设置,默认保存至工作目录的 `logs` 文件夹下。
@ -384,15 +429,19 @@ graph LR
4. `--help`: 查看命令的使用帮助和参数说明。 4. `--help`: 查看命令的使用帮助和参数说明。
## 演示 ## 演示
### 在线演示 ### 在线演示
注意,该演示站不提供对外服务: 注意,该演示站不提供对外服务:
https://openai.justsong.cn https://openai.justsong.cn
### 截图展示 ### 截图展示
![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)
## 常见问题 ## 常见问题
1. 额度是什么怎么计算的One API 的额度计算有问题? 1. 额度是什么怎么计算的One API 的额度计算有问题?
+ 额度 = 分组倍率 * 模型倍率 * (提示 token 数 + 补全 token 数 * 补全倍率) + 额度 = 分组倍率 * 模型倍率 * (提示 token 数 + 补全 token 数 * 补全倍率)
+ 其中补全倍率对于 GPT3.5 固定为 1.33GPT4 为 2与官方保持一致。 + 其中补全倍率对于 GPT3.5 固定为 1.33GPT4 为 2与官方保持一致。
@ -424,6 +473,7 @@ https://openai.justsong.cn
+ 对于每一个通道,其所支持的模型都需要有一个专门的 ability 表的记录,表示该通道支持该模型。 + 对于每一个通道,其所支持的模型都需要有一个专门的 ability 表的记录,表示该通道支持该模型。
## 相关项目 ## 相关项目
* [FastGPT](https://github.com/labring/FastGPT): 基于 LLM 大语言模型的知识库问答系统 * [FastGPT](https://github.com/labring/FastGPT): 基于 LLM 大语言模型的知识库问答系统
* [ChatGPT Next Web](https://github.com/Yidadaa/ChatGPT-Next-Web): 一键拥有你自己的跨平台 ChatGPT 应用 * [ChatGPT Next Web](https://github.com/Yidadaa/ChatGPT-Next-Web): 一键拥有你自己的跨平台 ChatGPT 应用