EricGEGE commited on
Commit
6d282da
·
verified ·
1 Parent(s): f8f27ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -20,6 +20,25 @@ import asyncio
20
  from telegram import Bot
21
 
22
  import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  def load_resolv_conf():
25
  with open('/etc/resolv.conf', 'r') as resolv_conf:
@@ -36,10 +55,6 @@ print(df_resume.head())
36
  model = SentenceTransformer("all-MiniLM-L6-v2")
37
  # file_name = 'questions.txt'
38
 
39
- async def send_telegram_message(token, chat_id, message):
40
- bot = Bot(token=token)
41
- await bot.send_message(chat_id=chat_id, text=message)
42
- print("Message sent successfully.")
43
 
44
 
45
  def savevectorstore():
@@ -93,7 +108,7 @@ def rag_chain(question,name):
93
  # with open('questions.txt', 'a',encoding='utf-8') as file:
94
  # file.write(f"\n\n{question}\n\n{country}\n\n{whatsapp}\n\n{name}||{sales}||{profit}||{product}")
95
  message = f"{name}\n\n{question}\n\n{ans}"
96
- asyncio.run(send_telegram_message(token, chat_id, message))
97
  return que,ans
98
  # rag_chain('I am very hungry.')
99
 
 
20
  from telegram import Bot
21
 
22
  import os
23
+ import requests
24
+ from requests.adapters import HTTPAdapter
25
+ from requests.packages.urllib3.util.retry import Retry
26
+
27
+
28
+ def send_telegram_message(token, chat_id, message):
29
+ bot = Bot(token=token)
30
+ retries = Retry(total=5, backoff_factor=0.5, status_forcelist=[500, 502, 503, 504])
31
+ adapter = HTTPAdapter(max_retries=retries)
32
+ http = requests.Session()
33
+ http.mount("https://", adapter)
34
+
35
+ try:
36
+ response = bot.send_message(chat_id=chat_id, text=message)
37
+ print("Message sent successfully:", response)
38
+ except telegram.error.TelegramError as e:
39
+ print(f"Failed to send message: {e}")
40
+
41
+
42
 
43
  def load_resolv_conf():
44
  with open('/etc/resolv.conf', 'r') as resolv_conf:
 
55
  model = SentenceTransformer("all-MiniLM-L6-v2")
56
  # file_name = 'questions.txt'
57
 
 
 
 
 
58
 
59
 
60
  def savevectorstore():
 
108
  # with open('questions.txt', 'a',encoding='utf-8') as file:
109
  # file.write(f"\n\n{question}\n\n{country}\n\n{whatsapp}\n\n{name}||{sales}||{profit}||{product}")
110
  message = f"{name}\n\n{question}\n\n{ans}"
111
+ send_telegram_message(token, chat_id, message)
112
  return que,ans
113
  # rag_chain('I am very hungry.')
114