Add support for SOCKS proxy in ChatGPTAPI fetch (#214)

This commit is contained in:
InterestingDarkness 2023-03-03 10:43:27 +08:00 committed by GitHub
parent f19998d59b
commit 20d6135658
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -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 {