openai-node
openai-node copied to clipboard
Plz add 'proxy' option for configuration
Describe the feature or improvement you're requesting
I want to break through some firewalls to access the openai api, but I don't want to affect the access speed of other services. In addition to customizing proxy rules for openai domain names, the best way is to support the configuration of request proxies, which will facilitate the overall configuration.
Additional context
No response
Since the axios is used for requesting, you can try the following, the second param is the axios configuration (I have changed the solution from proxy => httpsAgent as proxy seems not working well in axios):
import HttpsProxyAgent from 'https-proxy-agent'
const rst = await openai.createChatCompletion(
{
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: 'Hello!' }]
},
{
proxy: false,
httpAgent: HttpsProxyAgent('http://proxy-host:proxy-port'),
httpsAgent: HttpsProxyAgent('http://proxy-host:proxy-port')
}
)
There is no reliable mainland agent recommended
Maybe you not need proxy configuration option (。・∀・)ノ゙
I also had a need to use proxy, found a basePath
configuration option by looking up the source code.
import { Configuration, OpenAIApi } from 'openai';
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
basePath: `https://${process.env.OPENAI_PROXY_URL}/v1`
});
const openai = new OpenAIApi(configuration);
Since the axios is used for requesting, you can try the following, the second param is the axios configuration (I have changed the solution from proxy => httpsAgent as proxy seems not working well in axios):
import HttpsProxyAgent from 'https-proxy-agent' const rst = await openai.createChatCompletion( { model: 'gpt-3.5-turbo', messages: [{ role: 'user', content: 'Hello!' }] }, { proxy: false, httpAgent: HttpsProxyAgent('http://proxy-host:proxy-port'), httpsAgent: HttpsProxyAgent('http://proxy-host:proxy-port') } )
I love you sooooooooooooooooooooo much! 解决了我一个多小时的问题。
Our upcoming v4 also has support for proxies, as documented here: https://github.com/openai/openai-node/tree/v4#configuring-an-https-agent-eg-for-proxies