diff --git a/.github/ISSUE_TEMPLATE/bug-report-zh.yml b/.github/ISSUE_TEMPLATE/bug-report-zh.yml new file mode 100644 index 0000000..0ab21c0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report-zh.yml @@ -0,0 +1,70 @@ +name: 🐞 发现一个Bug! +description: 报告一个bug或不正常的行为 +labels: [unconfirmed bug] + +body: + - type: markdown + attributes: + value: 感谢你贡献问题! + + - type: checkboxes + id: checks + attributes: + label: 初始检查 + description: | + 请确认以下所有项均被满足 + options: + - label: 我运行的`openai-forward`版本不低于v0.6.0 + required: true + + - type: textarea + id: description + attributes: + label: 问题描述 + description: | + 请描述你遇到的问题,以及你期望看到的结果。 + + validations: + required: true + + - type: textarea + id: example + attributes: + label: 配置/代码示例和输出 + description: > + 如果可能,请添加一个最小化的、可复现该问题的代码/配置示例,以便开发者能够更好地理解你的问题。 + + - type: textarea + id: idea + attributes: + label: 我的见解 + description: > + 你对于这个bug的任何想法 + + + - type: textarea + id: version + attributes: + label: 环境 + description: | + Python版本、操作系统和`openai-forward`版本 + + 在终端执行以下命令,以查看输出版本: + + ```bash + python -c "import sys,platform; print('python: {}\nOS: {}'.format(sys.version, platform.system()));" + python -c "import openai_forward; print('openai_forward: {}'.format(openai_forward.__version__));" + ``` + + validations: + required: true + + + - type: checkboxes + id: checklist-final + attributes: + label: 最后一步 + description: 回顾你的回答 + options: + - label: 我认为上述的描述已经足够详细,开发者能够复现该问题 + required: true \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml new file mode 100644 index 0000000..7799db4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -0,0 +1,69 @@ +name: 🐞 Bug Report +description: Report a bug or unexpected behavior in openai-forward above (v0.6.0) +labels: [unconfirmed bug] + +body: + - type: markdown + attributes: + value: Thank you for contributing to openai-forward! + + + - type: checkboxes + id: checks + attributes: + label: Initial Checks + description: | + Just a few checks to make sure you need to create a bug report. + options: + - label: My `openai-forward` version is not lower than v0.6.0 + required: true + + - type: textarea + id: description + attributes: + label: Issue Description + description: | + Please describe the problem you encountered and what you expected to see. + + validations: + required: true + + - type: textarea + id: example + attributes: + label: Configuration/Code Example and Output + description: > + If possible, please provide a minimized, reproducible code/configuration example so developers can better understand your issue. + + - type: textarea + id: idea + attributes: + label: My Insight + description: > + Any thoughts you have regarding this bug + + - type: textarea + id: version + attributes: + label: Environment + description: | + Python version, operating system, and `openai-forward` version + + Run the following commands in the terminal to see the output versions: + + ```bash + python -c "import sys,platform; print('python: {}\nOS: {}'.format(sys.version, platform.system()));" + python -c "import openai_forward; print('openai_forward: {}'.format(openai_forward.__version__));" + ``` + + validations: + required: true + + - type: checkboxes + id: checklist-final + attributes: + label: Final Step + description: Review your answers + options: + - label: I believe my description above is detailed enough for developers to reproduce the issue. + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..0ea3890 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: true +contact_links: + - name: Join the Telegram channel + url: https://t.me/openai_forward + about: Join the official channel and stay tuned for news, updates and announcements. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request-zh.yml b/.github/ISSUE_TEMPLATE/feature_request-zh.yml new file mode 100644 index 0000000..616e21c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request-zh.yml @@ -0,0 +1,20 @@ +name: ✨ 功能请求 +description: Suggest ideas, new features or enhancements +labels: [enhancement] +body: + - type: checkboxes + attributes: + label: Checklist + options: + - label: 我相信这个想法很棒并且将使框架变得更好 + required: true + - label: 我已在issue中搜索了类似请求,包括已关闭的请求 + required: true + + - type: textarea + attributes: + label: 详细描述 + description: 提供一份对该请求的详细描述 + placeholder: 描述... + validations: + required: true \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..a6446b0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,21 @@ +name: ✨ Feature request + +description: Suggest ideas, new features or enhancements +labels: [enhancement] +body: + - type: checkboxes + attributes: + label: Checklist + options: + - label: I believe the idea is awesome and would benefit the framework + required: true + - label: I have searched in the issue tracker for similar requests, including closed ones + required: true + + - type: textarea + attributes: + label: Detailed Description + description: Provide a detailed description of the request + placeholder: Description... + validations: + required: true \ No newline at end of file diff --git a/.vercelignore b/.vercelignore deleted file mode 100644 index 91d7ded..0000000 --- a/.vercelignore +++ /dev/null @@ -1,2 +0,0 @@ -**/* -!vercel.json \ No newline at end of file diff --git a/Examples/completion.py b/Examples/completion.py index 64d548b..ee8cd38 100644 --- a/Examples/completion.py +++ b/Examples/completion.py @@ -16,7 +16,6 @@ user_content = "现在让我们使用泰勒展开推导出牛顿法迭代公式: \n" from sparrow import MeasureTime -mt = MeasureTime().start() resp = openai.Completion.create( model="gpt-3.5-turbo-instruct", prompt=user_content, diff --git a/README.md b/README.md index e8a9065..917328a 100644 --- a/README.md +++ b/README.md @@ -6,32 +6,27 @@

- OpenAI API风格接口转发服务
- The fastest way to deploy LLMs api forwarding
+ 一个支持多目标路由、流量控制、自动重试以及一键云端部署的高效代理工具

- PyPI version + + PyPI version + License - Release (latest by date) - - - GitHub repo size + Release (latest by date) - docker image size + docker image size - tests + tests - pypi downloads - - - codecov + pypi downloads

@@ -48,9 +43,10 @@ -OpenAI-Forward -是一个专为大型语言模型设计的高级转发服务,提供包括用户请求速率控制、Token速率限制和自定义API密钥等增强功能。该服务可用于代理本地模型(如 [LocalAI](https://github.com/go-skynet/LocalAI) -)或云端模型(如 [openai](https://api.openai.com))。 +openai-forward +是一个专为大型语言模型设计的高级转发服务,提供包括用户请求速率控制、Token速率限制和自定义API密钥等增强功能。 +该服务可用于代理本地模型(如 [LocalAI](https://github.com/go-skynet/LocalAI))或云端模型(如 [OpenAI](https://api.openai.com))。 +服务由 `fastapi`,`aiohttp`,`asyncio`全异步实现,保证了其高效性。 @@ -68,8 +64,8 @@ OpenAI-Forward 提供如下功能: - **实时响应日志**: 支持流式响应的会话日志记录 - **多目标路由**: 能够同时转发多个服务到不同的路由地址 - **自动重试机制**:在请求失败时自动重试 -- **快速部署**: `pip` /`docker` 快速本地安装和部署,支持一键云端部署 -- ... +- **快速部署**: `pip`/`docker` 快速本地安装和部署,支持一键云端部署 + 由本项目搭建的代理服务地址: @@ -77,7 +73,7 @@ OpenAI-Forward 提供如下功能: > https://render.openai-forward.com -注:此代理服务仅供学习和研究目的使用。 +注:此代理服务仅供个人学习和研究目的使用,勿用于任何商业用途。 ## 部署指南 @@ -129,16 +125,19 @@ INFO: Application startup complete. INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit) ``` -### 代理OpenAI API: +### 代理OpenAI模型: -这也是`aifd run`的默认选项 +`aifd run`的默认选项便是代理`https://api.openai.com` -#### 在三方应用中使用 +下面以搭建好的服务地址`https://api/openai-forward.com` 为例
点击展开 -基于开源项目[ChatGPT-Next-Web](https://github.com/Yidadaa/ChatGPT-Next-Web)搭建自己的chatgpt服务 +#### 在三方应用中使用 + + +基于开源项目[ChatGPT-Next-Web](https://github.com/Yidadaa/ChatGPT-Next-Web)中接入: 替换docker启动命令中的 `BASE_URL`为自己搭建的代理服务地址 ```bash @@ -150,7 +149,6 @@ docker run -d \ yidadaa/chatgpt-next-web ``` -
#### 在代码中接入 @@ -164,8 +162,6 @@ docker run -d \ openai.api_key = "sk-******" ``` -
- 更多(点击展开) **JS/TS** @@ -220,7 +216,7 @@ curl --location 'https://api.openai-forward.com/v1/images/generations' \ ### 代理其它云端模型 - **适用场景:** 例如,通过 [claude-to-chatgpt](https://github.com/jtsang4/claude-to-chatgpt) 可以将 claude 的 API 格式转换为 openai 的api格式, -然后使用 `openai-forward` 进行代理。 +然后使用本服务进行代理。 (更多) diff --git a/_worker.js b/_worker.js deleted file mode 100644 index 4100311..0000000 --- a/_worker.js +++ /dev/null @@ -1,13 +0,0 @@ -export default { - async fetch(request, env) { - try { - const url = new URL(request.url); - url.hostname = "api.openai.com"; - return await fetch( - new Request(url, {method: request.method, headers: request.headers, body: request.body}) - ); - } catch (e) { - return new Response(e.stack, {status: 500}); - } - } -} diff --git a/deploy.md b/deploy.md index 8d761b8..cc784c2 100644 --- a/deploy.md +++ b/deploy.md @@ -13,10 +13,7 @@ [pip部署](#pip部署) | [docker部署](#docker部署) | -[render一键部署](#render-一键部署) | -[railway一键部署](#railway-一键部署) | -[cloudflare部署](#cloudflare-部署) | -[Vercel一键部署](#Vercel-一键部署) +[render一键部署](#render-一键部署) @@ -29,14 +26,8 @@ **一键免费云平台部署** 1. [Render一键部署](deploy.md#render-一键部署) -2. [Railway部署](deploy.md#Railway-一键部署) --- -下面的部署仅包含反向代理功能 - -3. [一键Vercel部署](deploy.md#vercel-一键部署) -4. [cloudflare部署](deploy.md#cloudflare-部署) - ## pip部署 **安装** @@ -70,7 +61,7 @@ http://{ip}:{port}/v1/chat/completions 首先准备好一个域名, 如本项目中使用的域名为`api.openai-forward.com` 常用方式是使用nginx(不习惯用命令行配置的话可以考虑用 [Nginx Proxy Manager](https://github.com/NginxProxyManager/nginx-proxy-manager), 它可方便设置Let's Encrypt证书自动申请和自动续期) 代理转发 openai-forward 服务端口(默认8000)。 -需要注意的是,若要使用流式转发,在nginx配置中需要添加关闭代理缓存的配置, 即在Nginx Proxy Manager的 Custom Nginx Configuration中写入: +需要注意的是,若要使用流式转发,在nginx配置中需要添加关闭代理缓存的配置, 即在Nginx Proxy Manager页面的 Custom Nginx Configuration中写入: ```bash proxy_buffering off; ``` @@ -132,64 +123,3 @@ Render的免费计划: 每月750小时免费实例时间(意味着单个实例 > https://render.openai-forward.com > https://openai-forward.onrender.com - - - - - -## Railway 一键部署 -[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/tejCum?referralCode=U0-kXv) - -1. 点击上面部署按钮进行一键部署 - 也可先fork本仓库,再手动在操作界面导入自己的fork项目 -2. 填写环境变量,必填项`PORT` :`8000`, 可选项 如默认的OPENAI_API_KEY 等 -3. 绑定自定义域名 - -注: Railway 每月提供 $5.0和500小时执行时间的免费计划。这意味着单个免费用户每个月只能使用大约21天 - - - - - - - -⚠️下面两种部署方式仅提供简单的转发服务,没有任何额外功能。 -适合只有简单需求的用户(国内访问openai api服务)。 - -## Vercel 一键部署 - -[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fbeidongjiedeguang%2Fopenai-forward&project-name=openai-forward&repository-name=openai-forward&framework=other) -因python的部署方式在vercel上存在诸多限制,因此现在将Vercel部署方式切换为直接代理转发,而没有其它功能。 - -1. 点击按钮即可一键免费部署 - 也可先fork本仓库,再手动在vercel操作界面import项目 -2. [绑定自定义域名](https://vercel.com/docs/concepts/projects/domains/add-a-domain):Vercel 分配的DNS在某些区域被污染了导致国内无法访问,绑定自定义域名即可直连。 - - - - - - - -## Cloudflare 部署 - -部署方式二选一: -* Pages部署: fork本仓库,在[cloudflare](https://dash.cloudflare.com/)上创建应用程序时选择Pages, 然后选择连接到Git, 选择刚刚fork的仓库即可完成部署。 -* Workers部署: 在[cloudflare](https://dash.cloudflare.com/)上创建应用程序时选择Workers, 部署好示例代码后,点击快速修改(quick edit)复制[_worker.js](_worker.js) 至代码编辑器即可完成服务部署。 - -绑定自定义域名: **目前Pages部署时cloudflare自动分配的域名国内可以直接访问**, 而Workers部署时分配的则绑定自定义域名国内才可访问. - -绑定自定义域名需要将域名默认nameserver(域名服务器)绑定到cloudflare提供的nameserver,大体上过程是: -```mermaid -stateDiagram-v2 - [*] --> 注册cloudflare - [*] --> 在任意机构注册域名 - 注册cloudflare --> 添加worker/page - 添加worker/page --> 在cloudflare的worker/page中添加域名 : worker/page应用部署成功 - 在任意机构注册域名 --> 去注册域名机构更改默认nameserver为cloudflare提供的nameserver - 去注册域名机构更改默认nameserver为cloudflare提供的nameserver --> 在cloudflare的worker/page中添加域名: 域名服务器更改验证成功 - 在cloudflare的worker/page中添加域名 --> 成功 -``` -这种部署方式轻便简洁,支持流式转发. 不过目前[_worker.js](_worker.js)这个简单脚本仅提供转发服务, 不支持额外功能。 - -> https://openai-forward-9ak.pages.dev (这是cloudflare pages自动分配的域名,目前可以直接访问) diff --git a/pyproject.toml b/pyproject.toml index b137ef6..b8e4549 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,10 +34,10 @@ dependencies = [ dynamic = ["version"] [project.urls] -Homepage = "https://github.com/beidongjiedeguang/openai-forward" -Documentation = "https://github.com/beidongjiedeguang/openai-forward#openai-forward" -Issues = "https://github.com/beidongjiedeguang/openai-forward/issues" -Source = "https://github.com/beidongjiedeguang/openai-forward" +Homepage = "https://github.com/KenyonY/openai-forward" +Documentation = "https://github.com/KenyonY/openai-forward#openai-forward" +Issues = "https://github.com/KenyonY/openai-forward/issues" +Source = "https://github.com/KenyonY/openai-forward" [project.optional-dependencies] test = [ diff --git a/vercel.json b/vercel.json deleted file mode 100644 index 44cc392..0000000 --- a/vercel.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "rewrites": [ - { "source": "/", "destination": "https://api.openai.com" }, - { - "source": "/:match*", - "destination": "https://api.openai.com/:match*" - } - ], - "github": { - "silent": true - } -}