本文整理汇总了Python中rasa_sdk.executor.CollectingDispatcher方法的典型用法代码示例。如果您正苦于以下问题:Python executor.CollectingDispatcher方法的具体用法?Python executor.CollectingDispatcher怎么用?Python executor.CollectingDispatcher使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rasa_sdk.executor
的用法示例。
在下文中一共展示了executor.CollectingDispatcher方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from rasa_sdk import executor [as 别名]
# 或者: from rasa_sdk.executor import CollectingDispatcher [as 别名]
def run(
self,
dispatcher, # type: CollectingDispatcher
tracker, # type: Tracker
domain, # type: Dict[Text, Any]
): # type: (...) -> List[Dict[Text, Any]]
url = f"https://rasa.com/carbon/index.html?" \
f"&rasaxhost=https://carbon.rasa.com" \
f"&conversationId={tracker.sender_id}" \
f"&destination=https://offset.earth%2F%3Fr%3D5de3ac5d7e813f00184649ea"
link_1_url = url + f"&label=link-1-clicked"
link_2_url = url + f"&label=link-2-clicked"
return [SlotSet("link_1_url", link_1_url), SlotSet("link_2_url", link_2_url)]
示例2: submit
# 需要导入模块: from rasa_sdk import executor [as 别名]
# 或者: from rasa_sdk.executor import CollectingDispatcher [as 别名]
def submit(self, dispatcher, tracker, domain):
# type: (CollectingDispatcher, Tracker, Dict[Text, Any]) -> List[Dict]
"""Define what the form has to do
after all required slots are filled
basically it generate sentiment analysis
using the user's feedback"""
sid = SentimentIntensityAnalyzer()
all_slots = tracker.slots
for slot, value in all_slots.copy().items():
if slot in self.required_slots(tracker):
res = sid.polarity_scores(value)
score = res.pop('compound', None)
classi, confidence = max(res.items(), key=lambda x: x[1])
# classification of the feedback, could be pos, neg, or neu
all_slots[slot+'_class'] = classi
# sentiment score of the feedback, range form -1 to 1
all_slots[slot+'_score'] = score
return [SlotSet(slot, value) for slot, value in all_slots.items()]
示例3: run
# 需要导入模块: from rasa_sdk import executor [as 别名]
# 或者: from rasa_sdk.executor import CollectingDispatcher [as 别名]
def run(self, dispatcher, tracker, domain):
# type: (CollectingDispatcher, Tracker, Dict[Text, Any]) -> List[Dict[Text, Any]]
result = tracker.slots
name = result['name']
if name is None:
name = 'Anonymous'
else:
name = name + "'s"
http_result =""""""
for key, value in result.items():
if key != 'requested_slot':
http_result += """<p>{}: {}</p>""".format(key, value)
# url of the server set up by result.py
url = 'http://localhost:8080/?name={}&result={}'.format(name, http_result)
webbrowser.open(url)
return []
示例4: utter_attribute_value
# 需要导入模块: from rasa_sdk import executor [as 别名]
# 或者: from rasa_sdk.executor import CollectingDispatcher [as 别名]
def utter_attribute_value(
self,
dispatcher: CollectingDispatcher,
object_name: Text,
attribute_name: Text,
attribute_value: Text,
) -> None:
"""
Utters a response that informs the user about the attribute value of the
attribute of interest.
Args:
dispatcher: the dispatcher
object_name: the name of the object
attribute_name: the name of the attribute
attribute_value: the value of the attribute
"""
if attribute_value:
dispatcher.utter_message(
text=f"'{object_name}' has the value '{attribute_value}' for attribute '{attribute_name}'."
)
else:
dispatcher.utter_message(
text=f"Did not find a valid value for attribute '{attribute_name}' for object '{object_name}'."
)
示例5: request_next_slot
# 需要导入模块: from rasa_sdk import executor [as 别名]
# 或者: from rasa_sdk.executor import CollectingDispatcher [as 别名]
def request_next_slot(
self,
dispatcher: "CollectingDispatcher",
tracker: "Tracker",
domain: Dict[Text, Any],
) -> Optional[List[EventType]]:
"""Request the next slot and utter template if needed,
else return None"""
for slot in self.required_slots(tracker):
if self._should_request_slot(tracker, slot):
logger.debug(f"Request next slot '{slot}'")
dispatcher.utter_message(template=f"utter_ask_{slot}", **tracker.slots)
return [SlotSet(REQUESTED_SLOT, slot)]
# no more required slots to fill
return None
示例6: _validate_if_required
# 需要导入模块: from rasa_sdk import executor [as 别名]
# 或者: from rasa_sdk.executor import CollectingDispatcher [as 别名]
def _validate_if_required(
self,
dispatcher: "CollectingDispatcher",
tracker: "Tracker",
domain: Dict[Text, Any],
) -> List[EventType]:
"""Return a list of events from `self.validate(...)`
if validation is required:
- the form is active
- the form is called after `action_listen`
- form validation was not cancelled
"""
if tracker.latest_action_name == "action_listen" and tracker.active_form.get(
"validate", True
):
logger.debug(f"Validating user input '{tracker.latest_message}'")
if utils.is_coroutine_action(self.validate):
return await self.validate(dispatcher, tracker, domain)
else:
return self.validate(dispatcher, tracker, domain)
else:
logger.debug("Skipping validation")
return []
示例7: test_extract_requested_slot_default
# 需要导入模块: from rasa_sdk import executor [as 别名]
# 或者: from rasa_sdk.executor import CollectingDispatcher [as 别名]
def test_extract_requested_slot_default():
"""Test default extraction of a slot value from entity with the same name
"""
form = FormAction()
tracker = Tracker(
"default",
{"requested_slot": "some_slot"},
{"entities": [{"entity": "some_slot", "value": "some_value"}]},
[],
False,
None,
{},
"action_listen",
)
slot_values = form.extract_requested_slot(CollectingDispatcher(), tracker, {})
assert slot_values == {"some_slot": "some_value"}
示例8: validate_cuisine
# 需要导入模块: from rasa_sdk import executor [as 别名]
# 或者: from rasa_sdk.executor import CollectingDispatcher [as 别名]
def validate_cuisine(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
"""Validate cuisine value."""
if value.lower() in self.cuisine_db():
# validation succeeded, set the value of the "cuisine" slot to value
return {"cuisine": value}
else:
dispatcher.utter_message(template="utter_wrong_cuisine")
# validation failed, set this slot to None, meaning the
# user will be asked for the slot again
return {"cuisine": None}
示例9: validate_outdoor_seating
# 需要导入模块: from rasa_sdk import executor [as 别名]
# 或者: from rasa_sdk.executor import CollectingDispatcher [as 别名]
def validate_outdoor_seating(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
"""Validate outdoor_seating value."""
if isinstance(value, str):
if "out" in value:
# convert "out..." to True
return {"outdoor_seating": True}
elif "in" in value:
# convert "in..." to False
return {"outdoor_seating": False}
else:
dispatcher.utter_message(template="utter_wrong_outdoor_seating")
# validation failed, set slot to None
return {"outdoor_seating": None}
else:
# affirm/deny was picked up as T/F
return {"outdoor_seating": value}
示例10: run
# 需要导入模块: from rasa_sdk import executor [as 别名]
# 或者: from rasa_sdk.executor import CollectingDispatcher [as 别名]
def run(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[Dict[Text, Any]]:
dispatcher.utter_message("I will remind you in 5 seconds.")
date = datetime.datetime.now() + datetime.timedelta(seconds=5)
entities = tracker.latest_message.get("entities")
reminder = ReminderScheduled(
"EXTERNAL_reminder",
trigger_date_time=date,
entities=entities,
name="my_reminder",
kill_on_user_message=False,
)
return [reminder]
示例11: submit
# 需要导入模块: from rasa_sdk import executor [as 别名]
# 或者: from rasa_sdk.executor import CollectingDispatcher [as 别名]
def submit(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[EventType]:
"""Once we have an email, attempt to add it to the database"""
email = tracker.get_slot("email")
client = MailChimpAPI(config.mailchimp_api_key)
# if the email is already subscribed, this returns False
added_to_list = client.subscribe_user(config.mailchimp_list, email)
# utter submit template
if added_to_list:
dispatcher.utter_message(template="utter_confirmationemail")
else:
dispatcher.utter_message(template="utter_already_subscribed")
return []
示例12: run
# 需要导入模块: from rasa_sdk import executor [as 别名]
# 或者: from rasa_sdk.executor import CollectingDispatcher [as 别名]
def run(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[EventType]:
# Fallback caused by TwoStageFallbackPolicy
if (
len(tracker.events) >= 4
and tracker.events[-4].get("name") == "action_default_ask_affirmation"
):
dispatcher.utter_message(template="utter_restart_with_button")
return [SlotSet("feedback_value", "negative"), ConversationPaused()]
# Fallback caused by Core
else:
dispatcher.utter_message(template="utter_default")
return [UserUtteranceReverted()]
示例13: run
# 需要导入模块: from rasa_sdk import executor [as 别名]
# 或者: from rasa_sdk.executor import CollectingDispatcher [as 别名]
def run(self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]):
dispatcher.utter_template("utter_first", tracker)
# dispatcher.utter_template("utter_howcanhelp", tracker)
dispatcher.utter_message(md("您可以这样向我提问: <br/>头痛怎么办<br/>\
什么人容易头痛<br/>\
头痛吃什么药<br/>\
头痛能治吗<br/>\
头痛属于什么科<br/>\
头孢地尼分散片用途<br/>\
如何防止头痛<br/>\
头痛要治多久<br/>\
糖尿病有什么并发症<br/>\
糖尿病有什么症状"))
return []
示例14: run
# 需要导入模块: from rasa_sdk import executor [as 别名]
# 或者: from rasa_sdk.executor import CollectingDispatcher [as 别名]
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
query = tracker.latest_message['text']
most_similar_id, score = self.get_most_similar_standard_question_id(query)
if float(score) > 0.93:
response = self.faq_data[most_similar_id]['a']
dispatcher.utter_message(response)
dispatcher.utter_message("Problem solved?")
else:
response = "Sorry, this question is beyond my ability..."
dispatcher.utter_message(response)
dispatcher.utter_message("Sorry, I can't answer your question. You can dial the manual serviece...")
return []
示例15: submit
# 需要导入模块: from rasa_sdk import executor [as 别名]
# 或者: from rasa_sdk.executor import CollectingDispatcher [as 别名]
def submit(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[Dict]:
dispatcher.utter_message("❤️❤️❤️Thank you so much for showing your intrest in traveling with us")
return []