Spaces:
Paused
Paused
Commit ·
e98b99a
1
Parent(s): 8a2407c
debugging
Browse files
main.py
CHANGED
|
@@ -89,7 +89,6 @@ async def proxy(request: Request, model_path: str, api_key: str = Security(get_a
|
|
| 89 |
except json.JSONDecodeError:
|
| 90 |
pass # Not a json body, proxy as is
|
| 91 |
|
| 92 |
-
print(request_body_to_send)
|
| 93 |
|
| 94 |
target_url = f"https://aiplatform.googleapis.com/v1/projects/{project_id}/locations/global/publishers/google/models/{model_path}?key={express_key}"
|
| 95 |
|
|
@@ -121,11 +120,19 @@ async def proxy(request: Request, model_path: str, api_key: str = Security(get_a
|
|
| 121 |
else:
|
| 122 |
try:
|
| 123 |
response_data = await response.aread()
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
return Response(
|
| 126 |
-
content=
|
| 127 |
status_code=response.status_code,
|
| 128 |
-
headers=
|
| 129 |
)
|
| 130 |
finally:
|
| 131 |
await response.aclose()
|
|
|
|
| 89 |
except json.JSONDecodeError:
|
| 90 |
pass # Not a json body, proxy as is
|
| 91 |
|
|
|
|
| 92 |
|
| 93 |
target_url = f"https://aiplatform.googleapis.com/v1/projects/{project_id}/locations/global/publishers/google/models/{model_path}?key={express_key}"
|
| 94 |
|
|
|
|
| 120 |
else:
|
| 121 |
try:
|
| 122 |
response_data = await response.aread()
|
| 123 |
+
response_json = json.loads(response_data)
|
| 124 |
+
|
| 125 |
+
if 'candidates' in response_json:
|
| 126 |
+
for candidate in response_json.get('candidates', []):
|
| 127 |
+
if 'content' in candidate and 'parts' in candidate.get('content', {}):
|
| 128 |
+
candidate['content']['parts'] = [part for part in candidate['content']['parts'] if part]
|
| 129 |
+
|
| 130 |
+
modified_response_data = json.dumps(response_json).encode('utf-8')
|
| 131 |
+
|
| 132 |
return Response(
|
| 133 |
+
content=modified_response_data,
|
| 134 |
status_code=response.status_code,
|
| 135 |
+
headers=dict(response.headers),
|
| 136 |
)
|
| 137 |
finally:
|
| 138 |
await response.aclose()
|