The OpenAI Python client doesn't directly support proxy configuration. You'll need to use the requests library to configure the proxy.
The base_url parameter is not intended for proxy settings. It's typically used to set a different API endpoint (if OpenAI provides alternative endpoints in the future).
You are using an HTTP proxy (http://) for HTTPS requests. Ensure that your proxy supports HTTPS traffic.
Here's an example of how you can modify your code to use a proxy with the OpenAI API using requests:
import config
import openai
import requests
from requests.auth import HTTPProxyAuth
# Configure your proxy
proxy = "http://95.164.128.235:9943"
proxy_auth = HTTPProxyAuth('M0k0EN', 'ZSNkKy')
# Configure a session to use the proxy
session = requests.Session()
session.proxies = {'http': proxy, 'https': proxy}
session.auth = proxy_auth
# Tell OpenAI to use this session
openai.api_base = 'https://api.openai.com/v1'
openai.organization = 'your-organization-id' # if you have an organization ID
openai.api_key = config.api_key
openai.session = session
try:
response = openai.Completion.create(
model="gpt-3.5-turbo-instruct",
prompt="Say this is a test",
max_tokens=7,
temperature=0
)
print(response.choices[0].text)
except Exception as e:
print(f"Error: {e}")