37 Commits

Author SHA1 Message Date
Yanyutin753
040a0b8d26 适配oaiFree 2024-04-04 10:02:04 +08:00
Clivia
e5c1fd5936 项目跟进oaifree 2024-04-04 09:54:12 +08:00
Clivia
579c02e270 Create oaifree-docker-image.yml 2024-04-04 09:53:38 +08:00
Yanyutin753
ce494a27f8 项目向oaifree迁移 2024-04-04 09:48:55 +08:00
Yanyutin753
fa971cf108 支持动态适配gpts 2024-02-26 13:08:45 +08:00
Clivia
10ae0b415c 优化非流式回复空的问题 2024-02-22 00:04:26 +08:00
Clivia
b850592a57 修改部署说明 2024-02-21 18:51:12 +08:00
Clivia
719e6f83a9 Update start.sh 2024-02-21 18:50:15 +08:00
Clivia
c07d1f3268 更新 gpts.json 2024-02-20 10:00:02 +08:00
Clivia
33fb486c82 修改key_for_gpts_info 2024-02-20 01:18:14 +08:00
Clivia
6203fb3535 update KEY_FOR_GPTS_INFO 2024-02-20 01:05:35 +08:00
Clivia
b19586e24a 优化更新gpts的结构 2024-02-19 21:50:02 +08:00
Clivia
9f80493866 Update docker-compose.yml 2024-02-17 17:43:43 +08:00
Clivia
36eede643d Update docker-compose.yml 2024-02-17 17:42:46 +08:00
Clivia
6032546b5d Create ninja-image.yml 2024-02-17 17:41:44 +08:00
Clivia
7328dadefb Update xyhelper-deploy.yml 2024-02-17 17:41:09 +08:00
Clivia
b7e2af8afd Update and rename docker-deploy.yml to xyhelper-deploy.yml 2024-02-17 17:40:48 +08:00
Clivia
04c1599756 Update docker-deploy.yml 2024-02-17 17:38:22 +08:00
Clivia
06665924f6 更新自定义网址更新access_token失败 2024-02-17 02:07:11 +08:00
Clivia
6787069afb 修改部署说明 2024-02-13 18:05:32 +08:00
Clivia
abbdebc24e 修改部署说明 2024-02-11 23:41:50 +08:00
Clivia
e599e2a0cc 修改部署说明 2024-02-11 23:08:37 +08:00
Clivia
0c0dd0e8a7 新增部署说明 2024-02-11 21:32:03 +08:00
Clivia
5524ad2b11 更新部署配置 2024-02-11 21:26:55 +08:00
Clivia
ef27e47f91 项目将脱离ninja,需修改配置 2024-02-11 21:19:30 +08:00
Clivia
26539a0d79 项目将脱离ninja,需修改相应配置 2024-02-11 21:11:53 +08:00
Clivia
a3b5ae310c 修改部署说明 2024-02-11 20:57:09 +08:00
Clivia
c85a228fb9 增加xyhelper渠道 2024-02-11 20:55:23 +08:00
Clivia
4a7338637d 添加xyhelper渠道刷新refresh_token为access_token 2024-02-11 20:54:28 +08:00
Clivia
d02e2d0eb1 Update main.py 2024-02-11 20:52:57 +08:00
Clivia
ebd3c3974f 修改部署说明 2024-02-11 20:04:06 +08:00
Clivia
ab88debcf3 修改部署说明 2024-02-11 19:57:23 +08:00
Clivia
73b14891dd 适配xyhelper的免费接口 2024-02-11 19:56:26 +08:00
Clivia
1f50b3d3a9 修改xyhelper免费部署说明 2024-02-11 19:55:13 +08:00
Clivia
227781a12c 部署说明 2024-02-11 11:11:01 +08:00
Clivia
f06821d54f Update main.py 2024-02-09 15:48:28 +08:00
Clivia
3637133b2e 增加请求头 2024-02-09 15:42:55 +08:00
12 changed files with 948 additions and 1141 deletions

View File

@@ -42,6 +42,5 @@ jobs:
push: true
tags: |
yangclivia/pandora-to-api:${{ steps.tag_name.outputs.tag }}
yangclivia/pandora-to-api:0.7.7
platforms: linux/amd64,linux/arm64
build-args: TARGETPLATFORM=${{ matrix.platform }}

View File

@@ -0,0 +1,46 @@
name: oaifree Build and Push Docker Image
on:
release:
types: [created]
workflow_dispatch:
inputs:
tag:
description: 'Tag Name'
required: true
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set tag name
id: tag_name
run: |
if [ "${{ github.event_name }}" = "release" ]; then
echo "::set-output name=tag::${GITHUB_REF#refs/tags/}"
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "::set-output name=tag::${{ github.event.inputs.tag }}"
fi
- name: Build and push Docker image with Release tag
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: |
yangclivia/pandora-to-api:${{ steps.tag_name.outputs.tag }}
platforms: linux/amd64,linux/arm64
build-args: TARGETPLATFORM=${{ matrix.platform }}

46
.github/workflows/xyhelper-deploy.yml vendored Normal file
View File

@@ -0,0 +1,46 @@
name: xyhelper Build and Push Docker Image
on:
release:
types: [created]
workflow_dispatch:
inputs:
tag:
description: 'Tag Name'
required: true
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set tag name
id: tag_name
run: |
if [ "${{ github.event_name }}" = "release" ]; then
echo "::set-output name=tag::${GITHUB_REF#refs/tags/}"
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "::set-output name=tag::${{ github.event.inputs.tag }}"
fi
- name: Build and push Docker image with Release tag
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: |
yangclivia/pandora-to-api:${{ steps.tag_name.outputs.tag }}
platforms: linux/amd64,linux/arm64
build-args: TARGETPLATFORM=${{ matrix.platform }}

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.log

6
.idea/encodings.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/log/access.log" charset="GBK" />
</component>
</project>

View File

@@ -10,13 +10,15 @@ COPY . /app
# 设置环境变量
ENV PYTHONUNBUFFERED=1
RUN chmod +x /app/main.py
RUN chmod +x /app/start.sh
RUN apt update && apt install -y jq
# # 设置 pip 源为清华大学镜像
# RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 安装任何所需的依赖项
RUN pip install --no-cache-dir flask flask_apscheduler requests Pillow flask-cors tiktoken fake_useragent redis websocket-client pysocks requests[socks] websocket-client[optional]
RUN pip install --no-cache-dir flask flask_apscheduler gunicorn requests Pillow flask-cors tiktoken fake_useragent redis websocket-client pysocks requests[socks] websocket-client[optional]
# 在容器启动时运行 Flask 应用
CMD ["python3", "main.py"]
CMD ["/app/start.sh"]

View File

@@ -1,21 +1,25 @@
## 0.7.7 ninja版本项目简介
![Docker Image Size (tag)](https://img.shields.io/docker/image-size/yangclivia/pandora-to-api/0.7.7)![Docker Pulls](https://img.shields.io/docker/pulls/yangclivia/pandora-to-api)[![GitHub Repo stars](https://img.shields.io/github/stars/Yanyutin753/RefreshToV1Api?style=social)](https://github.com/Yanyutin753/refresh-gpt-chat/stargazers)
## 项目简介
> [!IMPORTANT]
>
> Respect Zhile大佬 , Respect Wizerd
> Respect `oaiFree` , Respect `Wizerd`
感谢pandoraNext和Wizerd的付出,敬礼!!!
感谢oaiFree、Ink-Osier大佬们的付出,敬礼!!!
本项目支持:
1.ninja `proxy` 模式下的 `backend-api` 转为 `/v1/chat/completions` 接口,支持流式和非流式响应。
1.oaiFree `proxy` 模式下的 `backend-api` 转为 `/v1/chat/completions` 接口,支持流式和非流式响应。
2.ninja `proxy` 模式下的 `backend-api` 转为 `/v1/images/generations` 接口
2.oaiFree `proxy` 模式下的 `backend-api` 转为 `/v1/images/generations` 接口
3. 支持直接把refresh_token作为请求key方便接入one_api
4. 支持 gpt-4-mobile 、gpt-4-s 、基本所有的GPTS
* **oaiFree 的 免费 backend-api 接口,无需打码**
* 之后可能跟[Linux.do](https://linux.do/latest)论坛挂钩,请提前做好准备
如果本项目对你有帮助的话,请点个小星星吧~
如果有什么在项目的使用过程中的疑惑或需求,欢迎加入 Community Telegram Channel: [Inker 的魔法世界](https://t.me/InkerWorld) 来和大家一起交流一下~
@@ -34,7 +38,7 @@
- [x] 支持 gpt-3.5-turbo
- [x] 支持 动态gpts
- [x] 暂不 支持 gpts
- [x] 支持 流式输出
@@ -59,13 +63,13 @@
## 注意
> [!CAUTION]
> 1. 本项目的运行需要 ninja
> 1. 本项目的运行需要 oaiFree 的免费接口
>
> 2. 本项目实际为将来自 `/v1/chat/completions` 的请求转发到ninja的 `/backend-api/conversation` 接口,因此本项目并不支持高并发操作,请不要接入如 `沉浸式翻译` 等高并发项目。
> 2. 本项目实际为将来自 `/v1/chat/completions` 的请求转发到oaiFree免费接口的 `/backend-api/conversation` 接口,因此本项目并不支持高并发操作,请不要接入如 `沉浸式翻译` 等高并发项目。
>
> 3. 本项目支持使用apple平台的refresh_token作为请求key.
>
> 4. 本项目并不能绕过 OpenAI 和 ninja 官方的限制,只提供便利,不提供绕过。
> 4. 本项目并不能绕过 OpenAI 和 oaiFree 官方的限制,只提供便利,不提供绕过。
>
> 5. 提问的艺术:当出现项目不能正常运行时,请携带 `DEBUG` 级别的日志在 `Issue` 或者社区群内提问,否则将开启算命模式~
@@ -77,7 +81,7 @@
2. gpt-4-mobile支持代码解释器、bing联网、dalle绘图的 GPT-4对应的是官方的手机版 GPT-4截止至2023年12月15日本模型使用量不计入 GPT-4 用量(即不受每 3 小时 40 次的限制)
3. 几乎所有的 GPTS配置方式见下文
3. 由于oaiFree未提供GPTS接口暂不支持几乎所有的 GPTS配置方式见下文
4. gpt-3.5-turbo
@@ -91,19 +95,19 @@
- `need_log_to_file`: 用于设置是否需要将日志输出到文件,可选值为:`true``false`,默认为 `true`,日志文件路径为:`./log/access.log`,默认每天会自动分割日志文件。
- `process_workers`: 用于设置进程数,如果不需要设置,可以保持不变,如果需要设置,可以设置为需要设置的值,如果设置`1`,则会强制设置为单进程模式
- `process_workers`: 用于设置进程数,如果不需要设置,可以保持不变,如果需要设置,可以设置为需要设置的值,默认`2`
- `process_threads`: 用于设置线程数,如果不需要设置,可以保持不变,如果需要设置,可以设置为需要设置的值,如果设置`1`,则会强制设置为单线程模式
- `process_threads`: 用于设置线程数,如果不需要设置,可以保持不变,如果需要设置,可以设置为需要设置的值,默认`2`
- `upstream_base_url`: ninja 的部署地址,如:`https://pandoranext.com`,注意:不要以 `/` 结尾。可以填写为本项目可以访问到的 PandoraNext 的内网地址。
- `upstream_base_url`: oaiFree 的接口地址,如:`https://chat.oaifree.com`,注意:不要以 `/` 结尾。
- `upstream_api_prefix`: PandoraNext Proxy 模式下的 API 前缀
- `upstream_api_prefix`: 默认为["dad04481-fa3f-494e-b90c-b822128073e5"],之后可多填
- `backend_container_url`: 用于dalle模型生成图片的时候展示所用需要设置为使用如 [ChatGPT-Next-Web](https://github.com/ChatGPTNextWebTeam/ChatGPT-Next-Web) 的用户可以访问到的本项目地址,如:`http://1.2.3.4:50011`,同原环境变量中的 `UPLOAD_BASE_URL`
- `backend_container_api_prefix`: 用于设置本项目 `/v1/xxx` 接口的前缀如果留空则与官方api调用接口一致。设置示例`666 `
- `key_for_gpts_info`: 填入refresh_token每天自动转成access_token 推荐或者access_token(不推荐), 仅获取 GPTS 信息的 access_token需要该 access_token 能够访问所有配置的 GPTS。后续发送消息仍需要在请求头携带请求所用的 access_token如果未配置该项请将 `gpts.json` 文件修改为:
- `key_for_gpts_info(选填)`: 填入refresh_token每天自动转成access_token 推荐或者access_token(不推荐), 仅获取 GPTS 信息的 access_token需要该 access_token 能够访问所有配置的 GPTS。后续发送消息仍需要在请求头携带请求所用的 access_token如果未配置该项请将 `gpts.json` 文件修改为:
```json
{}
@@ -143,7 +147,8 @@ PS. 注意arkose_urls中的地址需要支持PandoraNext的Arkose Token获取
- `enableOai`:用于设置是否使用官网通过refresh_token刷新access_token仅在 `enableOai``true` 时生效。
- `ninja_refreshToAccess_Url`:用于设置使用ninja来进行使用refresh_token刷新access_token,enableOai为false的时候必填
- `oaiFree_refreshToAccess_Url`:用于设置使用oaiFree来进行使用refresh_token刷新access_token,enableOai为false的时候必填
- 默认为"https://token.oaifree.com/api/auth/refresh"
- `redis`
@@ -157,9 +162,7 @@ PS. 注意arkose_urls中的地址需要支持PandoraNext的Arkose Token获取
## GPTS配置说明
### 使用 GPTS
1. 可修改 `gpts.json` 文件其中每个对象的key即为调用对应 GPTS 的时候使用的模型名称,而 `id` 则为对应的模型id`id` 对应每个 GPTS 的链接的后缀。配置多个GPTS的时候用逗号隔开。
如果需要使用 GPTS需要修改 `gpts.json` 文件其中每个对象的key即为调用对应 GPTS 的时候使用的模型名称,而 `id` 则为对应的模型id`id` 对应每个 GPTS 的链接的后缀。配置多个GPTS的时候用逗号隔开。
例如PandoraNext的官方 GPTS 的链接为:`https://chat.oaifree.com/g/g-CFsXuTRfy-pandoranextzhu-shou`,则该模型的 `id` 的值应为 `g-CFsXuTRfy-pandoranextzhu-shou`,而模型名可以自定义。
@@ -176,16 +179,7 @@ PS. 注意arkose_urls中的地址需要支持PandoraNext的Arkose Token获取
}
```
2. 直接请求的时候加上相应的gpt-4-gizmo-XXXXXX等同于上面的id的值
```json
{
"stream":true,
"model":"gpt-4-gizmo-XXXX",
"messages": [{"role": "user", "content": "你是什么模型"}]
}
```
注意:使用该配置的时候需要保证正确填写 `config.json` 文件的环境变量 `KEY_FOR_GPTS_INFO`,同时该变量设置的 `key` 允许访问所有配置的 GPTS。
注意:使用该配置的时候需要保证正确填写 `docker-compose.yml` 的环境变量 `KEY_FOR_GPTS_INFO`,同时该变量设置的 `key` 允许访问所有配置的 GPTS。
## 绘图接口使用说明
@@ -193,7 +187,7 @@ PS. 注意arkose_urls中的地址需要支持PandoraNext的Arkose Token获取
请求方式:`POST`
请求头:正常携带 `Authorization``Content-Type` 即可,`Authorization` 的值为 `Bearer <ninja 的 fk>``Content-Type` 的值为 `application/json`
请求头:正常携带 `Authorization``Content-Type` 即可,`Authorization` 的值为 `Bearer <refresh_token>``Content-Type` 的值为 `application/json`
请求体格式示例:
@@ -326,7 +320,7 @@ PS. 注意arkose_urls中的地址需要支持PandoraNext的Arkose Token获取
## 示例
[ChatGPT-Next-Web](https://github.com/Yanyutin753/ChatGPT-Next-Web-LangChain-Gpt-4-All)项目插件版的docker-compose部署为例支持完全适配项目,这里提供一个简单的部署配置文件示例:
以ChatGPT-Next-Web项目的docker-compose部署为例这里提供一个简单的部署配置文件示例
```
version: '3'
@@ -336,10 +330,9 @@ services:
ports:
- "50013:3000"
environment:
- CUSTOM_MODELS=-all,+gpt-3.5-turbo,+gpt-4-s,+gpt-4-mobile,+gpt-4-vision-preview,+gpt-4-gizmo-XXX
- OPENAI_API_KEY=<正确的refresh_token>
- BASE_URL=<backend-to-api容器地址>
- CUSTOM_MODELS=-gpt-4-0613,-gpt-4-32k,-gpt-4-32k-0613,-gpt-4-turbo-preview,-gpt-4-1106-preview,-gpt-4-0125-preview,-gpt-3.5-turbo-0125,-gpt-3.5-turbo-0613,-gpt-3.5-turbo-1106,-gpt-3.5-turbo-16k,-gpt-3.5-turbo-16k-0613,+gpt-3.5-turbo,+gpt-4,+gpt-4-mobile,+gpt-4-vision-preview,+gpt-4-mobile,+<gpts.json 中的模型名>
- CUSTOM_MODELS=+gpt-4-s,+gpt-4-mobile,+<gpts.json 中的模型名>
```
@@ -354,20 +347,17 @@ services:
![api-2](https://github.com/Ink-Osier/PandoraToV1Api/assets/133617214/37c0381f-a70a-42bb-83f1-1491053240b7)
### 读文件
![api-3](https://github.com/Yanyutin753/xyhelperToV1Api_refresh/assets/132346501/e1f2e770-cd33-4af0-a0c7-5ddabf1c076d)
### 绘图
![api-4](https://github.com/Ink-Osier/PandoraToV1Api/assets/133617214/8eea9436-12ee-46b1-86c1-67e7e97da83a)
![api-3](https://github.com/Ink-Osier/PandoraToV1Api/assets/133617214/8eea9436-12ee-46b1-86c1-67e7e97da83a)
### GPT-4-Mobile
![api-5](https://github.com/Ink-Osier/PandoraToV1Api/assets/133617214/2eb4fd4f-7c66-4a1f-a54a-3c280a36e509)
![api-4](https://github.com/Ink-Osier/PandoraToV1Api/assets/133617214/2eb4fd4f-7c66-4a1f-a54a-3c280a36e509)
### GPTS
![api-6](https://github.com/Ink-Osier/PandoraToV1Api/assets/133617214/299df56a-d245-4920-8892-94e1a9cc644a)
![api-5](https://github.com/Ink-Osier/PandoraToV1Api/assets/133617214/299df56a-d245-4920-8892-94e1a9cc644a)
### Bot 模式
@@ -394,4 +384,4 @@ services:
## Star History
[![Star History Chart](https://api.star-history.com/svg?repos=Yanyutin753/ninjaToV1Api_refresh&type=Date)](https://star-history.com/#Yanyutin753/ninjaToV1Api_refresh&Date)
[![Star History Chart](https://api.star-history.com/svg?repos=Yanyutin753/oaiFreeV1Api_refresh&type=Date)](https://star-history.com/#Yanyutin753/oaiFreeV1Api_refresh&Date)

View File

@@ -4,8 +4,8 @@
"process_workers": 2,
"process_threads": 2,
"proxy": "",
"upstream_base_url": "",
"upstream_api_prefix": "",
"upstream_base_url": "https://chat.oaifree.com",
"upstream_api_prefix": ["dad04481-fa3f-494e-b90c-b822128073e5"],
"backend_container_url": "",
"backend_container_api_prefix": "",
"key_for_gpts_info": "",
@@ -26,8 +26,8 @@
},
"refresh_ToAccess": {
"stream_sleep_time": 0,
"enableOai":"true",
"ninja_refreshToAccess_Url": ""
"enableOai":"false",
"oaifree_refreshToAccess_Url": "https://token.oaifree.com/api/auth/refresh"
},
"redis": {
"host": "redis",

View File

@@ -1,5 +1 @@
{
"gpt-4-classic": {
"id":"g-YyyyMT9XH-chatgpt-classic"
}
}
{}

View File

@@ -2,7 +2,7 @@ version: '3'
services:
backend-to-api:
image: yangclivia/pandora-to-api:0.7.7
image: yangclivia/pandora-to-api:0.7.9
restart: always
ports:
- "50011:33333"

1888
main.py

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,7 @@ if [ -z "$PROCESS_WORKERS" ]; then
export PROCESS_WORKERS
if [ -z "$PROCESS_WORKERS" ]; then
PROCESS_WORKERS=1
PROCESS_WORKERS=2
fi
fi
@@ -31,4 +31,4 @@ echo "PROCESS_WORKERS: ${PROCESS_WORKERS}"
echo "PROCESS_THREADS: ${PROCESS_THREADS}"
# 启动 Gunicorn 并使用 tee 命令同时输出日志到文件和控制台
exec gunicorn -w ${PROCESS_WORKERS} --threads ${PROCESS_THREADS} --bind 0.0.0.0:33333 main:app --access-logfile - --error-logfile - --timeout 60
exec gunicorn -w ${PROCESS_WORKERS} --threads ${PROCESS_THREADS} --bind 0.0.0.0:33333 main:app --access-logfile - --error-logfile -