chatgpt-web
chatgpt-web copied to clipboard
为APi添加代理
昨天下午开始,api的域名被墙,希望能支持代理
建议支持SOCKS5代理。
目前可以自己加一下,我这边已经可以用了:
1.安装https-proxy-agent
npm install https-proxy-agent
2.在service/arc.chatgpt.ts下修改
引入https-proxy-agent
import { HttpsProxyAgent } from 'https-proxy-agent'
然后找到new ChatGPTAPI那一行,按如下修改:
api = new ChatGPTAPI({
...options,
fetch: (url, options = {}) => {
const defaultOptions = {
agent: new HttpsProxyAgent({your proxy}),
}
const mergedOptions = {
...defaultOptions,
...options,
}
return fetch(url, mergedOptions)
},
+1 现在api都是fetch failed
目前可以自己加一下,我这边已经可以用了: 1.安装https-proxy-agent
npm install https-proxy-agent
2.在service/arc.chatgpt.ts下修改 引入https-proxy-agentimport { HttpsProxyAgent } from 'https-proxy-agent'
然后找到new ChatGPTAPI那一行,按如下修改:api = new ChatGPTAPI({ ...options, fetch: (url, options = {}) => { const defaultOptions = { agent: new HttpsProxyAgent({your proxy}), } const mergedOptions = { ...defaultOptions, ...options, } return fetch(url, mergedOptions) },
结果:
目前可以自己加一下,我这边已经可以用了: 1.安装https-proxy-agent
npm install https-proxy-agent
2.在service/arc.chatgpt.ts下修改 引入https-proxy-agentimport { HttpsProxyAgent } from 'https-proxy-agent'
然后找到new ChatGPTAPI那一行,按如下修改:api = new ChatGPTAPI({ ...options, fetch: (url, options = {}) => { const defaultOptions = { agent: new HttpsProxyAgent({your proxy}), } const mergedOptions = { ...defaultOptions, ...options, } return fetch(url, mergedOptions) },
我把下面的代码复制上来,通过在
.env
定义SOCKS_PROXY_HOST
和SOCKS_PROXY_PORT
来解决问题。这个代码原本就在,只是不知道为什么readme没有提到。
这段代码原本就在下面:
https://github.com/Chanzhaoyu/chatgpt-web/blob/f19998d59bd048923ddde2d9ff5272ce7dc8e6fe/service/src/chatgpt/index.ts#L40-L48
#214 在
/service/.env
文件里配置SOCKS_PROXY_HOST
和SOCKS_PROXY_PORT
就好了
不对的,如果是用的api模式,即使配置了这2个,也不会走代理的
不对的,如果是用的api模式,即使配置了这2个,也不会走代理的
就像我提到的,你需要复制你框住的那段代码到上面才可以
几十分钟前 merge 了对 API 方式提供代理代码
是的,我也看见了,其实就是把那段代码拿到上面来了,所以就可以使用了。
@CKylinMC 这样设置也不太行啊


@CKylinMC 这样设置也不太行啊
3002?这里不是写后端服务端口,而是你的proxy的端口。因为这是OpenAI的锁区,你需要一个代理,这里填写的是SOCKS代理服务的地址和端口。
目前可以自己加一下,我这边已经可以用了: 1.安装https-proxy-agent
npm install https-proxy-agent
2.在service/arc.chatgpt.ts下修改 引入https-proxy-agentimport { HttpsProxyAgent } from 'https-proxy-agent'
然后找到new ChatGPTAPI那一行,按如下修改:api = new ChatGPTAPI({ ...options, fetch: (url, options = {}) => { const defaultOptions = { agent: new HttpsProxyAgent({your proxy}), } const mergedOptions = { ...defaultOptions, ...options, } return fetch(url, mergedOptions) },
Thanks @ws1993 , I just want to correct your code to be able to copy and use :
api = new ChatGPTAPI({
...options, // Spread operator to include any additional options provided to ChatGPTAPI constructor
fetch: (url, options = {}) => {
const defaultOptions = {
agent: new HttpsProxyAgent({host: 'IP', port: 3128}), // Update to pass proxy server information correctly
}
const mergedOptions = {
...defaultOptions,
...options, // Spread operator to override defaultOptions with any options provided to the fetch function
}
return fetch(url, mergedOptions) // Return fetch function with merged options
},
})
I can use squid proxy with above code !
有人时常遇到接口503报错吗
有共享的代理吗?没有海外服务器啊