Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,13 +41,11 @@ async def proxy(endpoint: str, request: Request):
|
|
| 41 |
content=body
|
| 42 |
)
|
| 43 |
|
| 44 |
-
# Фильтруем "hop-by-hop" заголовки из ответа
|
| 45 |
response_headers = {
|
| 46 |
k: v for k, v in resp_openai.headers.items()
|
| 47 |
if k.lower() not in HOP_BY_HOP_HEADERS
|
| 48 |
}
|
| 49 |
|
| 50 |
-
# Возвращаем полный ответ (статус, заголовки, тело) от OpenAI
|
| 51 |
return Response(
|
| 52 |
content=resp_openai.content,
|
| 53 |
status_code=resp_openai.status_code,
|
|
@@ -55,6 +53,12 @@ async def proxy(endpoint: str, request: Request):
|
|
| 55 |
)
|
| 56 |
|
| 57 |
except httpx.RequestError as e:
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
except Exception as e:
|
| 60 |
-
|
|
|
|
|
|
| 41 |
content=body
|
| 42 |
)
|
| 43 |
|
|
|
|
| 44 |
response_headers = {
|
| 45 |
k: v for k, v in resp_openai.headers.items()
|
| 46 |
if k.lower() not in HOP_BY_HOP_HEADERS
|
| 47 |
}
|
| 48 |
|
|
|
|
| 49 |
return Response(
|
| 50 |
content=resp_openai.content,
|
| 51 |
status_code=resp_openai.status_code,
|
|
|
|
| 53 |
)
|
| 54 |
|
| 55 |
except httpx.RequestError as e:
|
| 56 |
+
# ЭТО ВАЖНАЯ ЧАСТЬ ДЛЯ ДИАГНОСТИКИ
|
| 57 |
+
# Выводим полную ошибку в логи Hugging Face Space
|
| 58 |
+
print(f"!!! HTTPX Request Error Caught: {e!r}")
|
| 59 |
+
# Возвращаем клиенту более детальную ошибку
|
| 60 |
+
return Response(content=f"Could not connect to OpenAI API. Details: {e!r}", status_code=502)
|
| 61 |
+
|
| 62 |
except Exception as e:
|
| 63 |
+
print(f"!!! Generic Error Caught: {e!r}")
|
| 64 |
+
return Response(content=f"An internal proxy error occurred. Details: {e!r}", status_code=500)
|