TypeError: fetch failed (can't connect to OpenAI Api)
sannyii opened this issue · 11 comments
sannyii commented
加了key以后,一直connect error的错误。求救。。。
sannyii commented
状态码 500
blkcor commented
我也
https://api.openai.com/v1/chat/completions这个接口fetch不到
.env配置了HTTPS_PROXY为我的clash
ddiu8081 commented
clash的话,可以先开启增强模式;HTTPS_PROXY
参数还没在这个 repo 实装
mango2017 commented
error fetch failed
应该怎么改啊
DanielFu12 commented
同样报错,有大神指导一下吗
x-dr commented
用cf_worker反代apenai api 替换掉https://api.openai.com
我自建了一个https://openai.1rmb.tk
代码
const TELEGRAPH_URL = 'https://api.openai.com';
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const url = new URL(request.url);
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', '*');
return modifiedResponse;
}
使用
curl --location 'https://openai.1rmb.tk/v1/chat/completions' \
--header 'Authorization: Bearer sk-xxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}'
ddiu8081 commented
HTTPS_PROXY
已经支持,本地运行可配置一个 HTTP 代理。
honestyallan commented
部署到google云,访问api/generate接口, 报500异常
xuyudong commented
用cf_worker反代apenai api 替换掉https://api.openai.com 我自建了一个https://openai.1rmb.tk
代码
const TELEGRAPH_URL = 'https://api.openai.com'; addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)) }) async function handleRequest(request) { const url = new URL(request.url); 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', '*'); return modifiedResponse; }
使用
感谢,已成功
ronalzhang commented
大哥给看看我这个是什么原因啊~
{
"errno": -61,
"code": "ECONNREFUSED",
"syscall": "connect",
"address": "127.0.0.1",
"port": 3000
}
vaynevayne commented
clash是装在个人电脑里, 做代理的话岂不是只有局域网内的才能代理? 没太理解clash代理,求科普