AgentGPT
AgentGPT copied to clipboard
Is it possible to set proxy when connecting OpenAI's API
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?
Hi @fubuki8087, to set proxy for AgentGPT, you can try the following steps:
- 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.
- 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.
you can test proxychains in ubuntu,,https://github.com/search?q=proxychains
ok thanks
Hi @fubuki8087, to set proxy for AgentGPT, you can try the following steps:
- 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.
- 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?
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!
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.
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