apirrone
commited on
Commit
·
9d80ad8
1
Parent(s):
82a3883
ruff
Browse files
src/reachy_mini_conversation_app/console.py
CHANGED
|
@@ -285,21 +285,18 @@ class LocalStream:
|
|
| 285 |
# Try to validate by checking if we can fetch the models
|
| 286 |
try:
|
| 287 |
import httpx
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
"Content-Type": "application/json"
|
| 291 |
-
}
|
| 292 |
async with httpx.AsyncClient(timeout=10.0) as client:
|
| 293 |
-
response = await client.get(
|
| 294 |
-
"https://api.openai.com/v1/models",
|
| 295 |
-
headers=headers
|
| 296 |
-
)
|
| 297 |
if response.status_code == 200:
|
| 298 |
return JSONResponse({"valid": True})
|
| 299 |
elif response.status_code == 401:
|
| 300 |
return JSONResponse({"valid": False, "error": "invalid_api_key"}, status_code=401)
|
| 301 |
else:
|
| 302 |
-
return JSONResponse(
|
|
|
|
|
|
|
| 303 |
except Exception as e:
|
| 304 |
logger.warning(f"API key validation failed: {e}")
|
| 305 |
return JSONResponse({"valid": False, "error": "validation_error"}, status_code=500)
|
|
@@ -321,6 +318,7 @@ class LocalStream:
|
|
| 321 |
if self._instance_path:
|
| 322 |
try:
|
| 323 |
from dotenv import load_dotenv
|
|
|
|
| 324 |
from reachy_mini_conversation_app.config import set_custom_profile
|
| 325 |
|
| 326 |
env_path = Path(self._instance_path) / ".env"
|
|
|
|
| 285 |
# Try to validate by checking if we can fetch the models
|
| 286 |
try:
|
| 287 |
import httpx
|
| 288 |
+
|
| 289 |
+
headers = {"Authorization": f"Bearer {key}", "Content-Type": "application/json"}
|
|
|
|
|
|
|
| 290 |
async with httpx.AsyncClient(timeout=10.0) as client:
|
| 291 |
+
response = await client.get("https://api.openai.com/v1/models", headers=headers)
|
|
|
|
|
|
|
|
|
|
| 292 |
if response.status_code == 200:
|
| 293 |
return JSONResponse({"valid": True})
|
| 294 |
elif response.status_code == 401:
|
| 295 |
return JSONResponse({"valid": False, "error": "invalid_api_key"}, status_code=401)
|
| 296 |
else:
|
| 297 |
+
return JSONResponse(
|
| 298 |
+
{"valid": False, "error": "validation_failed"}, status_code=response.status_code
|
| 299 |
+
)
|
| 300 |
except Exception as e:
|
| 301 |
logger.warning(f"API key validation failed: {e}")
|
| 302 |
return JSONResponse({"valid": False, "error": "validation_error"}, status_code=500)
|
|
|
|
| 318 |
if self._instance_path:
|
| 319 |
try:
|
| 320 |
from dotenv import load_dotenv
|
| 321 |
+
|
| 322 |
from reachy_mini_conversation_app.config import set_custom_profile
|
| 323 |
|
| 324 |
env_path = Path(self._instance_path) / ".env"
|