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

可以用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!"}]
}'
我之前也遇到过,在宿主机上搭的代理
先确认一下容器内能访问到代理
查看宿主机ip: ip addr show docker0,容器内ping一下
如果不行, docker-compose文件指定一下 network_mode: bridge
我之前也遇到过,在宿主机上搭的代理
先确认一下容器内能访问到代理
查看宿主机ip: ip addr show docker0,容器内ping一下
如果不行, docker-compose文件指定一下 network_mode: bridge
容器内可以ping通代理
谢谢,我看下
貌似是docker缓存的锅,谢谢大家