admin管理员组文章数量:1530013
✈ChatGPT的API接口为 https://api.openai 但是很多小伙伴不是国家区域不对,就试没有一个好的代理,经常chatgpt出现无法聊天的情况,那么自己搭建一个代理服务器那不是很香?还是免费的,直接整起来!图文教程,无缝链接!
教程
1.首先注册并且登录cloudflare
https://www.cloudflare/zh-cn/
2. 打开Workers和Pages,并且创建应用程序
创建Worker
部署程序
3. 编辑代码:
编辑代码:
const TELEGRAPH_URL = 'https://api.openai';
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const url = new URL(request.url);
const headers_Origin = request.headers.get("Access-Control-Allow-Origin") || "*"
url.host = TELEGRAPH_URL.replace(/^https?:\/\//, '');
const modifiedRequest = new Request(url.toString(), {
headers: request.headers,
method: request.method,
body: request.body,
redirect: 'follow'
});
const response = await fetch(modifiedRequest);
const modifiedResponse = new Response(response.body, response);
// 添加允许跨域访问的响应头
modifiedResponse.headers.set('Access-Control-Allow-Origin', headers_Origin);
return modifiedResponse;
}
基本部署完成
1. 测试连接
https://你自定义的项目名.workers.dev/v1/chat/completions
2. 成功示例
{
"error": {
"message": "You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai/account/api-keys.",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
上面的基本就算部署成功了,但是你还需要部署你自己的域名来访问,成为你自己专属的第一无二的api接口,所以你还需要绑定域名。
部署域名
1. 点开触发器
添加自定义域
2. 输入自定义域名
输入你在Cloudflare托管的域名,自定义一个未使用的二级域名地址,并点添加自定义域
3. 最终成品
本文标签: 代理服务器傻瓜教程CloudFlarechatGPT
版权声明:本文标题:利用Cloudflare搭建ChatGPT API 代理服务器 傻瓜教程 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1726695527a1081078.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论