Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plz add 'proxy' option for configuration #85

Closed
zhongkai opened this issue Mar 3, 2023 · 5 comments
Closed

Plz add 'proxy' option for configuration #85

zhongkai opened this issue Mar 3, 2023 · 5 comments
Labels
fixed in v4 Issues addressed by v4

Comments

@zhongkai
Copy link

zhongkai commented Mar 3, 2023

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

@brooklynb7
Copy link

brooklynb7 commented Mar 4, 2023

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')
    }
  )

@xmenbe
Copy link

xmenbe commented Mar 4, 2023

There is no reliable mainland agent recommended

@xueelf
Copy link

xueelf commented Mar 21, 2023

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);

@little-spider-cyber
Copy link

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! 解决了我一个多小时的问题。

@rattrayalex
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in v4 Issues addressed by v4
Projects
None yet
Development

No branches or pull requests

7 participants