Guest User

Untitled

a guest
Dec 30th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. from __future__ import absolute_import
  2. from __future__ import division
  3. from __future__ import unicode_literals
  4.  
  5. from rasa_core_sdk import Action
  6. from rasa_core_sdk.events import SlotSet
  7.  
  8. import os
  9. import infermedica_api
  10.  
  11. class ActionMed(Action):
  12. def name(self):
  13. return 'action_medicine'
  14.  
  15. def run(self, dispatcher, tracker, domain):
  16. api = infermedica_api.API(app_id=os.environ['APP_ID'],
  17. app_key=os.environ['API_KEY'])
  18. choices = {}
  19. buttons = []
  20. symp = tracker.get_slot('symptom')
  21. request = infermedica_api.Diagnosis(sex='male', age='25')
  22.  
  23. symp = api.parse(symp).to_dict()
  24. symp_id = symp['mentions'][0]['id']
  25. request.add_symptom(symp_id, 'present')
  26.  
  27. request = api.diagnosis(request)
  28. items = request.question.items
  29.  
  30. for choice in items:
  31. choices[choice['id']] = choice['name']
  32.  
  33. response = request.question.text
  34.  
  35. for key, value in choices.items():
  36. title = value
  37. request.add_symptom(key, 'present')
  38. request = api.diagnosis(request)
  39. text = request.question.text
  40. buttons.append({"title": title, "payload": text})
  41. # response = "Let's try this medicine"
  42.  
  43. dispatcher.utter_button_message(response, buttons)
  44. # return [SlotSet('symptom', symp)]
  45. return []
Add Comment
Please, Sign In to add comment