mirror of
https://github.com/Chanzhaoyu/chatgpt-web.git
synced 2025-10-17 16:45:23 +00:00
Add support for SOCKS proxy in ChatGPTAPI fetch (#214)
This commit is contained in:

committed by
GitHub

parent
f19998d59b
commit
20d6135658
@@ -27,8 +27,17 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
|
|||||||
apiKey: process.env.OPENAI_API_KEY,
|
apiKey: process.env.OPENAI_API_KEY,
|
||||||
debug: false,
|
debug: false,
|
||||||
}
|
}
|
||||||
|
let fetchFn
|
||||||
api = new ChatGPTAPI({ ...options })
|
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'
|
apiModel = 'ChatGPTAPI'
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Reference in New Issue
Block a user