Spaces:
Sleeping
Sleeping
Update app/services.py
Browse files- app/services.py +16 -4
app/services.py
CHANGED
|
@@ -68,11 +68,11 @@ async def test_api_key(api_key: str) -> dict:
|
|
| 68 |
"X-Title": "ContextIQ-Test"
|
| 69 |
}
|
| 70 |
|
| 71 |
-
# Minimal test payload
|
| 72 |
payload = {
|
| 73 |
"model": settings.MODEL_NAME,
|
| 74 |
-
"messages": [{"role": "user", "content": "
|
| 75 |
-
"max_tokens":
|
| 76 |
"temperature": 0
|
| 77 |
}
|
| 78 |
|
|
@@ -90,6 +90,17 @@ async def test_api_key(api_key: str) -> dict:
|
|
| 90 |
|
| 91 |
if response.status_code == 200:
|
| 92 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
response_data = response.json()
|
| 94 |
|
| 95 |
# Check for successful response structure
|
|
@@ -136,9 +147,10 @@ async def test_api_key(api_key: str) -> dict:
|
|
| 136 |
|
| 137 |
except Exception as json_error:
|
| 138 |
logger.error(f"❌ Failed to parse JSON response: {json_error}")
|
|
|
|
| 139 |
return {
|
| 140 |
"valid": False,
|
| 141 |
-
"message": "Invalid response format from OpenRouter",
|
| 142 |
"model_info": None
|
| 143 |
}
|
| 144 |
|
|
|
|
| 68 |
"X-Title": "ContextIQ-Test"
|
| 69 |
}
|
| 70 |
|
| 71 |
+
# Minimal test payload - use higher max_tokens to ensure valid response
|
| 72 |
payload = {
|
| 73 |
"model": settings.MODEL_NAME,
|
| 74 |
+
"messages": [{"role": "user", "content": "Test"}],
|
| 75 |
+
"max_tokens": 10,
|
| 76 |
"temperature": 0
|
| 77 |
}
|
| 78 |
|
|
|
|
| 90 |
|
| 91 |
if response.status_code == 200:
|
| 92 |
try:
|
| 93 |
+
# Check if response has content
|
| 94 |
+
response_text = response.text
|
| 95 |
+
if not response_text or response_text.strip() == "":
|
| 96 |
+
logger.error("❌ Empty response from OpenRouter API")
|
| 97 |
+
return {
|
| 98 |
+
"valid": False,
|
| 99 |
+
"message": "Empty response from OpenRouter API. Please try again.",
|
| 100 |
+
"model_info": None
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
logger.info(f"📄 Response content preview: {response_text[:200]}...")
|
| 104 |
response_data = response.json()
|
| 105 |
|
| 106 |
# Check for successful response structure
|
|
|
|
| 147 |
|
| 148 |
except Exception as json_error:
|
| 149 |
logger.error(f"❌ Failed to parse JSON response: {json_error}")
|
| 150 |
+
logger.error(f"📄 Raw response content: {response.text}")
|
| 151 |
return {
|
| 152 |
"valid": False,
|
| 153 |
+
"message": "Invalid response format from OpenRouter. Please try again.",
|
| 154 |
"model_info": None
|
| 155 |
}
|
| 156 |
|