Update api_helper.py
Browse files- api_helper.py +3 -7
api_helper.py
CHANGED
|
@@ -1,6 +1,3 @@
|
|
| 1 |
-
import requests
|
| 2 |
-
import json
|
| 3 |
-
|
| 4 |
# Constants
|
| 5 |
SPACE_URL = "https://abanm-dubs.hf.space/api/generate"
|
| 6 |
API_KEY = "s3cr3t_k3y" # Replace with your actual API key
|
|
@@ -35,12 +32,11 @@ def call_api(message):
|
|
| 35 |
data = json.loads(chunk)
|
| 36 |
if "response" in data:
|
| 37 |
bot_response += data["response"]
|
| 38 |
-
return bot_response if bot_response else "Error: No response from API."
|
| 39 |
except json.JSONDecodeError:
|
| 40 |
bot_response += "\nError decoding response chunk."
|
| 41 |
-
|
| 42 |
-
|
| 43 |
except requests.exceptions.Timeout:
|
| 44 |
return "Error: The API call timed out."
|
| 45 |
except requests.exceptions.RequestException as e:
|
| 46 |
-
return f"Error: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# Constants
|
| 2 |
SPACE_URL = "https://abanm-dubs.hf.space/api/generate"
|
| 3 |
API_KEY = "s3cr3t_k3y" # Replace with your actual API key
|
|
|
|
| 32 |
data = json.loads(chunk)
|
| 33 |
if "response" in data:
|
| 34 |
bot_response += data["response"]
|
|
|
|
| 35 |
except json.JSONDecodeError:
|
| 36 |
bot_response += "\nError decoding response chunk."
|
| 37 |
+
|
| 38 |
+
return bot_response.strip() if bot_response else "Error: No 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)}"
|