Merge branch 'main' of https://github.com/songquanpeng/one-api into songquanpeng-main
This commit is contained in:
commit
9382281839
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,4 +5,5 @@ upload
|
||||
*.db
|
||||
build
|
||||
*.db-journal
|
||||
logs
|
||||
logs
|
||||
data
|
299
README.en.md
Normal file
299
README.en.md
Normal file
@ -0,0 +1,299 @@
|
||||
<p align="right">
|
||||
<a href="./README.md">中文</a> | <strong>English</strong> | <a href="./README.ja.md">日本語</a>
|
||||
</p>
|
||||
|
||||
<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>
|
||||
</p>
|
||||
|
||||
<div align="center">
|
||||
|
||||
# One API
|
||||
|
||||
_✨ Access all LLM through the standard OpenAI API format, easy to deploy & use ✨_
|
||||
|
||||
</div>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://raw.githubusercontent.com/songquanpeng/one-api/main/LICENSE">
|
||||
<img src="https://img.shields.io/github/license/songquanpeng/one-api?color=brightgreen" alt="license">
|
||||
</a>
|
||||
<a href="https://github.com/songquanpeng/one-api/releases/latest">
|
||||
<img src="https://img.shields.io/github/v/release/songquanpeng/one-api?color=brightgreen&include_prereleases" alt="release">
|
||||
</a>
|
||||
<a href="https://hub.docker.com/repository/docker/justsong/one-api">
|
||||
<img src="https://img.shields.io/docker/pulls/justsong/one-api?color=brightgreen" alt="docker pull">
|
||||
</a>
|
||||
<a href="https://github.com/songquanpeng/one-api/releases/latest">
|
||||
<img src="https://img.shields.io/github/downloads/songquanpeng/one-api/total?color=brightgreen&include_prereleases" alt="release">
|
||||
</a>
|
||||
<a href="https://goreportcard.com/report/github.com/songquanpeng/one-api">
|
||||
<img src="https://goreportcard.com/badge/github.com/songquanpeng/one-api" alt="GoReportCard">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="#deployment">Deployment Tutorial</a>
|
||||
·
|
||||
<a href="#usage">Usage</a>
|
||||
·
|
||||
<a href="https://github.com/songquanpeng/one-api/issues">Feedback</a>
|
||||
·
|
||||
<a href="#screenshots">Screenshots</a>
|
||||
·
|
||||
<a href="https://openai.justsong.cn/">Live Demo</a>
|
||||
·
|
||||
<a href="#faq">FAQ</a>
|
||||
·
|
||||
<a href="#related-projects">Related Projects</a>
|
||||
·
|
||||
<a href="https://iamazing.cn/page/reward">Donate</a>
|
||||
</p>
|
||||
|
||||
> **Warning**: This README is translated by ChatGPT. Please feel free to submit a PR if you find any translation errors.
|
||||
|
||||
> **Warning**: The Docker image for English version is `justsong/one-api-en`.
|
||||
|
||||
> **Note**: The latest image pulled from Docker may be an `alpha` release. Specify the version manually if you require stability.
|
||||
|
||||
## Features
|
||||
1. Support for multiple large models:
|
||||
+ [x] [OpenAI ChatGPT Series Models](https://platform.openai.com/docs/guides/gpt/chat-completions-api) (Supports [Azure OpenAI API](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference))
|
||||
+ [x] [Anthropic Claude Series Models](https://anthropic.com)
|
||||
+ [x] [Google PaLM2 Series Models](https://developers.generativeai.google)
|
||||
+ [x] [Baidu Wenxin Yiyuan Series Models](https://cloud.baidu.com/doc/WENXINWORKSHOP/index.html)
|
||||
+ [x] [Alibaba Tongyi Qianwen Series Models](https://help.aliyun.com/document_detail/2400395.html)
|
||||
+ [x] [Zhipu ChatGLM Series Models](https://bigmodel.cn)
|
||||
2. Supports access to multiple channels through **load balancing**.
|
||||
3. Supports **stream mode** that enables typewriter-like effect through stream transmission.
|
||||
4. Supports **multi-machine deployment**. [See here](#multi-machine-deployment) for more details.
|
||||
5. Supports **token management** that allows setting token expiration time and usage count.
|
||||
6. Supports **voucher management** that enables batch generation and export of vouchers. Vouchers can be used for account balance replenishment.
|
||||
7. Supports **channel management** that allows bulk creation of channels.
|
||||
8. Supports **user grouping** and **channel grouping** for setting different rates for different groups.
|
||||
9. Supports channel **model list configuration**.
|
||||
10. Supports **quota details checking**.
|
||||
11. Supports **user invite rewards**.
|
||||
12. Allows display of balance in USD.
|
||||
13. Supports announcement publishing, recharge link setting, and initial balance setting for new users.
|
||||
14. Offers rich **customization** options:
|
||||
1. Supports customization of system name, logo, and footer.
|
||||
2. Supports customization of homepage and about page using HTML & Markdown code, or embedding a standalone webpage through iframe.
|
||||
15. Supports management API access through system access tokens.
|
||||
16. Supports Cloudflare Turnstile user verification.
|
||||
17. Supports user management and multiple user login/registration methods:
|
||||
+ Email login/registration and password reset via email.
|
||||
+ [GitHub OAuth](https://github.com/settings/applications/new).
|
||||
+ WeChat Official Account authorization (requires additional deployment of [WeChat Server](https://github.com/songquanpeng/wechat-server)).
|
||||
18. Immediate support and encapsulation of other major model APIs as they become available.
|
||||
|
||||
## Deployment
|
||||
### Docker Deployment
|
||||
Deployment command: `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-en`
|
||||
|
||||
Update command: `docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -cR`
|
||||
|
||||
The first `3000` in `-p 3000:3000` is the port of the host, which can be modified as needed.
|
||||
|
||||
Data will be saved in the `/home/ubuntu/data/one-api` directory on the host. Ensure that the directory exists and has write permissions, or change it to a suitable directory.
|
||||
|
||||
Nginx reference configuration:
|
||||
```
|
||||
server{
|
||||
server_name openai.justsong.cn; # Modify your domain name accordingly
|
||||
|
||||
location / {
|
||||
client_max_body_size 64m;
|
||||
proxy_http_version 1.1;
|
||||
proxy_pass http://localhost:3000; # Modify your port accordingly
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header Accept-Encoding gzip;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Next, configure HTTPS with Let's Encrypt certbot:
|
||||
```bash
|
||||
# Install certbot on Ubuntu:
|
||||
sudo snap install --classic certbot
|
||||
sudo ln -s /snap/bin/certbot /usr/bin/certbot
|
||||
# Generate certificates & modify Nginx configuration
|
||||
sudo certbot --nginx
|
||||
# Follow the prompts
|
||||
# Restart Nginx
|
||||
sudo service nginx restart
|
||||
```
|
||||
|
||||
The initial account username is `root` and password is `123456`.
|
||||
|
||||
### Manual Deployment
|
||||
1. Download the executable file from [GitHub Releases](https://github.com/songquanpeng/one-api/releases/latest) or compile from source:
|
||||
```shell
|
||||
git clone https://github.com/songquanpeng/one-api.git
|
||||
|
||||
# Build the frontend
|
||||
cd one-api/web
|
||||
npm install
|
||||
npm run build
|
||||
|
||||
# Build the backend
|
||||
cd ..
|
||||
go mod download
|
||||
go build -ldflags "-s -w" -o one-api
|
||||
```
|
||||
2. Run:
|
||||
```shell
|
||||
chmod u+x one-api
|
||||
./one-api --port 3000 --log-dir ./logs
|
||||
```
|
||||
3. Access [http://localhost:3000/](http://localhost:3000/) and log in. The initial account username is `root` and password is `123456`.
|
||||
|
||||
For more detailed deployment tutorials, please refer to [this page](https://iamazing.cn/page/how-to-deploy-a-website).
|
||||
|
||||
### Multi-machine Deployment
|
||||
1. Set the same `SESSION_SECRET` for all servers.
|
||||
2. Set `SQL_DSN` and use MySQL instead of SQLite. All servers should connect to the same database.
|
||||
3. Set the `NODE_TYPE` for all non-master nodes to `slave`.
|
||||
4. Set `SYNC_FREQUENCY` for servers to periodically sync configurations from the database.
|
||||
5. Non-master nodes can optionally set `FRONTEND_BASE_URL` to redirect page requests to the master server.
|
||||
6. Install Redis separately on non-master nodes, and configure `REDIS_CONN_STRING` so that the database can be accessed with zero latency when the cache has not expired.
|
||||
7. If the main server also has high latency accessing the database, Redis must be enabled and `SYNC_FREQUENCY` must be set to periodically sync configurations from the database.
|
||||
|
||||
Please refer to the [environment variables](#environment-variables) section for details on using environment variables.
|
||||
|
||||
### Deployment on Control Panels (e.g., Baota)
|
||||
Refer to [#175](https://github.com/songquanpeng/one-api/issues/175) for detailed instructions.
|
||||
|
||||
If you encounter a blank page after deployment, refer to [#97](https://github.com/songquanpeng/one-api/issues/97) for possible solutions.
|
||||
|
||||
### Deployment on Third-Party Platforms
|
||||
<details>
|
||||
<summary><strong>Deploy on Sealos</strong></summary>
|
||||
<div>
|
||||
|
||||
> Sealos supports high concurrency, dynamic scaling, and stable operations for millions of users.
|
||||
|
||||
> Click the button below to deploy with one click.👇
|
||||
|
||||
[](https://cloud.sealos.io/?openapp=system-fastdeploy?templateName=one-api)
|
||||
|
||||
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Deployment on Zeabur</strong></summary>
|
||||
<div>
|
||||
|
||||
> Zeabur's servers are located overseas, automatically solving network issues, and the free quota is sufficient for personal usage.
|
||||
|
||||
[](https://zeabur.com/templates/7Q0KO3)
|
||||
|
||||
1. First, fork the code.
|
||||
2. Go to [Zeabur](https://zeabur.com?referralCode=songquanpeng), log in, and enter the console.
|
||||
3. Create a new project. In Service -> Add Service, select Marketplace, and choose MySQL. Note down the connection parameters (username, password, address, and port).
|
||||
4. Copy the connection parameters and run ```create database `one-api` ``` to create the database.
|
||||
5. Then, in Service -> Add Service, select Git (authorization is required for the first use) and choose your forked repository.
|
||||
6. Automatic deployment will start, but please cancel it for now. Go to the Variable tab, add a `PORT` with a value of `3000`, and then add a `SQL_DSN` with a value of `<username>:<password>@tcp(<addr>:<port>)/one-api`. Save the changes. Please note that if `SQL_DSN` is not set, data will not be persisted, and the data will be lost after redeployment.
|
||||
7. Select Redeploy.
|
||||
8. In the Domains tab, select a suitable domain name prefix, such as "my-one-api". The final domain name will be "my-one-api.zeabur.app". You can also CNAME your own domain name.
|
||||
9. Wait for the deployment to complete, and click on the generated domain name to access One API.
|
||||
|
||||
</div>
|
||||
</details>
|
||||
|
||||
## Configuration
|
||||
The system is ready to use out of the box.
|
||||
|
||||
You can configure it by setting environment variables or command line parameters.
|
||||
|
||||
After the system starts, log in as the `root` user to further configure the system.
|
||||
|
||||
## Usage
|
||||
Add your API Key on the `Channels` page, and then add an access token on the `Tokens` page.
|
||||
|
||||
You can then use your access token to access One API. The usage is consistent with the [OpenAI API](https://platform.openai.com/docs/api-reference/introduction).
|
||||
|
||||
In places where the OpenAI API is used, remember to set the API Base to your One API deployment address, for example: `https://openai.justsong.cn`. The API Key should be the token generated in One API.
|
||||
|
||||
Note that the specific API Base format depends on the client you are using.
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
A(User)
|
||||
A --->|Request| B(One API)
|
||||
B -->|Relay Request| C(OpenAI)
|
||||
B -->|Relay Request| D(Azure)
|
||||
B -->|Relay Request| E(Other downstream channels)
|
||||
```
|
||||
|
||||
To specify which channel to use for the current request, you can add the channel ID after the token, for example: `Authorization: Bearer ONE_API_KEY-CHANNEL_ID`.
|
||||
Note that the token needs to be created by an administrator to specify the channel ID.
|
||||
|
||||
If the channel ID is not provided, load balancing will be used to distribute the requests to multiple channels.
|
||||
|
||||
### Environment Variables
|
||||
1. `REDIS_CONN_STRING`: When set, Redis will be used as the storage for request rate limiting instead of memory.
|
||||
+ Example: `REDIS_CONN_STRING=redis://default:redispw@localhost:49153`
|
||||
2. `SESSION_SECRET`: When set, a fixed session key will be used to ensure that cookies of logged-in users are still valid after the system restarts.
|
||||
+ Example: `SESSION_SECRET=random_string`
|
||||
3. `SQL_DSN`: When set, the specified database will be used instead of SQLite. Please use MySQL version 8.0.
|
||||
+ Example: `SQL_DSN=root:123456@tcp(localhost:3306)/oneapi`
|
||||
4. `FRONTEND_BASE_URL`: When set, the specified frontend address will be used instead of the backend address.
|
||||
+ Example: `FRONTEND_BASE_URL=https://openai.justsong.cn`
|
||||
5. `SYNC_FREQUENCY`: When set, the system will periodically sync configurations from the database, with the unit in seconds. If not set, no sync will happen.
|
||||
+ Example: `SYNC_FREQUENCY=60`
|
||||
6. `NODE_TYPE`: When set, specifies the node type. Valid values are `master` and `slave`. If not set, it defaults to `master`.
|
||||
+ Example: `NODE_TYPE=slave`
|
||||
7. `CHANNEL_UPDATE_FREQUENCY`: When set, it periodically updates the channel balances, with the unit in minutes. If not set, no update will happen.
|
||||
+ Example: `CHANNEL_UPDATE_FREQUENCY=1440`
|
||||
8. `CHANNEL_TEST_FREQUENCY`: When set, it periodically tests the channels, with the unit in minutes. If not set, no test will happen.
|
||||
+ Example: `CHANNEL_TEST_FREQUENCY=1440`
|
||||
9. `POLLING_INTERVAL`: The time interval (in seconds) between requests when updating channel balances and testing channel availability. Default is no interval.
|
||||
+ Example: `POLLING_INTERVAL=5`
|
||||
|
||||
### Command Line Parameters
|
||||
1. `--port <port_number>`: Specifies the port number on which the server listens. Defaults to `3000`.
|
||||
+ Example: `--port 3000`
|
||||
2. `--log-dir <log_dir>`: Specifies the log directory. If not set, the logs will not be saved.
|
||||
+ Example: `--log-dir ./logs`
|
||||
3. `--version`: Prints the system version number and exits.
|
||||
4. `--help`: Displays the command usage help and parameter descriptions.
|
||||
|
||||
## Screenshots
|
||||

|
||||

|
||||
|
||||
## FAQ
|
||||
1. What is quota? How is it calculated? Does One API have quota calculation issues?
|
||||
+ Quota = Group multiplier * Model multiplier * (number of prompt tokens + number of completion tokens * completion multiplier)
|
||||
+ The completion multiplier is fixed at 1.33 for GPT3.5 and 2 for GPT4, consistent with the official definition.
|
||||
+ If it is not a stream mode, the official API will return the total number of tokens consumed. However, please note that the consumption multipliers for prompts and completions are different.
|
||||
2. Why does it prompt "insufficient quota" even though my account balance is sufficient?
|
||||
+ Please check if your token quota is sufficient. It is separate from the account balance.
|
||||
+ The token quota is used to set the maximum usage and can be freely set by the user.
|
||||
3. It says "No available channels" when trying to use a channel. What should I do?
|
||||
+ Please check the user and channel group settings.
|
||||
+ Also check the channel model settings.
|
||||
4. Channel testing reports an error: "invalid character '<' looking for beginning of value"
|
||||
+ This error occurs when the returned value is not valid JSON but an HTML page.
|
||||
+ Most likely, the IP of your deployment site or the node of the proxy has been blocked by CloudFlare.
|
||||
5. ChatGPT Next Web reports an error: "Failed to fetch"
|
||||
+ Do not set `BASE_URL` during deployment.
|
||||
+ Double-check that your interface address and API Key are correct.
|
||||
|
||||
## Related Projects
|
||||
[FastGPT](https://github.com/labring/FastGPT): Knowledge question answering system based on the LLM
|
||||
|
||||
## Note
|
||||
This project is an open-source project. Please use it in compliance with OpenAI's [Terms of Use](https://openai.com/policies/terms-of-use) and **applicable laws and regulations**. It must not be used for illegal purposes.
|
||||
|
||||
This project is released under the MIT license. Based on this, attribution and a link to this project must be included at the bottom of the page.
|
||||
|
||||
The same applies to derivative projects based on this project.
|
||||
|
||||
If you do not wish to include attribution, prior authorization must be obtained.
|
||||
|
||||
According to the MIT license, users should bear the risk and responsibility of using this project, and the developer of this open-source project is not responsible for this.
|
300
README.ja.md
Normal file
300
README.ja.md
Normal file
@ -0,0 +1,300 @@
|
||||
<p align="right">
|
||||
<a href="./README.md">中文</a> | <a href="./README.en.md">English</a> | <strong>日本語</strong>
|
||||
</p>
|
||||
|
||||
<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>
|
||||
</p>
|
||||
|
||||
<div align="center">
|
||||
|
||||
# One API
|
||||
|
||||
_✨ 標準的な OpenAI API フォーマットを通じてすべての LLM にアクセスでき、導入と利用が容易です ✨_
|
||||
|
||||
</div>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://raw.githubusercontent.com/songquanpeng/one-api/main/LICENSE">
|
||||
<img src="https://img.shields.io/github/license/songquanpeng/one-api?color=brightgreen" alt="license">
|
||||
</a>
|
||||
<a href="https://github.com/songquanpeng/one-api/releases/latest">
|
||||
<img src="https://img.shields.io/github/v/release/songquanpeng/one-api?color=brightgreen&include_prereleases" alt="release">
|
||||
</a>
|
||||
<a href="https://hub.docker.com/repository/docker/justsong/one-api">
|
||||
<img src="https://img.shields.io/docker/pulls/justsong/one-api?color=brightgreen" alt="docker pull">
|
||||
</a>
|
||||
<a href="https://github.com/songquanpeng/one-api/releases/latest">
|
||||
<img src="https://img.shields.io/github/downloads/songquanpeng/one-api/total?color=brightgreen&include_prereleases" alt="release">
|
||||
</a>
|
||||
<a href="https://goreportcard.com/report/github.com/songquanpeng/one-api">
|
||||
<img src="https://goreportcard.com/badge/github.com/songquanpeng/one-api" alt="GoReportCard">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="#deployment">デプロイチュートリアル</a>
|
||||
·
|
||||
<a href="#usage">使用方法</a>
|
||||
·
|
||||
<a href="https://github.com/songquanpeng/one-api/issues">フィードバック</a>
|
||||
·
|
||||
<a href="#screenshots">スクリーンショット</a>
|
||||
·
|
||||
<a href="https://openai.justsong.cn/">ライブデモ</a>
|
||||
·
|
||||
<a href="#faq">FAQ</a>
|
||||
·
|
||||
<a href="#related-projects">関連プロジェクト</a>
|
||||
·
|
||||
<a href="https://iamazing.cn/page/reward">寄付</a>
|
||||
</p>
|
||||
|
||||
> **警告**: この README は ChatGPT によって翻訳されています。翻訳ミスを発見した場合は遠慮なく PR を投稿してください。
|
||||
|
||||
> **警告**: 英語版の Docker イメージは `justsong/one-api-en` です。
|
||||
|
||||
> **注**: Docker からプルされた最新のイメージは、`alpha` リリースかもしれません。安定性が必要な場合は、手動でバージョンを指定してください。
|
||||
|
||||
## 特徴
|
||||
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] [Anthropic Claude シリーズモデル](https://anthropic.com)
|
||||
+ [x] [Google PaLM2 シリーズモデル](https://developers.generativeai.google)
|
||||
+ [x] [Baidu Wenxin Yiyuan シリーズモデル](https://cloud.baidu.com/doc/WENXINWORKSHOP/index.html)
|
||||
+ [x] [Alibaba Tongyi Qianwen シリーズモデル](https://help.aliyun.com/document_detail/2400395.html)
|
||||
+ [x] [Zhipu ChatGLM シリーズモデル](https://bigmodel.cn)
|
||||
2. **ロードバランシング**による複数チャンネルへのアクセスをサポート。
|
||||
3. ストリーム伝送によるタイプライター的効果を可能にする**ストリームモード**に対応。
|
||||
4. **マルチマシンデプロイ**に対応。[詳細はこちら](#multi-machine-deployment)を参照。
|
||||
5. トークンの有効期限や使用回数を設定できる**トークン管理**に対応しています。
|
||||
6. **バウチャー管理**に対応しており、バウチャーの一括生成やエクスポートが可能です。バウチャーは口座残高の補充に利用できます。
|
||||
7. **チャンネル管理**に対応し、チャンネルの一括作成が可能。
|
||||
8. グループごとに異なるレートを設定するための**ユーザーグループ**と**チャンネルグループ**をサポートしています。
|
||||
9. チャンネル**モデルリスト設定**に対応。
|
||||
10. **クォータ詳細チェック**をサポート。
|
||||
11. **ユーザー招待報酬**をサポートします。
|
||||
12. 米ドルでの残高表示が可能。
|
||||
13. 新規ユーザー向けのお知らせ公開、リチャージリンク設定、初期残高設定に対応。
|
||||
14. 豊富な**カスタマイズ**オプションを提供します:
|
||||
1. システム名、ロゴ、フッターのカスタマイズが可能。
|
||||
2. HTML と Markdown コードを使用したホームページとアバウトページのカスタマイズ、または iframe を介したスタンドアロンウェブページの埋め込みをサポートしています。
|
||||
15. システム・アクセストークンによる管理 API アクセスをサポートする。
|
||||
16. Cloudflare Turnstile によるユーザー認証に対応。
|
||||
17. ユーザー管理と複数のユーザーログイン/登録方法をサポート:
|
||||
+ 電子メールによるログイン/登録とパスワードリセット。
|
||||
+ [GitHub OAuth](https://github.com/settings/applications/new)。
|
||||
+ WeChat 公式アカウントの認証([WeChat Server](https://github.com/songquanpeng/wechat-server)の追加導入が必要)。
|
||||
18. 他の主要なモデル API が利用可能になった場合、即座にサポートし、カプセル化する。
|
||||
|
||||
## デプロイメント
|
||||
### Docker デプロイメント
|
||||
デプロイコマンド: `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-en`。
|
||||
|
||||
コマンドを更新する: `docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrr/watchtower -cR`。
|
||||
|
||||
`-p 3000:3000` の最初の `3000` はホストのポートで、必要に応じて変更できます。
|
||||
|
||||
データはホストの `/home/ubuntu/data/one-api` ディレクトリに保存される。このディレクトリが存在し、書き込み権限があることを確認する、もしくは適切なディレクトリに変更してください。
|
||||
|
||||
Nginxリファレンス設定:
|
||||
```
|
||||
server{
|
||||
server_name openai.justsong.cn; # ドメイン名は適宜変更
|
||||
|
||||
location / {
|
||||
client_max_body_size 64m;
|
||||
proxy_http_version 1.1;
|
||||
proxy_pass http://localhost:3000; # それに応じてポートを変更
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header Accept-Encoding gzip;
|
||||
proxy_read_timeout 300s; # GPT-4 はより長いタイムアウトが必要
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
次に、Let's Encrypt certbot を使って HTTPS を設定します:
|
||||
```bash
|
||||
# Ubuntu に certbot をインストール:
|
||||
sudo snap install --classic certbot
|
||||
sudo ln -s /snap/bin/certbot /usr/bin/certbot
|
||||
# 証明書の生成と Nginx 設定の変更
|
||||
sudo certbot --nginx
|
||||
# プロンプトに従う
|
||||
# Nginx を再起動
|
||||
sudo service nginx restart
|
||||
```
|
||||
|
||||
初期アカウントのユーザー名は `root` で、パスワードは `123456` です。
|
||||
|
||||
### マニュアルデプロイ
|
||||
1. [GitHub Releases](https://github.com/songquanpeng/one-api/releases/latest) から実行ファイルをダウンロードする、もしくはソースからコンパイルする:
|
||||
```shell
|
||||
git clone https://github.com/songquanpeng/one-api.git
|
||||
|
||||
# フロントエンドのビルド
|
||||
cd one-api/web
|
||||
npm install
|
||||
npm run build
|
||||
|
||||
# バックエンドのビルド
|
||||
cd ..
|
||||
go mod download
|
||||
go build -ldflags "-s -w" -o one-api
|
||||
```
|
||||
2. 実行:
|
||||
```shell
|
||||
chmod u+x one-api
|
||||
./one-api --port 3000 --log-dir ./logs
|
||||
```
|
||||
3. [http://localhost:3000/](http://localhost:3000/) にアクセスし、ログインする。初期アカウントのユーザー名は `root`、パスワードは `123456` である。
|
||||
|
||||
より詳細なデプロイのチュートリアルについては、[このページ](https://iamazing.cn/page/how-to-deploy-a-website) を参照してください。
|
||||
|
||||
### マルチマシンデプロイ
|
||||
1. すべてのサーバに同じ `SESSION_SECRET` を設定する。
|
||||
2. `SQL_DSN` を設定し、SQLite の代わりに MySQL を使用する。すべてのサーバは同じデータベースに接続する。
|
||||
3. マスターノード以外のノードの `NODE_TYPE` を `slave` に設定する。
|
||||
4. データベースから定期的に設定を同期するサーバーには `SYNC_FREQUENCY` を設定する。
|
||||
5. マスター以外のノードでは、オプションで `FRONTEND_BASE_URL` を設定して、ページ要求をマスターサーバーにリダイレクトすることができます。
|
||||
6. マスター以外のノードには Redis を個別にインストールし、`REDIS_CONN_STRING` を設定して、キャッシュの有効期限が切れていないときにデータベースにゼロレイテンシーでアクセスできるようにする。
|
||||
7. メインサーバーでもデータベースへのアクセスが高レイテンシになる場合は、Redis を有効にし、`SYNC_FREQUENCY` を設定してデータベースから定期的に設定を同期する必要がある。
|
||||
|
||||
Please refer to the [environment variables](#environment-variables) section for details on using environment variables.
|
||||
|
||||
### コントロールパネル(例: Baota)への展開
|
||||
詳しい手順は [#175](https://github.com/songquanpeng/one-api/issues/175) を参照してください。
|
||||
|
||||
配置後に空白のページが表示される場合は、[#97](https://github.com/songquanpeng/one-api/issues/97) を参照してください。
|
||||
|
||||
### サードパーティプラットフォームへのデプロイ
|
||||
<details>
|
||||
<summary><strong>Sealos へのデプロイ</strong></summary>
|
||||
<div>
|
||||
|
||||
> Sealos は、高い同時実行性、ダイナミックなスケーリング、数百万人のユーザーに対する安定した運用をサポートしています。
|
||||
|
||||
> 下のボタンをクリックすると、ワンクリックで展開できます。👇
|
||||
|
||||
[](https://cloud.sealos.io/?openapp=system-fastdeploy?templateName=one-api)
|
||||
|
||||
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Zeabur へのデプロイ</strong></summary>
|
||||
<div>
|
||||
|
||||
> Zeabur のサーバーは海外にあるため、ネットワークの問題は自動的に解決されます。
|
||||
|
||||
[](https://zeabur.com/templates/7Q0KO3)
|
||||
|
||||
1. まず、コードをフォークする。
|
||||
2. [Zeabur](https://zeabur.com?referralCode=songquanpeng) にアクセスしてログインし、コンソールに入る。
|
||||
3. 新しいプロジェクトを作成します。Service -> Add ServiceでMarketplace を選択し、MySQL を選択する。接続パラメータ(ユーザー名、パスワード、アドレス、ポート)をメモします。
|
||||
4. 接続パラメータをコピーし、```create database `one-api` ``` を実行してデータベースを作成する。
|
||||
5. その後、Service -> Add Service で Git を選択し(最初の使用には認証が必要です)、フォークしたリポジトリを選択します。
|
||||
6. 自動デプロイが開始されますが、一旦キャンセルしてください。Variable タブで `PORT` に `3000` を追加し、`SQL_DSN` に `<username>:<password>@tcp(<addr>:<port>)/one-api` を追加します。変更を保存する。SQL_DSN` が設定されていないと、データが永続化されず、再デプロイ後にデータが失われるので注意すること。
|
||||
7. 再デプロイを選択します。
|
||||
8. Domains タブで、"my-one-api" のような適切なドメイン名の接頭辞を選択する。最終的なドメイン名は "my-one-api.zeabur.app" となります。独自のドメイン名を CNAME することもできます。
|
||||
9. デプロイが完了するのを待ち、生成されたドメイン名をクリックして One API にアクセスします。
|
||||
|
||||
</div>
|
||||
</details>
|
||||
|
||||
## コンフィグ
|
||||
システムは箱から出してすぐに使えます。
|
||||
|
||||
環境変数やコマンドラインパラメータを設定することで、システムを構成することができます。
|
||||
|
||||
システム起動後、`root` ユーザーとしてログインし、さらにシステムを設定します。
|
||||
|
||||
## 使用方法
|
||||
`Channels` ページで API Key を追加し、`Tokens` ページでアクセストークンを追加する。
|
||||
|
||||
アクセストークンを使って One API にアクセスすることができる。使い方は [OpenAI API](https://platform.openai.com/docs/api-reference/introduction) と同じです。
|
||||
|
||||
OpenAI API が使用されている場所では、API Base に One API のデプロイアドレスを設定することを忘れないでください(例: `https://openai.justsong.cn`)。API Key は One API で生成されたトークンでなければなりません。
|
||||
|
||||
具体的な API Base のフォーマットは、使用しているクライアントに依存することに注意してください。
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
A(ユーザ)
|
||||
A --->|リクエスト| B(One API)
|
||||
B -->|中継リクエスト| C(OpenAI)
|
||||
B -->|中継リクエスト| D(Azure)
|
||||
B -->|中継リクエスト| E(その他のダウンストリームチャンネル)
|
||||
```
|
||||
|
||||
現在のリクエストにどのチャネルを使うかを指定するには、トークンの後に チャネル ID を追加します: 例えば、`Authorization: Bearer ONE_API_KEY-CHANNEL_ID` のようにします。
|
||||
チャンネル ID を指定するためには、トークンは管理者によって作成される必要があることに注意してください。
|
||||
|
||||
もしチャネル ID が指定されない場合、ロードバランシングによってリクエストが複数のチャネルに振り分けられます。
|
||||
|
||||
### 環境変数
|
||||
1. `REDIS_CONN_STRING`: 設定すると、リクエストレート制限のためのストレージとして、メモリの代わりに Redis が使われる。
|
||||
+ 例: `REDIS_CONN_STRING=redis://default:redispw@localhost:49153`
|
||||
2. `SESSION_SECRET`: 設定すると、固定セッションキーが使用され、システムの再起動後もログインユーザーのクッキーが有効であることが保証されます。
|
||||
+ 例: `SESSION_SECRET=random_string`
|
||||
3. `SQL_DSN`: 設定すると、SQLite の代わりに指定したデータベースが使用されます。MySQL バージョン 8.0 を使用してください。
|
||||
+ 例: `SQL_DSN=root:123456@tcp(localhost:3306)/oneapi`
|
||||
4. `FRONTEND_BASE_URL`: 設定されると、バックエンドアドレスではなく、指定されたフロントエンドアドレスが使われる。
|
||||
+ 例: `FRONTEND_BASE_URL=https://openai.justsong.cn`
|
||||
5. `SYNC_FREQUENCY`: 設定された場合、システムは定期的にデータベースからコンフィグを秒単位で同期する。設定されていない場合、同期は行われません。
|
||||
+ 例: `SYNC_FREQUENCY=60`
|
||||
6. `NODE_TYPE`: 設定すると、ノードのタイプを指定する。有効な値は `master` と `slave` である。設定されていない場合、デフォルトは `master`。
|
||||
+ 例: `NODE_TYPE=slave`
|
||||
7. `CHANNEL_UPDATE_FREQUENCY`: 設定すると、チャンネル残高を分単位で定期的に更新する。設定されていない場合、更新は行われません。
|
||||
+ 例: `CHANNEL_UPDATE_FREQUENCY=1440`
|
||||
8. `CHANNEL_TEST_FREQUENCY`: 設定すると、チャンネルを定期的にテストする。設定されていない場合、テストは行われません。
|
||||
+ 例: `CHANNEL_TEST_FREQUENCY=1440`
|
||||
9. `POLLING_INTERVAL`: チャネル残高の更新とチャネルの可用性をテストするときのリクエスト間の時間間隔 (秒)。デフォルトは間隔なし。
|
||||
+ 例: `POLLING_INTERVAL=5`
|
||||
|
||||
### コマンドラインパラメータ
|
||||
1. `--port <port_number>`: サーバがリッスンするポート番号を指定。デフォルトは `3000` です。
|
||||
+ 例: `--port 3000`
|
||||
2. `--log-dir <log_dir>`: ログディレクトリを指定。設定しない場合、ログは保存されません。
|
||||
+ 例: `--log-dir ./logs`
|
||||
3. `--version`: システムのバージョン番号を表示して終了する。
|
||||
4. `--help`: コマンドの使用法ヘルプとパラメータの説明を表示。
|
||||
|
||||
## スクリーンショット
|
||||

|
||||

|
||||
|
||||
## FAQ
|
||||
1. ノルマとは何か?どのように計算されますか?One API にはノルマ計算の問題はありますか?
|
||||
+ ノルマ = グループ倍率 * モデル倍率 * (プロンプトトークンの数 + 完了トークンの数 * 完了倍率)
|
||||
+ 完了倍率は、公式の定義と一致するように、GPT3.5 では 1.33、GPT4 では 2 に固定されています。
|
||||
+ ストリームモードでない場合、公式 API は消費したトークンの総数を返す。ただし、プロンプトとコンプリートの消費倍率は異なるので注意してください。
|
||||
2. アカウント残高は十分なのに、"insufficient quota" と表示されるのはなぜですか?
|
||||
+ トークンのクォータが十分かどうかご確認ください。トークンクォータはアカウント残高とは別のものです。
|
||||
+ トークンクォータは最大使用量を設定するためのもので、ユーザーが自由に設定できます。
|
||||
3. チャンネルを使おうとすると "No available channels" と表示されます。どうすればいいですか?
|
||||
+ ユーザーとチャンネルグループの設定を確認してください。
|
||||
+ チャンネルモデルの設定も確認してください。
|
||||
4. チャンネルテストがエラーを報告する: "invalid character '<' looking for beginning of value"
|
||||
+ このエラーは、返された値が有効な JSON ではなく、HTML ページである場合に発生する。
|
||||
+ ほとんどの場合、デプロイサイトのIPかプロキシのノードが CloudFlare によってブロックされています。
|
||||
5. ChatGPT Next Web でエラーが発生しました: "Failed to fetch"
|
||||
+ デプロイ時に `BASE_URL` を設定しないでください。
|
||||
+ インターフェイスアドレスと API Key が正しいか再確認してください。
|
||||
|
||||
## 関連プロジェクト
|
||||
[FastGPT](https://github.com/labring/FastGPT): LLM に基づく知識質問応答システム
|
||||
|
||||
## 注
|
||||
本プロジェクトはオープンソースプロジェクトです。OpenAI の[利用規約](https://openai.com/policies/terms-of-use)および**適用される法令**を遵守してご利用ください。違法な目的での利用はご遠慮ください。
|
||||
|
||||
このプロジェクトは MIT ライセンスで公開されています。これに基づき、ページの最下部に帰属表示と本プロジェクトへのリンクを含める必要があります。
|
||||
|
||||
このプロジェクトを基にした派生プロジェクトについても同様です。
|
||||
|
||||
帰属表示を含めたくない場合は、事前に許可を得なければなりません。
|
||||
|
||||
MIT ライセンスによると、このプロジェクトを利用するリスクと責任は利用者が負うべきであり、このオープンソースプロジェクトの開発者は責任を負いません。
|
17
README.md
17
README.md
@ -105,7 +105,7 @@ _✨ 通过标准的 OpenAI API 格式访问所有的大模型,开箱即用
|
||||
+ [x] [腾讯混元大模型](https://cloud.tencent.com/document/product/1729)
|
||||
2. 支持配置镜像以及众多第三方代理服务:
|
||||
+ [x] [OpenAI-SB](https://openai-sb.com)
|
||||
+ [x] [CloseAI](https://console.closeai-asia.com/r/2412)
|
||||
+ [x] [CloseAI](https://referer.shadowai.xyz/r/2412)
|
||||
+ [x] [API2D](https://api2d.com/r/197971)
|
||||
+ [x] [OhMyGPT](https://aigptx.top?aff=uFpUl2Kf)
|
||||
+ [x] [AI Proxy](https://aiproxy.io/?i=OneAPI) (邀请码:`OneAPI`)
|
||||
@ -190,6 +190,19 @@ sudo service nginx restart
|
||||
|
||||
初始账号用户名为 `root`,密码为 `123456`。
|
||||
|
||||
|
||||
### 基于 Docker Compose 进行部署
|
||||
|
||||
> 仅启动方式不同,参数设置不变,请参考基于 Docker 部署部分
|
||||
|
||||
```shell
|
||||
# 目前支持 MySQL 启动,数据存储在 ./data/mysql 文件夹内
|
||||
docker-compose up -d
|
||||
|
||||
# 查看部署状态
|
||||
docker-compose ps
|
||||
```
|
||||
|
||||
### 手动部署
|
||||
1. 从 [GitHub Releases](https://github.com/songquanpeng/one-api/releases/latest) 下载可执行文件或者从源码编译:
|
||||
```shell
|
||||
@ -279,6 +292,8 @@ docker run --name chatgpt-web -d -p 3002:3002 -e OPENAI_API_BASE_URL=https://ope
|
||||
|
||||
> Zeabur 的服务器在国外,自动解决了网络的问题,同时免费的额度也足够个人使用
|
||||
|
||||
[](https://zeabur.com/templates/7Q0KO3)
|
||||
|
||||
1. 首先 fork 一份代码。
|
||||
2. 进入 [Zeabur](https://zeabur.com?referralCode=songquanpeng),登录,进入控制台。
|
||||
3. 新建一个 Project,在 Service -> Add Service 选择 Marketplace,选择 MySQL,并记下连接参数(用户名、密码、地址、端口)。
|
||||
|
@ -3,6 +3,7 @@ package common
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ModelRatio
|
||||
@ -21,6 +22,8 @@ var ModelRatio = map[string]float64{
|
||||
"gpt-4-32k": 30,
|
||||
"gpt-4-32k-0314": 30,
|
||||
"gpt-4-32k-0613": 30,
|
||||
"gpt-4-1106-preview": 5, // $0.01 / 1K tokens
|
||||
"gpt-4-vision-preview": 5, // $0.01 / 1K tokens
|
||||
"gpt-3.5-turbo": 0.75, // $0.0015 / 1K tokens
|
||||
"gpt-3.5-turbo-0301": 0.75,
|
||||
"gpt-3.5-turbo-0613": 0.75,
|
||||
@ -28,6 +31,7 @@ var ModelRatio = map[string]float64{
|
||||
"gpt-3.5-turbo-16k": 1.5, // $0.003 / 1K tokens
|
||||
"gpt-3.5-turbo-16k-0613": 1.5,
|
||||
"gpt-3.5-turbo-instruct": 0.75, // $0.0015 / 1K tokens
|
||||
"gpt-3.5-turbo-1106": 0.5, // $0.001 / 1K tokens
|
||||
"text-ada-001": 0.2,
|
||||
"text-babbage-001": 0.25,
|
||||
"text-curie-001": 1,
|
||||
@ -95,12 +99,27 @@ func GetCompletionRatio(name string) float64 {
|
||||
return 2
|
||||
}
|
||||
if strings.HasPrefix(name, "gpt-3.5") {
|
||||
if strings.HasSuffix(name, "1106") {
|
||||
return 2
|
||||
}
|
||||
if name == "gpt-3.5-turbo" || name == "gpt-3.5-turbo-16k" {
|
||||
// TODO: clear this after 2023-12-11
|
||||
now := time.Now()
|
||||
// https://platform.openai.com/docs/models/continuous-model-upgrades
|
||||
// if after 2023-12-11, use 2
|
||||
if now.After(time.Date(2023, 12, 11, 0, 0, 0, 0, time.UTC)) {
|
||||
return 2
|
||||
}
|
||||
}
|
||||
return 1.333333
|
||||
}
|
||||
if strings.HasPrefix(name, "gpt-4-1106") {
|
||||
return 3
|
||||
}
|
||||
if strings.HasPrefix(name, "gpt-4") {
|
||||
if strings.HasSuffix(name, "preview") {
|
||||
return 3
|
||||
}
|
||||
return 2
|
||||
}
|
||||
if strings.HasPrefix(name, "claude-instant-1") {
|
||||
|
@ -135,6 +135,15 @@ func init() {
|
||||
Root: "gpt-3.5-turbo-16k-0613",
|
||||
Parent: nil,
|
||||
},
|
||||
{
|
||||
Id: "gpt-3.5-turbo-1106",
|
||||
Object: "model",
|
||||
Created: 1699593571,
|
||||
OwnedBy: "openai",
|
||||
Permission: permission,
|
||||
Root: "gpt-3.5-turbo-1106",
|
||||
Parent: nil,
|
||||
},
|
||||
{
|
||||
Id: "gpt-3.5-turbo-instruct",
|
||||
Object: "model",
|
||||
@ -216,6 +225,24 @@ func init() {
|
||||
Root: "gpt-4-32k-0613",
|
||||
Parent: nil,
|
||||
},
|
||||
{
|
||||
Id: "gpt-4-1106-preview",
|
||||
Object: "model",
|
||||
Created: 1699593571,
|
||||
OwnedBy: "openai",
|
||||
Permission: permission,
|
||||
Root: "gpt-4-1106-preview",
|
||||
Parent: nil,
|
||||
},
|
||||
{
|
||||
Id: "gpt-4-vision-preview",
|
||||
Object: "model",
|
||||
Created: 1699593571,
|
||||
OwnedBy: "openai",
|
||||
Permission: permission,
|
||||
Root: "gpt-4-vision-preview",
|
||||
Parent: nil,
|
||||
},
|
||||
{
|
||||
Id: "text-embedding-ada-002",
|
||||
Object: "model",
|
||||
|
@ -9,19 +9,19 @@ services:
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
- ./data:/data
|
||||
- ./data/oneapi:/data
|
||||
- ./logs:/app/logs
|
||||
environment:
|
||||
- SQL_DSN=root:123456@tcp(host.docker.internal:3306)/one-api # 修改此行,或注释掉以使用 SQLite 作为数据库
|
||||
- SQL_DSN=oneapi:123456@tcp(db:3306)/one-api # 修改此行,或注释掉以使用 SQLite 作为数据库
|
||||
- REDIS_CONN_STRING=redis://redis
|
||||
- SESSION_SECRET=random_string # 修改为随机字符串
|
||||
- TZ=Asia/Shanghai
|
||||
# - NODE_TYPE=slave # 多机部署时从节点取消注释该行
|
||||
# - SYNC_FREQUENCY=60 # 需要定期从数据库加载数据时取消注释该行
|
||||
# - FRONTEND_BASE_URL=https://openai.justsong.cn # 多机部署时从节点取消注释该行
|
||||
|
||||
depends_on:
|
||||
- redis
|
||||
- db
|
||||
healthcheck:
|
||||
test: [ "CMD-SHELL", "wget -q -O - http://localhost:3000/api/status | grep -o '\"success\":\\s*true' | awk -F: '{print $2}'" ]
|
||||
interval: 30s
|
||||
@ -32,3 +32,18 @@ services:
|
||||
image: redis:latest
|
||||
container_name: redis
|
||||
restart: always
|
||||
|
||||
db:
|
||||
image: mysql:8.2.0
|
||||
restart: always
|
||||
container_name: mysql
|
||||
volumes:
|
||||
- ./data/mysql:/var/lib/mysql # 挂载目录,持久化存储
|
||||
ports:
|
||||
- '3306:3306'
|
||||
environment:
|
||||
TZ: Asia/Shanghai # 设置时区
|
||||
MYSQL_ROOT_PASSWORD: 'OneAPI@justsong' # 设置 root 用户的密码
|
||||
MYSQL_USER: oneapi # 创建专用用户
|
||||
MYSQL_PASSWORD: '123456' # 设置专用用户密码
|
||||
MYSQL_DATABASE: one-api # 自动创建数据库
|
@ -288,17 +288,15 @@ const ChannelsTable = () => {
|
||||
if (channels.length === 0) return;
|
||||
setLoading(true);
|
||||
let sortedChannels = [...channels];
|
||||
if (typeof sortedChannels[0][key] === 'string') {
|
||||
sortedChannels.sort((a, b) => {
|
||||
sortedChannels.sort((a, b) => {
|
||||
if (!isNaN(a[key])) {
|
||||
// If the value is numeric, subtract to sort
|
||||
return a[key] - b[key];
|
||||
} else {
|
||||
// If the value is not numeric, sort as strings
|
||||
return ('' + a[key]).localeCompare(b[key]);
|
||||
});
|
||||
} else {
|
||||
sortedChannels.sort((a, b) => {
|
||||
if (a[key] === b[key]) return 0;
|
||||
if (a[key] > b[key]) return -1;
|
||||
if (a[key] < b[key]) return 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
if (sortedChannels[0].id === channels[0].id) {
|
||||
sortedChannels.reverse();
|
||||
}
|
||||
@ -306,6 +304,7 @@ const ChannelsTable = () => {
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<Form onSubmit={searchChannels}>
|
||||
|
@ -130,7 +130,13 @@ const RedemptionsTable = () => {
|
||||
setLoading(true);
|
||||
let sortedRedemptions = [...redemptions];
|
||||
sortedRedemptions.sort((a, b) => {
|
||||
return ('' + a[key]).localeCompare(b[key]);
|
||||
if (!isNaN(a[key])) {
|
||||
// If the value is numeric, subtract to sort
|
||||
return a[key] - b[key];
|
||||
} else {
|
||||
// If the value is not numeric, sort as strings
|
||||
return ('' + a[key]).localeCompare(b[key]);
|
||||
}
|
||||
});
|
||||
if (sortedRedemptions[0].id === redemptions[0].id) {
|
||||
sortedRedemptions.reverse();
|
||||
|
@ -219,7 +219,13 @@ const TokensTable = () => {
|
||||
setLoading(true);
|
||||
let sortedTokens = [...tokens];
|
||||
sortedTokens.sort((a, b) => {
|
||||
return ('' + a[key]).localeCompare(b[key]);
|
||||
if (!isNaN(a[key])) {
|
||||
// If the value is numeric, subtract to sort
|
||||
return a[key] - b[key];
|
||||
} else {
|
||||
// If the value is not numeric, sort as strings
|
||||
return ('' + a[key]).localeCompare(b[key]);
|
||||
}
|
||||
});
|
||||
if (sortedTokens[0].id === tokens[0].id) {
|
||||
sortedTokens.reverse();
|
||||
|
@ -143,7 +143,13 @@ const UsersTable = () => {
|
||||
setLoading(true);
|
||||
let sortedUsers = [...users];
|
||||
sortedUsers.sort((a, b) => {
|
||||
return ('' + a[key]).localeCompare(b[key]);
|
||||
if (!isNaN(a[key])) {
|
||||
// If the value is numeric, subtract to sort
|
||||
return a[key] - b[key];
|
||||
} else {
|
||||
// If the value is not numeric, sort as strings
|
||||
return ('' + a[key]).localeCompare(b[key]);
|
||||
}
|
||||
});
|
||||
if (sortedUsers[0].id === users[0].id) {
|
||||
sortedUsers.reverse();
|
||||
|
Loading…
Reference in New Issue
Block a user