Spaces:
Sleeping
Sleeping
Update temp.py
Browse files
temp.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from typing import Dict, Any, Tuple
|
2 |
|
3 |
-
from dotenv import load_dotenv
|
4 |
-
load_dotenv('.env')
|
5 |
import gradio as gr
|
6 |
import json
|
7 |
from datetime import datetime, timedelta
|
@@ -214,6 +214,7 @@ class MailChatBot:
|
|
214 |
cost=cost
|
215 |
)
|
216 |
session.available_data['delivery_time'] = delivery_time
|
|
|
217 |
|
218 |
return email
|
219 |
|
@@ -224,6 +225,14 @@ class MailChatBot:
|
|
224 |
print('SESSION: ', req.session_hash)
|
225 |
session: Session = self.sessions.get(req.session_hash,
|
226 |
Session(id=req.session_hash)).copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
if session.state == 'done':
|
228 |
return 'We have your order in processing. If you have any queries Kindly contact us at 123-456-7890'
|
229 |
if session.state == 'rejected':
|
@@ -244,7 +253,7 @@ class MailChatBot:
|
|
244 |
session.state = 'confirmation'
|
245 |
response = self._get_confirmation_email(session)
|
246 |
data = session.available_data.copy()
|
247 |
-
data['pickup_time'] = data["pickup_date"][0]["date"] + " " + data[
|
248 |
|
249 |
cost, row_id = update_data_in_gsheet(data,
|
250 |
sheet_id=SHEET_ID,
|
@@ -288,15 +297,19 @@ class MailChatBot:
|
|
288 |
if session.available_data.get('pickup_location') != output.get('pickup_location') or \
|
289 |
session.available_data.get('delivery_location') != output.get('delivery_location'):
|
290 |
session.state = "update"
|
291 |
-
|
|
|
|
|
292 |
output = Data(**output)
|
293 |
print('OUTPUT: ', output)
|
|
|
294 |
output, missing_data = self._validate_response(output)
|
295 |
-
session.update_data(output)
|
|
|
296 |
if missing_data:
|
297 |
if 'pickup_date' in missing_data:
|
298 |
chain = self._init_chain('missing_data')
|
299 |
-
data = {"required_data": "\n".join([f"{idx+1}. {val}"\
|
300 |
for idx, val in enumerate(missing_data)]),
|
301 |
"cdate": current_date,
|
302 |
"cday": current_day,
|
@@ -304,7 +317,7 @@ class MailChatBot:
|
|
304 |
}
|
305 |
else:
|
306 |
chain = self._init_chain('missing_data_with_date')
|
307 |
-
data = {"required_data": "\n".join([f"{idx+1}. {val}"\
|
308 |
for idx, val in enumerate(missing_data)]),
|
309 |
'date': output.pickup_date[0]['date'],
|
310 |
'day': output.pickup_date[0]['day_of_week'],
|
|
|
1 |
from typing import Dict, Any, Tuple
|
2 |
|
3 |
+
# from dotenv import load_dotenv
|
4 |
+
# load_dotenv('.env')
|
5 |
import gradio as gr
|
6 |
import json
|
7 |
from datetime import datetime, timedelta
|
|
|
214 |
cost=cost
|
215 |
)
|
216 |
session.available_data['delivery_time'] = delivery_time
|
217 |
+
session.available_data['pickup_time'] = pickup_time.strftime('%H:%M')
|
218 |
|
219 |
return email
|
220 |
|
|
|
225 |
print('SESSION: ', req.session_hash)
|
226 |
session: Session = self.sessions.get(req.session_hash,
|
227 |
Session(id=req.session_hash)).copy()
|
228 |
+
# general_chain = GeminiChain.from_system_prompt(template=prompts.ROUTER_CHAIN_PROMPT,
|
229 |
+
# input_variables=['query'],
|
230 |
+
# model_name=get_env_variable("OPENAI_MODEL_TURBO"),
|
231 |
+
# temperature=self.temperature, api_key=get_env_variable("OPENAI_API_KEY"),
|
232 |
+
# verbose=self.verbose, output_parser=self.parser
|
233 |
+
# )
|
234 |
+
# # output = general_chain.invoke({'query': message})['text']
|
235 |
+
# # return output
|
236 |
if session.state == 'done':
|
237 |
return 'We have your order in processing. If you have any queries Kindly contact us at 123-456-7890'
|
238 |
if session.state == 'rejected':
|
|
|
253 |
session.state = 'confirmation'
|
254 |
response = self._get_confirmation_email(session)
|
255 |
data = session.available_data.copy()
|
256 |
+
data['pickup_time'] = data["pickup_date"][0]["date"] + " " + data['pickup_time']
|
257 |
|
258 |
cost, row_id = update_data_in_gsheet(data,
|
259 |
sheet_id=SHEET_ID,
|
|
|
297 |
if session.available_data.get('pickup_location') != output.get('pickup_location') or \
|
298 |
session.available_data.get('delivery_location') != output.get('delivery_location'):
|
299 |
session.state = "update"
|
300 |
+
|
301 |
+
reasons = output.get("reasoning", {})
|
302 |
+
output = output.get("required_data", {})
|
303 |
output = Data(**output)
|
304 |
print('OUTPUT: ', output)
|
305 |
+
print('REASONS: ', reasons)
|
306 |
output, missing_data = self._validate_response(output)
|
307 |
+
session.update_data(output)
|
308 |
+
|
309 |
if missing_data:
|
310 |
if 'pickup_date' in missing_data:
|
311 |
chain = self._init_chain('missing_data')
|
312 |
+
data = {"required_data": "\n".join([f"{idx+1}. {val}: {reasons[val]}"\
|
313 |
for idx, val in enumerate(missing_data)]),
|
314 |
"cdate": current_date,
|
315 |
"cday": current_day,
|
|
|
317 |
}
|
318 |
else:
|
319 |
chain = self._init_chain('missing_data_with_date')
|
320 |
+
data = {"required_data": "\n".join([f"{idx+1}. {val}: {reasons[val]}"\
|
321 |
for idx, val in enumerate(missing_data)]),
|
322 |
'date': output.pickup_date[0]['date'],
|
323 |
'day': output.pickup_date[0]['day_of_week'],
|