Update api_helper.py
Browse files- api_helper.py +4 -2
api_helper.py
CHANGED
|
@@ -19,7 +19,7 @@ def call_api(message):
|
|
| 19 |
"Authorization": f"Bearer {API_KEY}",
|
| 20 |
"Content-Type": "application/json",
|
| 21 |
}
|
| 22 |
-
payload = {"prompt": message} #
|
| 23 |
|
| 24 |
try:
|
| 25 |
# Send request with streaming enabled
|
|
@@ -35,6 +35,8 @@ def call_api(message):
|
|
| 35 |
bot_response += data.get("response", "")
|
| 36 |
except json.JSONDecodeError:
|
| 37 |
bot_response += "\nError decoding response chunk."
|
| 38 |
-
return bot_response
|
|
|
|
|
|
|
| 39 |
except requests.exceptions.RequestException as e:
|
| 40 |
return f"Error: {str(e)}"
|
|
|
|
| 19 |
"Authorization": f"Bearer {API_KEY}",
|
| 20 |
"Content-Type": "application/json",
|
| 21 |
}
|
| 22 |
+
payload = {"prompt": message} # Ensure the key matches API's expected input
|
| 23 |
|
| 24 |
try:
|
| 25 |
# Send request with streaming enabled
|
|
|
|
| 35 |
bot_response += data.get("response", "")
|
| 36 |
except json.JSONDecodeError:
|
| 37 |
bot_response += "\nError decoding response chunk."
|
| 38 |
+
return bot_response.strip() if bot_response else "Error: Empty response from API."
|
| 39 |
+
except requests.exceptions.Timeout:
|
| 40 |
+
return "Error: The API call timed out."
|
| 41 |
except requests.exceptions.RequestException as e:
|
| 42 |
return f"Error: {str(e)}"
|