Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: fetch failed (can't connect to OpenAI Api) #34

Closed
sannyii opened this issue Mar 3, 2023 · 11 comments
Closed

TypeError: fetch failed (can't connect to OpenAI Api) #34

sannyii opened this issue Mar 3, 2023 · 11 comments
Labels
question Further information is requested

Comments

@sannyii
Copy link

sannyii commented Mar 3, 2023

加了key以后,一直connect error的错误。求救。。。

@sannyii
Copy link
Author

sannyii commented Mar 3, 2023

状态码 500

@blkcor
Copy link

blkcor commented Mar 3, 2023

我也
https://api.openai.com/v1/chat/completions这个接口fetch不到
.env配置了HTTPS_PROXY为我的clash

@ddiu8081
Copy link
Member

ddiu8081 commented Mar 3, 2023

clash的话,可以先开启增强模式;HTTPS_PROXY 参数还没在这个 repo 实装

@mango2017
Copy link

error fetch failed
应该怎么改啊

@DanielFu12
Copy link

同样报错,有大神指导一下吗

@x-dr
Copy link

x-dr commented Mar 3, 2023

用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
Copy link
Member

ddiu8081 commented Mar 4, 2023

HTTPS_PROXY 已经支持,本地运行可配置一个 HTTP 代理。

@ddiu8081 ddiu8081 closed this as completed Mar 4, 2023
@ddiu8081 ddiu8081 changed the title 报错 Proxy error (can't connect to OpenAI Api) Mar 4, 2023
This was referenced Mar 4, 2023
@ddiu8081 ddiu8081 added the question Further information is requested label Mar 6, 2023
@ddiu8081 ddiu8081 changed the title Proxy error (can't connect to OpenAI Api) TypeError: fetch failed (can't connect to OpenAI Api) Mar 6, 2023
@ddiu8081 ddiu8081 pinned this issue Mar 6, 2023
@honestyallan
Copy link

部署到google云,访问api/generate接口, 报500异常

@xuyudong
Copy link

用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
Copy link

ronalzhang commented Mar 11, 2023

大哥给看看我这个是什么原因啊~
{
"errno": -61,
"code": "ECONNREFUSED",
"syscall": "connect",
"address": "127.0.0.1",
"port": 3000
}

@ddiu8081 ddiu8081 unpinned this issue Mar 11, 2023
@vaynevayne
Copy link

clash是装在个人电脑里, 做代理的话岂不是只有局域网内的才能代理? 没太理解clash代理,求科普

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

10 participants