bibibi12345 commited on
Commit
c863762
·
1 Parent(s): 6838d8b

added safety score. added proxy

Browse files
Dockerfile CHANGED
@@ -4,7 +4,7 @@ WORKDIR /app
4
 
5
  # Install dependencies
6
  COPY app/requirements.txt .
7
- RUN pip install --no-cache-dir -r requirements.txt
8
 
9
  # Copy application code
10
  COPY app/ .
 
4
 
5
  # Install dependencies
6
  COPY app/requirements.txt .
7
+ RUN pip cache purge && pip install --no-cache-dir -r requirements.txt
8
 
9
  # Copy application code
10
  COPY app/ .
app/api_helpers.py CHANGED
@@ -12,7 +12,7 @@ from openai import AsyncOpenAI
12
 
13
  from models import OpenAIRequest, OpenAIMessage
14
  from message_processing import (
15
- convert_to_openai_format,
16
  convert_chunk_to_openai,
17
  extract_reasoning_by_tags,
18
  _create_safety_ratings_html
 
12
 
13
  from models import OpenAIRequest, OpenAIMessage
14
  from message_processing import (
15
+ convert_to_openai_format,
16
  convert_chunk_to_openai,
17
  extract_reasoning_by_tags,
18
  _create_safety_ratings_html
app/message_processing.py CHANGED
@@ -5,7 +5,7 @@ import time
5
  import random # For more unique tool_call_id
6
  import urllib.parse
7
  from typing import List, Dict, Any, Tuple
8
- from app import config as app_config
9
 
10
  from google.genai import types
11
  from models import OpenAIMessage, ContentPartText, ContentPartImage
 
5
  import random # For more unique tool_call_id
6
  import urllib.parse
7
  from typing import List, Dict, Any, Tuple
8
+ import config as app_config
9
 
10
  from google.genai import types
11
  from models import OpenAIMessage, ContentPartText, ContentPartImage
app/openai_handler.py CHANGED
@@ -80,8 +80,15 @@ class ExpressClientWrapper:
80
  if 'extra_body' in payload:
81
  payload.update(payload.pop('extra_body'))
82
 
83
- proxy = app_config.SOCKS_PROXY or app_config.HTTPS_PROXY
84
- client_args = {'timeout': 300, 'proxies': proxy}
 
 
 
 
 
 
 
85
  if app_config.SSL_CERT_FILE:
86
  client_args['verify'] = app_config.SSL_CERT_FILE
87
  async with httpx.AsyncClient(**client_args) as client:
@@ -110,8 +117,15 @@ class ExpressClientWrapper:
110
  if 'extra_body' in payload:
111
  payload.update(payload.pop('extra_body'))
112
 
113
- proxy = app_config.SOCKS_PROXY or app_config.HTTPS_PROXY
114
- client_args = {'timeout': 300, 'proxies': proxy}
 
 
 
 
 
 
 
115
  if app_config.SSL_CERT_FILE:
116
  client_args['verify'] = app_config.SSL_CERT_FILE
117
  async with httpx.AsyncClient(**client_args) as client:
@@ -142,10 +156,15 @@ class OpenAIDirectHandler:
142
  f"projects/{project_id}/locations/{location}/endpoints/openapi"
143
  )
144
 
145
- proxy = app_config.SOCKS_PROXY or app_config.HTTPS_PROXY
 
 
 
 
 
146
  client_args = {}
147
- if proxy:
148
- client_args['proxies'] = proxy
149
  if app_config.SSL_CERT_FILE:
150
  client_args['verify'] = app_config.SSL_CERT_FILE
151
 
 
80
  if 'extra_body' in payload:
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:
91
+ client_args['proxies'] = proxies
92
  if app_config.SSL_CERT_FILE:
93
  client_args['verify'] = app_config.SSL_CERT_FILE
94
  async with httpx.AsyncClient(**client_args) as client:
 
117
  if 'extra_body' in payload:
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:
128
+ client_args['proxies'] = proxies
129
  if app_config.SSL_CERT_FILE:
130
  client_args['verify'] = app_config.SSL_CERT_FILE
131
  async with httpx.AsyncClient(**client_args) as client:
 
156
  f"projects/{project_id}/locations/{location}/endpoints/openapi"
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:
167
+ client_args['proxies'] = proxies
168
  if app_config.SSL_CERT_FILE:
169
  client_args['verify'] = app_config.SSL_CERT_FILE
170
 
app/project_id_discovery.py CHANGED
@@ -2,7 +2,7 @@ import aiohttp
2
  import json
3
  import re
4
  from typing import Dict, Optional
5
- from app import config
6
 
7
  # Global cache for project IDs: {api_key: project_id}
8
  PROJECT_ID_CACHE: Dict[str, str] = {}
 
2
  import json
3
  import re
4
  from typing import Dict, Optional
5
+ import config
6
 
7
  # Global cache for project IDs: {api_key: project_id}
8
  PROJECT_ID_CACHE: Dict[str, str] = {}