ItsCxdy commited on
Commit
4bd0628
·
verified ·
1 Parent(s): bca0877

Update telegram_bot.py

Browse files
Files changed (1) hide show
  1. telegram_bot.py +7 -10
telegram_bot.py CHANGED
@@ -5,8 +5,7 @@ from dotenv import load_dotenv
5
  from telegram import Update, ReplyKeyboardMarkup, ReplyKeyboardRemove
6
  import datetime
7
  from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes, ConversationHandler
8
- # NEW IMPORT: Necessary to explicitly configure the request object
9
- from telegram.request import HTTPXRequest
10
  import logging
11
 
12
  # Using the dedicated packages as recommended by LangChain warnings
@@ -43,6 +42,7 @@ class TelegramHomeopathyBot:
43
  # Explicitly set device to 'cpu' for memory constrained environments
44
  model_kwargs={'device': 'cpu'}
45
  )
 
46
  self.vector_store = Chroma(
47
  persist_directory="./vector_db",
48
  embedding_function=self.embeddings
@@ -378,18 +378,14 @@ def main():
378
 
379
  print("🚀 Starting Telegram Homeopathy Bot...")
380
 
381
- # NEW: Explicitly configure the request object to use the correct base URL
382
- # This often bypasses environmental DNS resolution failures.
383
- custom_request = HTTPXRequest(
384
- base_url='https://api.telegram.org/bot'
385
- )
386
 
387
  # Create Application
388
  application = (
389
  Application.builder()
390
  .token(TELEGRAM_TOKEN)
391
- .request(custom_request) # Inject the custom request object
392
- .build()
393
  )
394
 
395
  # Add conversation handler
@@ -421,4 +417,5 @@ def main():
421
 
422
  if __name__ == '__main__':
423
  # Ensure all initialization warnings are visible before starting the main loop
424
- main()
 
 
5
  from telegram import Update, ReplyKeyboardMarkup, ReplyKeyboardRemove
6
  import datetime
7
  from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes, ConversationHandler
8
+ # Removed: from telegram.request import HTTPXRequest
 
9
  import logging
10
 
11
  # Using the dedicated packages as recommended by LangChain warnings
 
42
  # Explicitly set device to 'cpu' for memory constrained environments
43
  model_kwargs={'device': 'cpu'}
44
  )
45
+ # Using a reliable embedding function is critical for RAG performance
46
  self.vector_store = Chroma(
47
  persist_directory="./vector_db",
48
  embedding_function=self.embeddings
 
378
 
379
  print("🚀 Starting Telegram Homeopathy Bot...")
380
 
381
+ # 🚨 FIX: Reverting to the standard Application.builder() to avoid the HTTPXRequest TypeError.
382
+ # The application will now use default request settings, which should work if the DNS issue is resolved.
 
 
 
383
 
384
  # Create Application
385
  application = (
386
  Application.builder()
387
  .token(TELEGRAM_TOKEN)
388
+ .build() # Removed the custom request object injection
 
389
  )
390
 
391
  # Add conversation handler
 
417
 
418
  if __name__ == '__main__':
419
  # Ensure all initialization warnings are visible before starting the main loop
420
+ main()
421
+