mirror of
https://github.com/jackhh66/ChatGPT_Web_accessToken.git
synced 2026-12-03 21:59:33 +00:00
Add support for SOCKS proxy in ChatGPTAPI fetch (#214)
This commit is contained in:
1 parent
f19998d59b
commit
20d6135658
1 file changed
+11
-2
@@ -27,8 +27,17 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
debug: false,
|
||||
}
|
||||
|
||||
api = new ChatGPTAPI({ ...options })
|
||||
let fetchFn
|
||||
if (process.env.SOCKS_PROXY_HOST && process.env.SOCKS_PROXY_PORT) {
|
||||
const agent = new SocksProxyAgent({
|
||||
hostname: process.env.SOCKS_PROXY_HOST,
|
||||
port: process.env.SOCKS_PROXY_PORT,
|
||||
})
|
||||
fetchFn = (url, options) => {
|
||||
return fetch(url, { agent, ...options })
|
||||
}
|
||||
}
|
||||
api = new ChatGPTAPI({ ...options, fetch: fetchFn })
|
||||
apiModel = 'ChatGPTAPI'
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in new issue
Block a user