-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathactions.py
46 lines (35 loc) · 1.37 KB
/
actions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from rasa_core_sdk import Action
from rasa_core_sdk.events import SlotSet
import os
import infermedica_api
class ActionMed(Action):
def name(self):
return 'action_medicine'
def run(self, dispatcher, tracker, domain):
api = infermedica_api.API(app_id=os.environ['APP_ID'],
app_key=os.environ['API_KEY'])
choices = {}
buttons = []
symp = tracker.get_slot('symptom')
request = infermedica_api.Diagnosis(sex='male', age='25')
symp = api.parse(symp).to_dict()
symp_id = symp['mentions'][0]['id']
request.add_symptom(symp_id, 'present')
request = api.diagnosis(request)
items = request.question.items
for choice in items:
choices[choice['id']] = choice['name']
response = request.question.text
for key, value in choices.items():
title = value
request.add_symptom(key, 'present')
request = api.diagnosis(request)
text = request.question.text
buttons.append({"title": title, "payload": text})
# response = "Let's try this medicine"
dispatcher.utter_button_message(response, buttons)
# return [SlotSet('symptom', symp)]
return []