├── open-proxy.zip ├── package.json ├── app.js └── README.md /open-proxy.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProbiusOfficial/openai-proxy/HEAD/open-proxy.zip -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "origin", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "node ./bin/www" 7 | }, 8 | "dependencies": { 9 | "cookie-parser": "~1.4.4", 10 | "debug": "~2.6.9", 11 | "express": "~4.16.1", 12 | "http-errors": "~1.6.3", 13 | "jade": "~1.11.0", 14 | "morgan": "~1.9.1", 15 | "http-proxy-middleware": "^2.0.6" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const { createProxyMiddleware } = require('http-proxy-middleware'); 3 | const app = express(); 4 | const port = 9000; 5 | 6 | app.get('/ok', (req, res) => { 7 | res.send('Proxy service is running properly!'); 8 | }); 9 | 10 | const openaiApiProxy = createProxyMiddleware('/', { 11 | target: 'https://api.openai.com', 12 | changeOrigin: true, 13 | pathRewrite: { 14 | '^/': '', 15 | }, 16 | }); 17 | 18 | app.use(openaiApiProxy); 19 | 20 | 21 | app.listen(port, () => { 22 | console.log(`Example app listening at http://localhost:${port}`); 23 | }); 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # openai-proxy 2 | 使用腾讯云函数将Openai的API偷渡到国内x 3 | 4 | 跟随下面的文档进行搭建 / 或者直接上传封装好的代码包即可x 5 | 6 | ### 如何部署 7 | 8 | 在腾讯云中打开云函数列表:https://console.cloud.tencent.com/scf/list 9 | 10 | 新建一个云函数,选择**从头开始**,类型为**Web函数**,**Nodejs**版本选择**16.13**如图: 11 | 12 | ![](https://fastly.jsdelivr.net/gh/ProbiusOfficial/My_pic@main/2023y-3m-24-d11-h26m1679628401679.png) 13 | 14 | 地区选择内陆地区以外的地区: 15 | 16 | ![](https://fastly.jsdelivr.net/gh/ProbiusOfficial/My_pic@main/2023y-3m-24-d11-h26m1679628416310.png) 17 | 18 | 注意超时时间的阈值高一点: 19 | 20 | ![](https://fastly.jsdelivr.net/gh/ProbiusOfficial/My_pic@main/2023y-3m-24-d11-h27m1679628434367.png) 21 | 22 | 启用多并发: 23 | 24 | ![](https://fastly.jsdelivr.net/gh/ProbiusOfficial/My_pic@main/2023y-3m-24-d11-h27m1679628449061.png) 25 | 26 | 配置API触发器: 27 | 28 | ![](https://fastly.jsdelivr.net/gh/ProbiusOfficial/My_pic@main/2023y-3m-24-d11-h27m1679628459018.png) 29 | 30 | 点击完成 31 | 32 | ![](https://fastly.jsdelivr.net/gh/ProbiusOfficial/My_pic@main/2023y-3m-24-d11-h27m1679628472034.png) 33 | 34 | 等待一段时间 来到**函数管理**选中**函数代码**,将[app.js](https://github.com/ProbiusOfficial/openai-proxy/blob/main/app.js) 和 [package.json](https://github.com/ProbiusOfficial/openai-proxy/blob/main/package.json) 替换为下面内容: 35 | 36 | ```JavaScript 37 | const express = require('express'); 38 | const { createProxyMiddleware } = require('http-proxy-middleware'); 39 | const app = express(); 40 | const port = 9000; 41 | 42 | app.get('/ok', (req, res) => { 43 | res.send('Proxy service is running properly!'); 44 | }); 45 | 46 | const openaiApiProxy = createProxyMiddleware('/', { 47 | target: 'https://api.openai.com', 48 | changeOrigin: true, 49 | pathRewrite: { 50 | '^/': '', 51 | }, 52 | }); 53 | 54 | app.use(openaiApiProxy); 55 | 56 | app.listen(port, () => { 57 | console.log(`Example app listening at http://localhost:${port}`); 58 | }); 59 | 60 | ``` 61 | 62 | ```json 63 | { 64 | "name": "origin", 65 | "version": "0.0.0", 66 | "private": true, 67 | "scripts": { 68 | "start": "node ./bin/www" 69 | }, 70 | "dependencies": { 71 | "cookie-parser": "~1.4.4", 72 | "debug": "~2.6.9", 73 | "express": "~4.16.1", 74 | "http-errors": "~1.6.3", 75 | "jade": "~1.11.0", 76 | "morgan": "~1.9.1", 77 | "http-proxy-middleware": "^2.0.6" 78 | } 79 | } 80 | ``` 81 | 82 | 83 | 84 | ![](https://fastly.jsdelivr.net/gh/ProbiusOfficial/My_pic@main/2023y-3m-24-d11-h28m1679628483083.png) 85 | 86 | 在部署处下拉,选择**自动配置依赖** 87 | 88 | ![](https://fastly.jsdelivr.net/gh/ProbiusOfficial/My_pic@main/2023y-3m-24-d11-h28m1679628497091.png) 89 | 90 | 最后点击部署即可。 91 | 92 | 访问url/ok返回时,说明部署成功: 93 | 94 | ![](https://fastly.jsdelivr.net/gh/ProbiusOfficial/My_pic@main/2023y-3m-24-d11-h28m1679628512018.png) 95 | 96 | 而云函数的访问路径即可用于替换OpenAi的API地址https://api.openai.com 97 | 98 | (/release可以加也可以不加,你也可以在API网关里面进一步设置,使用自己的域名) 99 | 100 | ### 如何使用 101 | 102 | 云函数的访问路径即可用于替换OpenAi的API地址https://api.openai.com 103 | 104 | 比如在 OpenAi Translator中 将云函数的url替换原本的openai url即可,亦或 105 | 106 | ### 效果预览 107 | 108 | ![](https://fastly.jsdelivr.net/gh/ProbiusOfficial/My_pic@main/2023y-3m-24-d11-h28m1679628525708.png) 109 | 110 | ![](https://fastly.jsdelivr.net/gh/ProbiusOfficial/My_pic@main/2023y-3m-24-d11-h29m1679628586588.png) 111 | 112 | ![](https://fastly.jsdelivr.net/gh/ProbiusOfficial/My_pic@main/2023y-3m-24-d11-h29m1679628597249.png) 113 | 114 | ![](https://fastly.jsdelivr.net/gh/ProbiusOfficial/My_pic@main/2023y-3m-24-d11-h30m1679628613797.png) 115 | 116 | ![](https://fastly.jsdelivr.net/gh/ProbiusOfficial/My_pic@main/2023y-3m-24-d11-h31m1679628672187.png) 117 | 118 | ### 其他 119 | 120 | 感谢文档:https://cloud.tencent.com/document/product/583/37920 121 | 122 | 本项目代码所用代码由GPT强力驱动生成(x 123 | 124 | ![](https://fastly.jsdelivr.net/gh/ProbiusOfficial/My_pic@main/2023y-3m-24-d11-h31m1679628687662.png) 125 | --------------------------------------------------------------------------------