bibibi12345 commited on
Commit
1ebdf9a
·
1 Parent(s): f38237b

made proxy cleaner

Browse files
app/config.py CHANGED
@@ -41,6 +41,5 @@ SAFETY_SCORE = os.environ.get("SAFETY_SCORE", "false").lower() == "true"
41
  # Validation logic moved to app/auth.py
42
 
43
  # Proxy settings
44
- HTTPS_PROXY = os.environ.get("HTTPS_PROXY")
45
- SOCKS_PROXY = os.environ.get("SOCKS_PROXY")
46
  SSL_CERT_FILE = os.environ.get("SSL_CERT_FILE")
 
41
  # Validation logic moved to app/auth.py
42
 
43
  # Proxy settings
44
+ PROXY_URL = os.environ.get("PROXY_URL")
 
45
  SSL_CERT_FILE = os.environ.get("SSL_CERT_FILE")
app/openai_handler.py CHANGED
@@ -81,10 +81,11 @@ class ExpressClientWrapper:
81
  payload.update(payload.pop('extra_body'))
82
 
83
  proxies = None
84
- if app_config.SOCKS_PROXY:
85
- proxies = {"all://": app_config.SOCKS_PROXY}
86
- elif app_config.HTTPS_PROXY:
87
- proxies = {"https://": app_config.HTTPS_PROXY}
 
88
 
89
  client_args = {'timeout': 300}
90
  if proxies:
@@ -118,10 +119,11 @@ class ExpressClientWrapper:
118
  payload.update(payload.pop('extra_body'))
119
 
120
  proxies = None
121
- if app_config.SOCKS_PROXY:
122
- proxies = {"all://": app_config.SOCKS_PROXY}
123
- elif app_config.HTTPS_PROXY:
124
- proxies = {"https://": app_config.HTTPS_PROXY}
 
125
 
126
  client_args = {'timeout': 300}
127
  if proxies:
@@ -157,10 +159,11 @@ class OpenAIDirectHandler:
157
  )
158
 
159
  proxies = None
160
- if app_config.SOCKS_PROXY:
161
- proxies = {"all://": app_config.SOCKS_PROXY}
162
- elif app_config.HTTPS_PROXY:
163
- proxies = {"https://": app_config.HTTPS_PROXY}
 
164
 
165
  client_args = {}
166
  if proxies:
 
81
  payload.update(payload.pop('extra_body'))
82
 
83
  proxies = None
84
+ if app_config.PROXY_URL:
85
+ if app_config.PROXY_URL.startswith("socks"):
86
+ proxies = {"all://": app_config.PROXY_URL}
87
+ else:
88
+ proxies = {"https://": app_config.PROXY_URL}
89
 
90
  client_args = {'timeout': 300}
91
  if proxies:
 
119
  payload.update(payload.pop('extra_body'))
120
 
121
  proxies = None
122
+ if app_config.PROXY_URL:
123
+ if app_config.PROXY_URL.startswith("socks"):
124
+ proxies = {"all://": app_config.PROXY_URL}
125
+ else:
126
+ proxies = {"https://": app_config.PROXY_URL}
127
 
128
  client_args = {'timeout': 300}
129
  if proxies:
 
159
  )
160
 
161
  proxies = None
162
+ if app_config.PROXY_URL:
163
+ if app_config.PROXY_URL.startswith("socks"):
164
+ proxies = {"all://": app_config.PROXY_URL}
165
+ else:
166
+ proxies = {"https://": app_config.PROXY_URL}
167
 
168
  client_args = {}
169
  if proxies:
app/project_id_discovery.py CHANGED
@@ -10,11 +10,7 @@ PROJECT_ID_CACHE: Dict[str, str] = {}
10
 
11
  def _get_proxy_url() -> Optional[str]:
12
  """Get proxy URL from config."""
13
- if config.SOCKS_PROXY:
14
- return config.SOCKS_PROXY
15
- if config.HTTPS_PROXY:
16
- return config.HTTPS_PROXY
17
- return None
18
 
19
 
20
  async def discover_project_id(api_key: str) -> str:
 
10
 
11
  def _get_proxy_url() -> Optional[str]:
12
  """Get proxy URL from config."""
13
+ return config.PROXY_URL
 
 
 
 
14
 
15
 
16
  async def discover_project_id(api_key: str) -> str:
app/vertex_ai_init.py CHANGED
@@ -14,10 +14,10 @@ from model_loader import refresh_models_config_cache # Import new model loader f
14
 
15
  def _get_http_options() -> Optional[types.HttpOptions]:
16
  """Get http options from config."""
17
- if app_config.SOCKS_PROXY:
18
  return types.HttpOptions(
19
- client_args={'proxy': app_config.SOCKS_PROXY},
20
- async_client_args={'proxy': app_config.SOCKS_PROXY},
21
  )
22
  return None
23
 
 
14
 
15
  def _get_http_options() -> Optional[types.HttpOptions]:
16
  """Get http options from config."""
17
+ if app_config.PROXY_URL and app_config.PROXY_URL.startswith("socks"):
18
  return types.HttpOptions(
19
+ client_args={'proxy': app_config.PROXY_URL},
20
+ async_client_args={'proxy': app_config.PROXY_URL},
21
  )
22
  return None
23