mihalykiss commited on
Commit
9bdd716
·
verified ·
1 Parent(s): 3c6dab3

Update rasa_app/actions/actions.py

Browse files
Files changed (1) hide show
  1. rasa_app/actions/actions.py +53 -4
rasa_app/actions/actions.py CHANGED
@@ -248,8 +248,6 @@ def parse_new_meals(text: str) -> Dict[str, str]:
248
  if current_keyword:
249
  meals[current_keyword] = current_meal_text.strip()
250
 
251
-
252
-
253
  if all(v == "Not specified" for v in meals.values()) and text.strip():
254
  meals['description'] = text.strip()
255
  del meals['breakfast']
@@ -261,7 +259,6 @@ def parse_new_meals(text: str) -> Dict[str, str]:
261
  else:
262
  meals = {k: v for k, v in meals.items() if v != "Not specified"}
263
 
264
-
265
  return meals
266
 
267
  class ValidateDietChangeForm(FormValidationAction):
@@ -276,7 +273,6 @@ class ValidateDietChangeForm(FormValidationAction):
276
  ) -> List[Dict[Text, Any]]:
277
  """Validate form slots and submit action."""
278
 
279
-
280
  events = await super().run(dispatcher, tracker, domain)
281
 
282
  if tracker.active_loop and tracker.active_loop.get('name') == 'diet_change_form' and tracker.get_slot('new_meals_text') is not None:
@@ -325,4 +321,57 @@ class ValidateDietChangeForm(FormValidationAction):
325
  SlotSet("change_day", None),
326
  ActiveLoop(None)]
327
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
  return events
 
248
  if current_keyword:
249
  meals[current_keyword] = current_meal_text.strip()
250
 
 
 
251
  if all(v == "Not specified" for v in meals.values()) and text.strip():
252
  meals['description'] = text.strip()
253
  del meals['breakfast']
 
259
  else:
260
  meals = {k: v for k, v in meals.items() if v != "Not specified"}
261
 
 
262
  return meals
263
 
264
  class ValidateDietChangeForm(FormValidationAction):
 
273
  ) -> List[Dict[Text, Any]]:
274
  """Validate form slots and submit action."""
275
 
 
276
  events = await super().run(dispatcher, tracker, domain)
277
 
278
  if tracker.active_loop and tracker.active_loop.get('name') == 'diet_change_form' and tracker.get_slot('new_meals_text') is not None:
 
321
  SlotSet("change_day", None),
322
  ActiveLoop(None)]
323
 
324
+ return events
325
+
326
+ class ActionUpdateUserInfo(Action):
327
+ def name(self) -> Text:
328
+ return "action_update_user_info"
329
+
330
+ async def run(
331
+ self,
332
+ dispatcher: CollectingDispatcher,
333
+ tracker: Tracker,
334
+ domain: Dict[Text, Any],
335
+ ) -> List[Dict[Text, Any]]:
336
+
337
+ change_field = tracker.get_slot("change_field")
338
+ new_value = tracker.get_slot("new_value")
339
+
340
+ events = []
341
+
342
+ if change_field and new_value:
343
+ change_field = change_field.lower()
344
+
345
+ if "diet" in change_field or "preference" in change_field:
346
+ events.append(SlotSet("dietary_preference", new_value))
347
+
348
+ elif "health" in change_field or "goal" in change_field:
349
+ events.append(SlotSet("health_goal", new_value))
350
+
351
+ elif "age" in change_field:
352
+ events.append(SlotSet("age", new_value))
353
+
354
+ elif "weight" in change_field:
355
+ events.append(SlotSet("weight", new_value))
356
+
357
+ elif "height" in change_field:
358
+ events.append(SlotSet("height", new_value))
359
+
360
+ elif "gender" in change_field:
361
+ events.append(SlotSet("gender", new_value))
362
+
363
+ elif "activity" in change_field:
364
+ events.append(SlotSet("activity_level", new_value))
365
+
366
+ events.append(SlotSet("change_field", None))
367
+ events.append(SlotSet("new_value", None))
368
+
369
+ dispatcher.utter_message(response="utter_confirm_update")
370
+
371
+ elif change_field and not new_value:
372
+ dispatcher.utter_message(response="utter_ask_new_value")
373
+
374
+ else:
375
+ dispatcher.utter_message(response="utter_ask_which_field_to_change")
376
+
377
  return events