https://github.com/probiusofficial/openai-proxy
使用腾讯云函数将Openai的API偷渡到国内x
https://github.com/probiusofficial/openai-proxy
Last synced: about 1 year ago
JSON representation
使用腾讯云函数将Openai的API偷渡到国内x
- Host: GitHub
- URL: https://github.com/probiusofficial/openai-proxy
- Owner: ProbiusOfficial
- Created: 2023-03-23T15:12:51.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-24T03:50:18.000Z (over 3 years ago)
- Last Synced: 2025-03-29T11:51:43.607Z (over 1 year ago)
- Language: JavaScript
- Size: 2.62 MB
- Stars: 22
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# openai-proxy
使用腾讯云函数将Openai的API偷渡到国内x
跟随下面的文档进行搭建 / 或者直接上传封装好的代码包即可x
### 如何部署
在腾讯云中打开云函数列表:https://console.cloud.tencent.com/scf/list
新建一个云函数,选择**从头开始**,类型为**Web函数**,**Nodejs**版本选择**16.13**如图:

地区选择内陆地区以外的地区:

注意超时时间的阈值高一点:

启用多并发:

配置API触发器:

点击完成

等待一段时间 来到**函数管理**选中**函数代码**,将[app.js](https://github.com/ProbiusOfficial/openai-proxy/blob/main/app.js) 和 [package.json](https://github.com/ProbiusOfficial/openai-proxy/blob/main/package.json) 替换为下面内容:
```JavaScript
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const app = express();
const port = 9000;
app.get('/ok', (req, res) => {
res.send('Proxy service is running properly!');
});
const openaiApiProxy = createProxyMiddleware('/', {
target: 'https://api.openai.com',
changeOrigin: true,
pathRewrite: {
'^/': '',
},
});
app.use(openaiApiProxy);
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
```
```json
{
"name": "origin",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"express": "~4.16.1",
"http-errors": "~1.6.3",
"jade": "~1.11.0",
"morgan": "~1.9.1",
"http-proxy-middleware": "^2.0.6"
}
}
```

在部署处下拉,选择**自动配置依赖**

最后点击部署即可。
访问url/ok返回时,说明部署成功:

而云函数的访问路径即可用于替换OpenAi的API地址https://api.openai.com
(/release可以加也可以不加,你也可以在API网关里面进一步设置,使用自己的域名)
### 如何使用
云函数的访问路径即可用于替换OpenAi的API地址https://api.openai.com
比如在 OpenAi Translator中 将云函数的url替换原本的openai url即可,亦或
### 效果预览





### 其他
感谢文档:https://cloud.tencent.com/document/product/583/37920
本项目代码所用代码由GPT强力驱动生成(x
