AgentGPT icon indicating copy to clipboard operation
AgentGPT copied to clipboard

Is it possible to set proxy when connecting OpenAI's API

Open fubuki8087 opened this issue 1 year ago • 4 comments

Due to Internet restriction in my region, I cannot connect OpenAI directly. Usually I use proxy to solve this problem, but I don't know how to set proxy for AgentGPT. I tried to set environment variables HTTP_PROXY and HTTP_PROXYS in docker container but failed. Is there any way to solve this problem?

fubuki8087 avatar Apr 16 '23 08:04 fubuki8087

Hi @fubuki8087, to set proxy for AgentGPT, you can try the following steps:

  1. Set the environment variables HTTP_PROXY and HTTPS_PROXY with your proxy server details in the docker container. You can do this by running the following command:
docker run -e HTTP_PROXY=<proxy-server-address> -e HTTPS_PROXY=<proxy-server-address> <image-name>

Replace <proxy-server-address> with the address of your proxy server and <image-name> with the name of the AgentGPT docker image.

  1. If setting the environment variables doesn't work, you can also try configuring the proxy settings in your code. You can do this by adding the following code to the beginning of your Python script:
import os
os.environ['HTTP_PROXY'] = '<proxy-server-address>'
os.environ['HTTPS_PROXY'] = '<proxy-server-address>'

Replace <proxy-server-address> with the address of your proxy server.

Let me know if this helps solve your problem.

hemangjoshi37a avatar Apr 16 '23 12:04 hemangjoshi37a

you can test proxychains in ubuntu,,https://github.com/search?q=proxychains

rat857 avatar Apr 16 '23 12:04 rat857

ok thanks

hemangjoshi37a avatar Apr 16 '23 12:04 hemangjoshi37a

Hi @fubuki8087, to set proxy for AgentGPT, you can try the following steps:

  1. Set the environment variables HTTP_PROXY and HTTPS_PROXY with your proxy server details in the docker container. You can do this by running the following command:
docker run -e HTTP_PROXY=<proxy-server-address> -e HTTPS_PROXY=<proxy-server-address> <image-name>

Replace <proxy-server-address> with the address of your proxy server and <image-name> with the name of the AgentGPT docker image.

  1. If setting the environment variables doesn't work, you can also try configuring the proxy settings in your code. You can do this by adding the following code to the beginning of your Python script:
import os
os.environ['HTTP_PROXY'] = '<proxy-server-address>'
os.environ['HTTPS_PROXY'] = '<proxy-server-address>'

Replace <proxy-server-address> with the address of your proxy server.

Let me know if this helps solve your problem.

For your first step, I've tried it but it's not work for me. I used Wireshark to observe that the packet was not proxied. Instead, it was directly transmitted to OpenAI API server.

For the second step, I don't know how to change the code. I don't see any code in AgentGPT is written in Python. Could you be more specific?

fubuki8087 avatar Apr 16 '23 15:04 fubuki8087

Added support for custom base url for local development: https://github.com/reworkd/AgentGPT/pull/543

Simply run setup.sh to create your .env file properly, and then update the openai base url env. We'll have some better docs for this in the future

@fubuki8087 @rat857 @hemangjoshi37a

Closing!

asim-shrestha avatar Jun 05 '23 01:06 asim-shrestha

If you're facing issues making OpenAI API calls with a proxy server, setting the proxy configuration explicitly using the openai.proxy attribute might help.

Here's an example of how you can set the proxy using environment variables:

import os
import openai
openai.proxy = {
    "http": os.environ.get('http_proxy', ''),
    "https": os.environ.get('https_proxy', '')
}

This is assuming you already have proxy settings set in your environment.

asimadnan avatar Dec 07 '23 22:12 asimadnan

If you're facing issues making OpenAI API calls with a proxy server, setting the proxy configuration explicitly using the openai.proxy attribute might help.

Here's an example of how you can set the proxy using environment variables:

import os
import openai
openai.proxy = {
    "http": os.environ.get('http_proxy', ''),
    "https": os.environ.get('https_proxy', '')
}

This is assuming you already have proxy settings set in your environment.

You can try add the HTTP_PROXY and HTTPS_PROXY in ./docker-compose.yml You might have to add all three of them

Paper-blue avatar Dec 09 '23 11:12 Paper-blue