chatgpt-web icon indicating copy to clipboard operation
chatgpt-web copied to clipboard

提示代理超时,用其他机器测试代理正常

Open bjznl opened this issue 2 years ago • 1 comments

我用docker-compose拉取了2.9.3,使用ChatGPTAPI,配置了socks代理。发送消息提示request to https://api.openai.com//v1/chat/completions failed, reason: Proxy connection timed out ,通过几个电脑还有手机测试这个代理,均能正常使用,被这个问题搞疯了,请问有什么办法能解决吗? image image

bjznl avatar Mar 07 '23 08:03 bjznl

可以用cf_worker反代apenai api 替换掉https://api.openai.com

我自建了一个https://openai.1rmb.tk

20230308000018

自建教程

代码
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!"}]
 }'

x-dr avatar Mar 07 '23 15:03 x-dr

我之前也遇到过,在宿主机上搭的代理

先确认一下容器内能访问到代理

查看宿主机ip: ip addr show docker0,容器内ping一下

如果不行, docker-compose文件指定一下 network_mode: bridge

yuntao1997 avatar Mar 08 '23 00:03 yuntao1997

我之前也遇到过,在宿主机上搭的代理

先确认一下容器内能访问到代理

查看宿主机ip: ip addr show docker0,容器内ping一下

如果不行, docker-compose文件指定一下 network_mode: bridge

容器内可以ping通代理

bjznl avatar Mar 08 '23 00:03 bjznl

谢谢,我看下

bjznl avatar Mar 08 '23 00:03 bjznl

貌似是docker缓存的锅,谢谢大家

bjznl avatar Mar 08 '23 02:03 bjznl