Neurolingua commited on
Commit
9bac017
·
verified ·
1 Parent(s): 4d5b15d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -13
app.py CHANGED
@@ -16,12 +16,14 @@ if not os.path.exists(UPLOAD_FOLDER):
16
  os.makedirs(UPLOAD_FOLDER)
17
 
18
  conversation_memory = ConversationBufferMemory(max_size=6)
19
- def get_rates_async(callback):
20
- def task():
21
- result = get_rates()
22
- callback(result)
23
- threading.Thread(target=task).start()
24
-
 
 
25
  # Initialize the Flask app
26
  account_sid = os.environ.get('TWILIO_ACCOUNT_SID')
27
  auth_token = os.environ.get('TWILIO_AUTH_TOKEN')
@@ -74,14 +76,8 @@ def whatsapp_webhook():
74
  elif 'bookkeeping' in incoming_msg:
75
  response_text = "Please provide the details you'd like to record."
76
  elif ('rates' in incoming_msg.lower()) or ('price' in incoming_msg.lower()) or ('market' in incoming_msg.lower()) or ('rate' in incoming_msg.lower()) or ('prices' in incoming_msg.lower()):
77
- def handle_rates(result):
78
- response_text = generate_response(incoming_msg + ' data ' + result, chat_history)
79
- conversation_memory.add_to_memory({"user": incoming_msg, "assistant": response_text})
80
- send_message(sender, response_text)
81
-
82
- get_rates_async(handle_rates)
83
  return '', 204
84
-
85
  else:
86
  # Generate response considering the chat history
87
  response_text = generate_response(incoming_msg, chat_history)
 
16
  os.makedirs(UPLOAD_FOLDER)
17
 
18
  conversation_memory = ConversationBufferMemory(max_size=6)
19
+ def handle_rates(sender, incoming_msg, chat_history):
20
+ def callback(result):
21
+ response_text = generate_response(incoming_msg + ' data ' + result, chat_history)
22
+ conversation_memory.add_to_memory({"user": incoming_msg, "assistant": response_text})
23
+ send_message(sender, response_text)
24
+
25
+ result = get_rates()
26
+ callback(result)
27
  # Initialize the Flask app
28
  account_sid = os.environ.get('TWILIO_ACCOUNT_SID')
29
  auth_token = os.environ.get('TWILIO_AUTH_TOKEN')
 
76
  elif 'bookkeeping' in incoming_msg:
77
  response_text = "Please provide the details you'd like to record."
78
  elif ('rates' in incoming_msg.lower()) or ('price' in incoming_msg.lower()) or ('market' in incoming_msg.lower()) or ('rate' in incoming_msg.lower()) or ('prices' in incoming_msg.lower()):
79
+ handle_rates(sender, incoming_msg, chat_history)
 
 
 
 
 
80
  return '', 204
 
81
  else:
82
  # Generate response considering the chat history
83
  response_text = generate_response(incoming_msg, chat_history)