**中文** | ~~[**English**](./README_EN.md)~~
<h1 align="center">
<br>
OpenAI Forward
<br>
</h1>
<p align="center">
<b> OpenAI API风格接口转发服务 <br/>
The fastest way to deploy openai api forwarding </b>
</p>
<p align="center">
<a href="https://pypi.org/project/openai-forward/"><img src="https://img.shields.io/pypi/v/openai-forward?color=brightgreen" alt="PyPI version" ></a>
<a href="https://github.com/beidongjiedeguang/openai-forward/blob/main/LICENSE">
<img alt="License" src="https://img.shields.io/github/license/beidongjiedeguang/openai-forward.svg?color=blue&style=flat-square">
</a>
<a href="https://github.com/beidongjiedeguang/openai-forward/releases">
<img alt="Release (latest by date)" src="https://img.shields.io/github/v/release/beidongjiedeguang/openai-forward">
</a>
<a href="https://github.com/beidongjiedeguang/openai-forward">
<img alt="GitHub repo size" src="https://img.shields.io/github/repo-size/beidongjiedeguang/openai-forward">
</a>
<a href="https://hub.docker.com/r/beidongjiedeguang/openai-forward">
<img alt="docker image size" src="https://img.shields.io/docker/image-size/beidongjiedeguang/openai-forward?style=flat&label=docker image">
</a>
<a href="https://github.com/beidongjiedeguang/openai-forward/actions/workflows/ci.yml">
<img alt="tests" src="https://img.shields.io/github/actions/workflow/status/beidongjiedeguang/openai-forward/ci.yml?label=tests">
</a>
<a href="https://pypistats.org/packages/openai-forward">
<img alt="pypi downloads" src="https://img.shields.io/pypi/dm/openai_forward">
</a>
<a href="https://codecov.io/gh/beidongjiedeguang/openai-forward">
<img alt="codecov" src="https://codecov.io/gh/beidongjiedeguang/openai-forward/branch/dev/graph/badge.svg">
</a>
</p>
<div align="center">
[功能](#功能) |
[部署指南](#部署指南) |
[应用](#应用) |
[配置选项](#配置选项) |
[对话日志](#对话日志)
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/tejCum?referralCode=U0-kXv)
[![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy?repo=https://github.com/beidongjiedeguang/openai-forward)
</div>
本项目用于解决一些地区无法直接访问OpenAI的问题,将该服务部署在可以正常访问OpenAI API的(云)服务器上,
通过该服务转发OpenAI的请求。即搭建反向代理服务; 允许输入多个OpenAI API-KEY 组成轮询池; 可自定义二次分发api key.
<picture>
<source type="image/webp" srcset="https://raw.githubusercontent.com/beidongjiedeguang/openai-forward/main/.github/images/separators/aqua.webp">
<img src="https://raw.githubusercontent.com/beidongjiedeguang/openai-forward/main/.github/images/separators/aqua.png" height=8px width="100%">
</picture>
由本项目搭建的长期代理地址:
> https://api.openai-forward.com
> https://render.openai-forward.com
> https://cloudflare.page.openai-forward.com
> https://vercel.openai-forward.com
## 功能
**基础功能**
- [x] 支持转发OpenAI所有接口
- [x] 支持流式响应
- [x] 支持指定转发路由前缀
- [x] docker部署
- [x] pip 安装部署
- [x] Railway 一键部署
- [x] Render 一键部署
- [x] cloudflare 部署
- [x] Vercel一键部署
**高级功能**
- [x] 允许输入多个openai api key 组成轮询池
- [x] 自定义 转发api key (见[高级配置](#高级配置))
- [x] 流式响应对话日志
- [x] 多接口转发
## 部署指南
👉 [部署文档](deploy.md)
提供以下几种部署方式
**有海外vps方案**
1. [pip 安装部署](deploy.md#pip部署)
2. [Docker部署](deploy.md#docker部署)
> https://api.openai-forward.com
**无vps免费部署方案**
1. [Railway部署](deploy.md#Railway-一键部署)
> https://railway.openai-forward.com
2. [Render一键部署](deploy.md#render-一键部署)
> https://render.openai-forward.com
---
下面的部署仅提供单一转发功能
3. [一键Vercel部署](deploy.md#vercel-一键部署)
> https://vercel.openai-forward.com
4. [cloudflare部署](deploy.md#cloudflare-部署)
> https://cloudflare.page.openai-forward.com
## 应用
### [聊天应用](https://chat.beidongjiedeguang.top)
基于开源项目[ChatGPT-Next-Web](https://github.com/Yidadaa/ChatGPT-Next-Web)搭建自己的chatgpt服务
替换docker启动命令中的 `BASE_URL`为我们自己搭建的代理服务地址
<details >
<summary> details</summary>
```bash
docker run -d \
-p 3000:3000 \
-e OPENAI_API_KEY="sk-******" \
-e BASE_URL="https://api.openai-forward.com" \
-e CODE="******" \
yidadaa/chatgpt-next-web
```
</details>
### 在代码中使用
**Python**
```diff
import openai
+ openai.api_base = "https://api.openai-forward.com/v1"
openai.api_key = "sk-******"
```
<details open>
<summary>More Examples</summary>
**JS/TS**
```diff
import { Configuration } from "openai";
const configuration = new Configuration({
+ basePath: "https://api.openai-forward.com/v1",
apiKey: "sk-******",
});
```
**gpt-3.5-turbo**
```bash
curl https://api.openai-forward.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-******" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}'
```
**Image Generation (DALL-E)**
```bash
curl --location 'https://api.openai-forward.com/v1/images/generations' \
--header 'Authorization: Bearer sk-******' \
--header 'Content-Type: application/json' \
--data '{
"prompt": "A photo of a cat",
"n": 1,
"size": "512x512"
}'
```
</details>
## 配置选项
配置的设置方式支持两种
一种为在命令行中执行`aifd run` 的运行参数(如`--port=8000`)中指定;
另一种为读取环境变量的方式指定。
### 命令行参数
可通过 `aifd run --help` 查看
<details open>
<summary>Click for more details</summary>
**`aifd run`参数配置项**
| 配置项 | 说明 | 默认值 |
|-----------------------|-----------------------|:----------------------:|
| --port | 服务端口号 | 8000 |
| --workers | 工作进程数 | 1 |
| --openai_base_url | 同 OPENAI_BASE_URL | https://api.openai.com |
| --openai_route_prefix | 同 OPENAI_ROUTE_PREFIX | `None` |
| --api_key | 同 OPENAI_API_KEY | `None` |
| --forward_key | 同 FORWARD_KEY | `None` |
| --extra_base_url | 同 EXTRA_BASE_URL | `None` |
| --extra_route_prefix | 同 EXTRA_ROUTE_PREFIX | `None` |
| --log_chat | 同 LOG_CHAT | `False` |
</details>
### 环境变量配置项
支持从运行目录下的`.env`文件中读取
| 环境变量 | 说明 | 默认值 |
|---------------------|-----------------------------------------------------------------------------------------------------------------------------------|:----------------------:|
| OPENAI_BASE_URL | 默认 openai官方 api 地址 | https://api.openai.com |
| OPENAI_ROUTE_PREFIX | openai(接口格式)路由前缀 | / |
| OPENAI_API_KEY | 默认openai api key,支持多个默认api key, 以 `sk-` 开头, 以逗号分隔 | 无 |
| FORWARD_KEY | 允许调用方使用该key代替openai api key,支持多个forward key, 以逗号分隔; 如果设置了OPENAI_API_KEY,而没有设置FORWARD_KEY, 则客户端调用时无需提供密钥, 此时出于安全考虑不建议FORWARD_KEY置空 | 无 |
| EXTRA_BASE_URL | 额外转发服务地址 | 无 |
| EXTRA_ROUTE_PREFIX | 额外转发服务路由前缀 | 无 |
| LOG_CHAT | 是否记录聊天内容 | `false` |
## 高级配置
### 设置openai api_key为自定义的forward key
<details markdown="1">
<summary>Click for more details</summary>
需要配置 OPENAI_API_KEY 和 FORWARD_KEY, 例如
```bash
OPENAI_API_KEY=sk-*******
FORWARD_KEY=fk-****** # 这里fk-token由我们自己定义
```
这里我们配置了FORWARD_KEY为`fk-******`, 那么后面客户端在调用时只需设置OPENAI_API_KEY为我们自定义的`fk-******` 即可。
这样的好处是在使用一些需要输入OPENAI_API_KEY的第三方应用时,我们可以使用自定义的api-key`fk-******`,
无需担心真正的OPENAI_API_KEY被泄露。并且可以对外分发`fk-******`。
**用例:**
```bash
curl https://api.openai-forward.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer fk-******" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}'
```
**Python**
```diff
import openai
+ openai.api_base = "https://api.openai-forward.com/v1"
- openai.api_key = "sk-******"
+ openai.api_key = "fk-******"
```
**Web application**
```bash
docker run -d \
-p 3000:3000 \
-e OPENAI_API_KEY="fk-******" \
-e BASE_URL="https://api.openai-forward.com" \
-e CODE="<your password>" \
yidadaa/chatgpt-next-web
```
</details>
### 多路由转发
支持转发不同地址的服务至同一端口的不同路由下,基本可以转发任何服务。
用例见 `.env.example`
## 对话日志
默认不记录对话日志,若要开启需设置环境变量`LOG_CHAT=true`
<details open>
<summary>Click for more details</summary>
保存路径在当前目录下的`Log/chat`路径中。
记录格式为
```text
{'messages': [{'user': 'hi'}], 'model': 'gpt-3.5-turbo', 'forwarded-for': '', 'uid': '467a17ec-bf39-4b65-9ebd-e722b3bdd5c3', 'datetime': '2023-07-18 14:01:21'}
{'assistant': 'Hello there! How can I assist you today?', 'uid': '467a17ec-bf39-4b65-9ebd-e722b3bdd5c3'}
{'messages': [{'user': 'Hello!'}], 'model': 'gpt-3.5-turbo', 'forwarded-for': '', 'uid': 'f844d156-e747-4887-aef8-e40d977b5ee7', 'datetime': '2023-07-18 14:01:23'}
{'assistant': 'Hi there! How can I assist you today?', 'uid': 'f844d156-e747-4887-aef8-e40d977b5ee7'}
```
转换为`json`格式:
```bash
aifd convert
```
得到`chat.json`:
```json
[
{
"datetime": "2023-07-18 14:01:21",
"forwarded-for": "",
"model": "gpt-3.5-turbo",
"messages": [
{
"user": "hi"
}
],
"assistant": "Hello there! How can I assist you today?"
},
{
"datetime": "2023-07-18 14:01:23",
"forwarded-for": "",
"model": "gpt-3.5-turbo",
"messages": [
{
"user": "Hello!"
}
],
"assistant": "Hi there! How can I assist you today?"
}
]
```
</details>
## Backer and Sponsor
<a href="https://www.jetbrains.com/?from=beidongjiedeguang/openai-forward" target="_blank">
<img src=".github/images/jetbrains.svg" width="100px" height="100px">
</a>
## License
OpenAI-Forward is licensed under the [MIT](https://opensource.org/license/mit/) license.
Raw data
{
"_id": null,
"home_page": "",
"name": "gpt-forward",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "OpenAI API Forwarding,chatgpt,fastapi,openai,openai-api,openai-proxy,python,streaming-api",
"author": "",
"author_email": "kunyuan <beidongjiedeguang@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/55/6e/d9e50e45c57904c7db7af3c16fd5b668b210b81e6b619ae8ac266a5ca3fa/gpt_forward-0.0.1a0.tar.gz",
"platform": null,
"description": "**\u4e2d\u6587** | ~~[**English**](./README_EN.md)~~\n\n<h1 align=\"center\">\n <br>\n OpenAI Forward\n <br>\n</h1>\n<p align=\"center\">\n <b> OpenAI API\u98ce\u683c\u63a5\u53e3\u8f6c\u53d1\u670d\u52a1 <br/>\n The fastest way to deploy openai api forwarding </b>\n</p>\n\n<p align=\"center\">\n <a href=\"https://pypi.org/project/openai-forward/\"><img src=\"https://img.shields.io/pypi/v/openai-forward?color=brightgreen\" alt=\"PyPI version\" ></a>\n <a href=\"https://github.com/beidongjiedeguang/openai-forward/blob/main/LICENSE\">\n <img alt=\"License\" src=\"https://img.shields.io/github/license/beidongjiedeguang/openai-forward.svg?color=blue&style=flat-square\">\n </a>\n <a href=\"https://github.com/beidongjiedeguang/openai-forward/releases\">\n <img alt=\"Release (latest by date)\" src=\"https://img.shields.io/github/v/release/beidongjiedeguang/openai-forward\">\n </a>\n <a href=\"https://github.com/beidongjiedeguang/openai-forward\">\n <img alt=\"GitHub repo size\" src=\"https://img.shields.io/github/repo-size/beidongjiedeguang/openai-forward\">\n </a>\n <a href=\"https://hub.docker.com/r/beidongjiedeguang/openai-forward\">\n <img alt=\"docker image size\" src=\"https://img.shields.io/docker/image-size/beidongjiedeguang/openai-forward?style=flat&label=docker image\">\n </a>\n <a href=\"https://github.com/beidongjiedeguang/openai-forward/actions/workflows/ci.yml\">\n <img alt=\"tests\" src=\"https://img.shields.io/github/actions/workflow/status/beidongjiedeguang/openai-forward/ci.yml?label=tests\">\n </a>\n <a href=\"https://pypistats.org/packages/openai-forward\">\n <img alt=\"pypi downloads\" src=\"https://img.shields.io/pypi/dm/openai_forward\">\n </a>\n <a href=\"https://codecov.io/gh/beidongjiedeguang/openai-forward\">\n <img alt=\"codecov\" src=\"https://codecov.io/gh/beidongjiedeguang/openai-forward/branch/dev/graph/badge.svg\">\n </a>\n</p>\n\n<div align=\"center\">\n\n[\u529f\u80fd](#\u529f\u80fd) |\n[\u90e8\u7f72\u6307\u5357](#\u90e8\u7f72\u6307\u5357) |\n[\u5e94\u7528](#\u5e94\u7528) |\n[\u914d\u7f6e\u9009\u9879](#\u914d\u7f6e\u9009\u9879) |\n[\u5bf9\u8bdd\u65e5\u5fd7](#\u5bf9\u8bdd\u65e5\u5fd7)\n\n[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/tejCum?referralCode=U0-kXv) \n[![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy?repo=https://github.com/beidongjiedeguang/openai-forward)\n\n</div>\n\n\u672c\u9879\u76ee\u7528\u4e8e\u89e3\u51b3\u4e00\u4e9b\u5730\u533a\u65e0\u6cd5\u76f4\u63a5\u8bbf\u95eeOpenAI\u7684\u95ee\u9898\uff0c\u5c06\u8be5\u670d\u52a1\u90e8\u7f72\u5728\u53ef\u4ee5\u6b63\u5e38\u8bbf\u95eeOpenAI API\u7684(\u4e91)\u670d\u52a1\u5668\u4e0a\uff0c\n\u901a\u8fc7\u8be5\u670d\u52a1\u8f6c\u53d1OpenAI\u7684\u8bf7\u6c42\u3002\u5373\u642d\u5efa\u53cd\u5411\u4ee3\u7406\u670d\u52a1; \u5141\u8bb8\u8f93\u5165\u591a\u4e2aOpenAI API-KEY \u7ec4\u6210\u8f6e\u8be2\u6c60; \u53ef\u81ea\u5b9a\u4e49\u4e8c\u6b21\u5206\u53d1api key.\n\n\n<picture>\n <source type=\"image/webp\" srcset=\"https://raw.githubusercontent.com/beidongjiedeguang/openai-forward/main/.github/images/separators/aqua.webp\">\n <img src=\"https://raw.githubusercontent.com/beidongjiedeguang/openai-forward/main/.github/images/separators/aqua.png\" height=8px width=\"100%\">\n</picture>\n\n\u7531\u672c\u9879\u76ee\u642d\u5efa\u7684\u957f\u671f\u4ee3\u7406\u5730\u5740\uff1a\n> https://api.openai-forward.com \n> https://render.openai-forward.com \n> https://cloudflare.page.openai-forward.com \n> https://vercel.openai-forward.com \n\n## \u529f\u80fd\n\n**\u57fa\u7840\u529f\u80fd**\n\n- [x] \u652f\u6301\u8f6c\u53d1OpenAI\u6240\u6709\u63a5\u53e3\n- [x] \u652f\u6301\u6d41\u5f0f\u54cd\u5e94\n- [x] \u652f\u6301\u6307\u5b9a\u8f6c\u53d1\u8def\u7531\u524d\u7f00\n- [x] docker\u90e8\u7f72\n- [x] pip \u5b89\u88c5\u90e8\u7f72\n- [x] Railway \u4e00\u952e\u90e8\u7f72\n- [x] Render \u4e00\u952e\u90e8\u7f72\n- [x] cloudflare \u90e8\u7f72\n- [x] Vercel\u4e00\u952e\u90e8\u7f72\n\n**\u9ad8\u7ea7\u529f\u80fd**\n\n- [x] \u5141\u8bb8\u8f93\u5165\u591a\u4e2aopenai api key \u7ec4\u6210\u8f6e\u8be2\u6c60\n- [x] \u81ea\u5b9a\u4e49 \u8f6c\u53d1api key (\u89c1[\u9ad8\u7ea7\u914d\u7f6e](#\u9ad8\u7ea7\u914d\u7f6e))\n- [x] \u6d41\u5f0f\u54cd\u5e94\u5bf9\u8bdd\u65e5\u5fd7\n- [x] \u591a\u63a5\u53e3\u8f6c\u53d1\n\n## \u90e8\u7f72\u6307\u5357\n\n\ud83d\udc49 [\u90e8\u7f72\u6587\u6863](deploy.md)\n\n\u63d0\u4f9b\u4ee5\u4e0b\u51e0\u79cd\u90e8\u7f72\u65b9\u5f0f \n**\u6709\u6d77\u5916vps\u65b9\u6848**\n\n1. [pip \u5b89\u88c5\u90e8\u7f72](deploy.md#pip\u90e8\u7f72)\n2. [Docker\u90e8\u7f72](deploy.md#docker\u90e8\u7f72)\n > https://api.openai-forward.com\n\n**\u65e0vps\u514d\u8d39\u90e8\u7f72\u65b9\u6848**\n\n1. [Railway\u90e8\u7f72](deploy.md#Railway-\u4e00\u952e\u90e8\u7f72)\n > https://railway.openai-forward.com\n2. [Render\u4e00\u952e\u90e8\u7f72](deploy.md#render-\u4e00\u952e\u90e8\u7f72)\n > https://render.openai-forward.com\n\n---\n\u4e0b\u9762\u7684\u90e8\u7f72\u4ec5\u63d0\u4f9b\u5355\u4e00\u8f6c\u53d1\u529f\u80fd\n\n3. [\u4e00\u952eVercel\u90e8\u7f72](deploy.md#vercel-\u4e00\u952e\u90e8\u7f72)\n > https://vercel.openai-forward.com\n4. [cloudflare\u90e8\u7f72](deploy.md#cloudflare-\u90e8\u7f72)\n > https://cloudflare.page.openai-forward.com\n\n## \u5e94\u7528\n\n### [\u804a\u5929\u5e94\u7528](https://chat.beidongjiedeguang.top)\n\n\u57fa\u4e8e\u5f00\u6e90\u9879\u76ee[ChatGPT-Next-Web](https://github.com/Yidadaa/ChatGPT-Next-Web)\u642d\u5efa\u81ea\u5df1\u7684chatgpt\u670d\u52a1 \n\u66ff\u6362docker\u542f\u52a8\u547d\u4ee4\u4e2d\u7684 `BASE_URL`\u4e3a\u6211\u4eec\u81ea\u5df1\u642d\u5efa\u7684\u4ee3\u7406\u670d\u52a1\u5730\u5740\n\n\n<details >\n <summary> details</summary> \n\n```bash \ndocker run -d \\\n -p 3000:3000 \\\n -e OPENAI_API_KEY=\"sk-******\" \\\n -e BASE_URL=\"https://api.openai-forward.com\" \\\n -e CODE=\"******\" \\\n yidadaa/chatgpt-next-web \n``` \n\n</details>\n\n### \u5728\u4ee3\u7801\u4e2d\u4f7f\u7528\n\n**Python**\n\n```diff\n import openai\n+ openai.api_base = \"https://api.openai-forward.com/v1\"\n openai.api_key = \"sk-******\"\n```\n\n<details open>\n <summary>More Examples</summary>\n\n**JS/TS**\n\n```diff\n import { Configuration } from \"openai\";\n \n const configuration = new Configuration({\n+ basePath: \"https://api.openai-forward.com/v1\",\n apiKey: \"sk-******\",\n });\n```\n\n**gpt-3.5-turbo**\n\n```bash\ncurl https://api.openai-forward.com/v1/chat/completions \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer sk-******\" \\\n -d '{\n \"model\": \"gpt-3.5-turbo\",\n \"messages\": [{\"role\": \"user\", \"content\": \"Hello!\"}]\n }'\n```\n\n**Image Generation (DALL-E)**\n\n```bash\ncurl --location 'https://api.openai-forward.com/v1/images/generations' \\\n--header 'Authorization: Bearer sk-******' \\\n--header 'Content-Type: application/json' \\\n--data '{\n \"prompt\": \"A photo of a cat\",\n \"n\": 1,\n \"size\": \"512x512\"\n}'\n```\n\n</details>\n\n## \u914d\u7f6e\u9009\u9879\n\n\u914d\u7f6e\u7684\u8bbe\u7f6e\u65b9\u5f0f\u652f\u6301\u4e24\u79cd \n\u4e00\u79cd\u4e3a\u5728\u547d\u4ee4\u884c\u4e2d\u6267\u884c`aifd run` \u7684\u8fd0\u884c\u53c2\u6570(\u5982`--port=8000`)\u4e2d\u6307\u5b9a; \n\u53e6\u4e00\u79cd\u4e3a\u8bfb\u53d6\u73af\u5883\u53d8\u91cf\u7684\u65b9\u5f0f\u6307\u5b9a\u3002\n\n### \u547d\u4ee4\u884c\u53c2\u6570\n\n\u53ef\u901a\u8fc7 `aifd run --help` \u67e5\u770b\n\n<details open>\n <summary>Click for more details</summary>\n\n**`aifd run`\u53c2\u6570\u914d\u7f6e\u9879**\n\n| \u914d\u7f6e\u9879 | \u8bf4\u660e | \u9ed8\u8ba4\u503c |\n|-----------------------|-----------------------|:----------------------:|\n| --port | \u670d\u52a1\u7aef\u53e3\u53f7 | 8000 |\n| --workers | \u5de5\u4f5c\u8fdb\u7a0b\u6570 | 1 |\n| --openai_base_url | \u540c OPENAI_BASE_URL | https://api.openai.com |\n| --openai_route_prefix | \u540c OPENAI_ROUTE_PREFIX | `None` |\n| --api_key | \u540c OPENAI_API_KEY | `None` |\n| --forward_key | \u540c FORWARD_KEY | `None` |\n| --extra_base_url | \u540c EXTRA_BASE_URL | `None` |\n| --extra_route_prefix | \u540c EXTRA_ROUTE_PREFIX | `None` |\n| --log_chat | \u540c LOG_CHAT | `False` |\n\n</details>\n\n### \u73af\u5883\u53d8\u91cf\u914d\u7f6e\u9879\n\n\u652f\u6301\u4ece\u8fd0\u884c\u76ee\u5f55\u4e0b\u7684`.env`\u6587\u4ef6\u4e2d\u8bfb\u53d6\n\n| \u73af\u5883\u53d8\u91cf | \u8bf4\u660e | \u9ed8\u8ba4\u503c |\n|---------------------|-----------------------------------------------------------------------------------------------------------------------------------|:----------------------:|\n| OPENAI_BASE_URL | \u9ed8\u8ba4 openai\u5b98\u65b9 api \u5730\u5740 | https://api.openai.com |\n| OPENAI_ROUTE_PREFIX | openai(\u63a5\u53e3\u683c\u5f0f)\u8def\u7531\u524d\u7f00 | / |\n| OPENAI_API_KEY | \u9ed8\u8ba4openai api key\uff0c\u652f\u6301\u591a\u4e2a\u9ed8\u8ba4api key, \u4ee5 `sk-` \u5f00\u5934\uff0c \u4ee5\u9017\u53f7\u5206\u9694 | \u65e0 |\n| FORWARD_KEY | \u5141\u8bb8\u8c03\u7528\u65b9\u4f7f\u7528\u8be5key\u4ee3\u66ffopenai api key\uff0c\u652f\u6301\u591a\u4e2aforward key, \u4ee5\u9017\u53f7\u5206\u9694; \u5982\u679c\u8bbe\u7f6e\u4e86OPENAI_API_KEY\uff0c\u800c\u6ca1\u6709\u8bbe\u7f6eFORWARD_KEY, \u5219\u5ba2\u6237\u7aef\u8c03\u7528\u65f6\u65e0\u9700\u63d0\u4f9b\u5bc6\u94a5, \u6b64\u65f6\u51fa\u4e8e\u5b89\u5168\u8003\u8651\u4e0d\u5efa\u8baeFORWARD_KEY\u7f6e\u7a7a | \u65e0 |\n| EXTRA_BASE_URL | \u989d\u5916\u8f6c\u53d1\u670d\u52a1\u5730\u5740 | \u65e0 |\n| EXTRA_ROUTE_PREFIX | \u989d\u5916\u8f6c\u53d1\u670d\u52a1\u8def\u7531\u524d\u7f00 | \u65e0 |\n| LOG_CHAT | \u662f\u5426\u8bb0\u5f55\u804a\u5929\u5185\u5bb9 | `false` |\n\n## \u9ad8\u7ea7\u914d\u7f6e\n\n### \u8bbe\u7f6eopenai api_key\u4e3a\u81ea\u5b9a\u4e49\u7684forward key\n<details markdown=\"1\">\n <summary>Click for more details</summary>\n\n\u9700\u8981\u914d\u7f6e OPENAI_API_KEY \u548c FORWARD_KEY, \u4f8b\u5982\n\n```bash\nOPENAI_API_KEY=sk-*******\nFORWARD_KEY=fk-****** # \u8fd9\u91ccfk-token\u7531\u6211\u4eec\u81ea\u5df1\u5b9a\u4e49\n```\n\n\u8fd9\u91cc\u6211\u4eec\u914d\u7f6e\u4e86FORWARD_KEY\u4e3a`fk-******`, \u90a3\u4e48\u540e\u9762\u5ba2\u6237\u7aef\u5728\u8c03\u7528\u65f6\u53ea\u9700\u8bbe\u7f6eOPENAI_API_KEY\u4e3a\u6211\u4eec\u81ea\u5b9a\u4e49\u7684`fk-******` \u5373\u53ef\u3002 \n\u8fd9\u6837\u7684\u597d\u5904\u662f\u5728\u4f7f\u7528\u4e00\u4e9b\u9700\u8981\u8f93\u5165OPENAI_API_KEY\u7684\u7b2c\u4e09\u65b9\u5e94\u7528\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u81ea\u5b9a\u4e49\u7684api-key`fk-******`,\n\u65e0\u9700\u62c5\u5fc3\u771f\u6b63\u7684OPENAI_API_KEY\u88ab\u6cc4\u9732\u3002\u5e76\u4e14\u53ef\u4ee5\u5bf9\u5916\u5206\u53d1`fk-******`\u3002\n\n**\u7528\u4f8b:**\n\n```bash\ncurl https://api.openai-forward.com/v1/chat/completions \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer fk-******\" \\\n -d '{\n \"model\": \"gpt-3.5-turbo\",\n \"messages\": [{\"role\": \"user\", \"content\": \"Hello!\"}]\n }'\n```\n\n**Python**\n\n```diff\n import openai\n+ openai.api_base = \"https://api.openai-forward.com/v1\"\n- openai.api_key = \"sk-******\"\n+ openai.api_key = \"fk-******\"\n```\n\n**Web application**\n\n```bash \ndocker run -d \\\n -p 3000:3000 \\\n -e OPENAI_API_KEY=\"fk-******\" \\\n -e BASE_URL=\"https://api.openai-forward.com\" \\\n -e CODE=\"<your password>\" \\\n yidadaa/chatgpt-next-web \n``` \n\n</details>\n\n### \u591a\u8def\u7531\u8f6c\u53d1\n\n\u652f\u6301\u8f6c\u53d1\u4e0d\u540c\u5730\u5740\u7684\u670d\u52a1\u81f3\u540c\u4e00\u7aef\u53e3\u7684\u4e0d\u540c\u8def\u7531\u4e0b\uff0c\u57fa\u672c\u53ef\u4ee5\u8f6c\u53d1\u4efb\u4f55\u670d\u52a1\u3002 \n\u7528\u4f8b\u89c1 `.env.example`\n\n\n## \u5bf9\u8bdd\u65e5\u5fd7\n\n\u9ed8\u8ba4\u4e0d\u8bb0\u5f55\u5bf9\u8bdd\u65e5\u5fd7\uff0c\u82e5\u8981\u5f00\u542f\u9700\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf`LOG_CHAT=true`\n<details open>\n <summary>Click for more details</summary>\n\n\u4fdd\u5b58\u8def\u5f84\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u7684`Log/chat`\u8def\u5f84\u4e2d\u3002 \n\u8bb0\u5f55\u683c\u5f0f\u4e3a\n\n```text\n{'messages': [{'user': 'hi'}], 'model': 'gpt-3.5-turbo', 'forwarded-for': '', 'uid': '467a17ec-bf39-4b65-9ebd-e722b3bdd5c3', 'datetime': '2023-07-18 14:01:21'}\n{'assistant': 'Hello there! How can I assist you today?', 'uid': '467a17ec-bf39-4b65-9ebd-e722b3bdd5c3'}\n{'messages': [{'user': 'Hello!'}], 'model': 'gpt-3.5-turbo', 'forwarded-for': '', 'uid': 'f844d156-e747-4887-aef8-e40d977b5ee7', 'datetime': '2023-07-18 14:01:23'}\n{'assistant': 'Hi there! How can I assist you today?', 'uid': 'f844d156-e747-4887-aef8-e40d977b5ee7'}\n```\n\n\u8f6c\u6362\u4e3a`json`\u683c\u5f0f\uff1a\n\n```bash\naifd convert\n```\n\n\u5f97\u5230`chat.json`\uff1a\n\n```json\n[\n {\n \"datetime\": \"2023-07-18 14:01:21\",\n \"forwarded-for\": \"\",\n \"model\": \"gpt-3.5-turbo\",\n \"messages\": [\n {\n \"user\": \"hi\"\n }\n ],\n \"assistant\": \"Hello there! How can I assist you today?\"\n },\n {\n \"datetime\": \"2023-07-18 14:01:23\",\n \"forwarded-for\": \"\",\n \"model\": \"gpt-3.5-turbo\",\n \"messages\": [\n {\n \"user\": \"Hello!\"\n }\n ],\n \"assistant\": \"Hi there! How can I assist you today?\"\n }\n]\n```\n\n</details>\n\n## Backer and Sponsor\n\n<a href=\"https://www.jetbrains.com/?from=beidongjiedeguang/openai-forward\" target=\"_blank\">\n<img src=\".github/images/jetbrains.svg\" width=\"100px\" height=\"100px\">\n</a>\n\n## License\n\nOpenAI-Forward is licensed under the [MIT](https://opensource.org/license/mit/) license.\n",
"bugtrack_url": null,
"license": "",
"summary": "\ud83d\ude80 OpenAI API Reverse Proxy \u00b7 ChatGPT API Proxy",
"version": "0.0.1a0",
"project_urls": {
"Documentation": "https://github.com/beidongjiedeguang/openai-forward#openai-forward",
"Homepage": "https://github.com/beidongjiedeguang/openai-forward",
"Issues": "https://github.com/beidongjiedeguang/openai-forward/issues",
"Source": "https://github.com/beidongjiedeguang/openai-forward"
},
"split_keywords": [
"openai api forwarding",
"chatgpt",
"fastapi",
"openai",
"openai-api",
"openai-proxy",
"python",
"streaming-api"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "276b97540bfd4f1ad578cce3612a4491f62bf96abcb15348eeee4fed1500a0b3",
"md5": "19800c5f6b416860406ea3b7e04e3c93",
"sha256": "fb8ccac6cb35c7bb742a154881ef70a1610be8f1bb8e96f58f6d0beeada089ef"
},
"downloads": -1,
"filename": "gpt_forward-0.0.1a0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "19800c5f6b416860406ea3b7e04e3c93",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 20341,
"upload_time": "2023-08-17T06:59:35",
"upload_time_iso_8601": "2023-08-17T06:59:35.272180Z",
"url": "https://files.pythonhosted.org/packages/27/6b/97540bfd4f1ad578cce3612a4491f62bf96abcb15348eeee4fed1500a0b3/gpt_forward-0.0.1a0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "556ed9e50e45c57904c7db7af3c16fd5b668b210b81e6b619ae8ac266a5ca3fa",
"md5": "c33d43c6349c3d92d619db881a5b7ed7",
"sha256": "2d42a10f98a90005ea45add0f0dbae362224c864c7d8898b529289d65bd2e648"
},
"downloads": -1,
"filename": "gpt_forward-0.0.1a0.tar.gz",
"has_sig": false,
"md5_digest": "c33d43c6349c3d92d619db881a5b7ed7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 16729,
"upload_time": "2023-08-17T06:59:37",
"upload_time_iso_8601": "2023-08-17T06:59:37.110381Z",
"url": "https://files.pythonhosted.org/packages/55/6e/d9e50e45c57904c7db7af3c16fd5b668b210b81e6b619ae8ac266a5ca3fa/gpt_forward-0.0.1a0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-17 06:59:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "beidongjiedeguang",
"github_project": "openai-forward#openai-forward",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "loguru",
"specs": []
},
{
"name": "fastapi",
"specs": [
[
">=",
"0.94.0"
]
]
},
{
"name": "uvicorn",
"specs": [
[
">=",
"0.21.0"
]
]
},
{
"name": "orjson",
"specs": []
},
{
"name": "python-dotenv",
"specs": []
},
{
"name": "httpx",
"specs": [
[
">=",
"0.24.1"
]
]
},
{
"name": "rich",
"specs": []
},
{
"name": "fire",
"specs": []
},
{
"name": "pytz",
"specs": []
}
],
"lcname": "gpt-forward"
}