Update bot_telegram.py
Browse files- bot_telegram.py +8 -8
bot_telegram.py
CHANGED
|
@@ -2,6 +2,7 @@ import os
|
|
| 2 |
import logging
|
| 3 |
import asyncio
|
| 4 |
import requests
|
|
|
|
| 5 |
from telegram import Update
|
| 6 |
from telegram.ext import Application, CommandHandler, MessageHandler, filters, CallbackContext
|
| 7 |
|
|
@@ -123,19 +124,14 @@ class TelegramBot:
|
|
| 123 |
|
| 124 |
headers = {
|
| 125 |
"Authorization": f"Bearer {self.auth_token}",
|
|
|
|
| 126 |
"accept": "application/json"
|
| 127 |
}
|
| 128 |
|
| 129 |
-
|
| 130 |
-
form_payload = {"question": user_message}
|
| 131 |
|
| 132 |
try:
|
| 133 |
-
|
| 134 |
-
response = requests.post(self.ai_url, headers={**headers, "Content-Type": "application/json"}, json=json_payload)
|
| 135 |
-
|
| 136 |
-
if response.status_code == 422:
|
| 137 |
-
logging.warning("JSON format rejected. Retrying with form-data...")
|
| 138 |
-
response = requests.post(self.ai_url, headers={**headers, "Content-Type": "application/x-www-form-urlencoded"}, data=form_payload)
|
| 139 |
|
| 140 |
logging.info(f"Response status: {response.status_code}")
|
| 141 |
logging.info(f"Response content: {response.text}")
|
|
@@ -179,3 +175,7 @@ if __name__ == "__main__":
|
|
| 179 |
password=API_PASSWORD
|
| 180 |
)
|
| 181 |
bot.run()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import logging
|
| 3 |
import asyncio
|
| 4 |
import requests
|
| 5 |
+
import time
|
| 6 |
from telegram import Update
|
| 7 |
from telegram.ext import Application, CommandHandler, MessageHandler, filters, CallbackContext
|
| 8 |
|
|
|
|
| 124 |
|
| 125 |
headers = {
|
| 126 |
"Authorization": f"Bearer {self.auth_token}",
|
| 127 |
+
"Content-Type": "application/x-www-form-urlencoded", # Always use form-data
|
| 128 |
"accept": "application/json"
|
| 129 |
}
|
| 130 |
|
| 131 |
+
form_payload = {"question": user_message} # Only use form-data
|
|
|
|
| 132 |
|
| 133 |
try:
|
| 134 |
+
response = requests.post(self.ai_url, headers=headers, data=form_payload)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
logging.info(f"Response status: {response.status_code}")
|
| 137 |
logging.info(f"Response content: {response.text}")
|
|
|
|
| 175 |
password=API_PASSWORD
|
| 176 |
)
|
| 177 |
bot.run()
|
| 178 |
+
|
| 179 |
+
# Prevent Hugging Face from stopping
|
| 180 |
+
while True:
|
| 181 |
+
time.sleep(3600) # Keep running indefinitely
|