本文整理汇总了Python中rasa_sdk.Tracker方法的典型用法代码示例。如果您正苦于以下问题:Python rasa_sdk.Tracker方法的具体用法?Python rasa_sdk.Tracker怎么用?Python rasa_sdk.Tracker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rasa_sdk
的用法示例。
在下文中一共展示了rasa_sdk.Tracker方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: submit
# 需要导入模块: import rasa_sdk [as 别名]
# 或者: from rasa_sdk import Tracker [as 别名]
def submit(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[Dict]:
"""Define what the form has to do
after all required slots are filled"""
# decide if the rating is low and send according finish message
rating = int(tracker.get_slot("rating"))
if rating < 3:
dispatcher.utter_template("utter_influence_done", tracker)
else:
dispatcher.utter_template("utter_awesome", tracker)
return []
示例2: run
# 需要导入模块: import rasa_sdk [as 别名]
# 或者: from rasa_sdk import Tracker [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)]
示例3: resolve_mention
# 需要导入模块: import rasa_sdk [as 别名]
# 或者: from rasa_sdk import Tracker [as 别名]
def resolve_mention(tracker: Tracker) -> Text:
"""
Resolves a mention of an entity, such as first, to the actual entity.
If multiple entities are listed during the conversation, the entities
are stored in the slot 'listed_items' as a list. We resolve the mention,
such as first, to the list index and retrieve the actual entity.
:param tracker: tracker
:return: name of the actually entity
"""
graph_database = GraphDatabase()
mention = tracker.get_slot("mention")
listed_items = tracker.get_slot("listed_items")
if mention is not None and listed_items is not None:
idx = int(graph_database.map("mention-mapping", mention))
if type(idx) is int and idx < len(listed_items):
return listed_items[idx]
示例4: submit
# 需要导入模块: import rasa_sdk [as 别名]
# 或者: from rasa_sdk import Tracker [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()]
示例5: run
# 需要导入模块: import rasa_sdk [as 别名]
# 或者: from rasa_sdk import Tracker [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 []
示例6: request_next_slot
# 需要导入模块: import rasa_sdk [as 别名]
# 或者: from rasa_sdk import Tracker [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
示例7: _validate_if_required
# 需要导入模块: import rasa_sdk [as 别名]
# 或者: from rasa_sdk import Tracker [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 []
示例8: test_get_attribute_slots
# 需要导入模块: import rasa_sdk [as 别名]
# 或者: from rasa_sdk import Tracker [as 别名]
def test_get_attribute_slots():
object_attributes = ["name", "cuisine", "price-range"]
expected_attribute_slots = [
{"name": "name", "value": "PastaBar"},
{"name": "cuisine", "value": "Italian"},
]
tracker = Tracker(
"default",
{"name": "PastaBar", "cuisine": "Italian"},
{},
[],
False,
None,
{},
"action_listen",
)
attribute_slots = get_attribute_slots(tracker, object_attributes)
for a in attribute_slots:
assert a in expected_attribute_slots
示例9: test_extract_requested_slot_default
# 需要导入模块: import rasa_sdk [as 别名]
# 或者: from rasa_sdk import Tracker [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"}
示例10: test_submit
# 需要导入模块: import rasa_sdk [as 别名]
# 或者: from rasa_sdk import Tracker [as 别名]
def test_submit(form_class: Type[FormAction]):
tracker = Tracker(
"default",
{"some_slot": "foobar", "other_slot": None},
{"intent": "greet"},
[],
False,
None,
{"name": "some_form", "validate": False, "rejected": False},
"action_listen",
)
form = form_class()
events = await form.run(dispatcher=None, tracker=tracker, domain=None)
assert events[0]["value"] == 42
示例11: validate_cuisine
# 需要导入模块: import rasa_sdk [as 别名]
# 或者: from rasa_sdk import Tracker [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}
示例12: validate_outdoor_seating
# 需要导入模块: import rasa_sdk [as 别名]
# 或者: from rasa_sdk import Tracker [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}
示例13: run
# 需要导入模块: import rasa_sdk [as 别名]
# 或者: from rasa_sdk import Tracker [as 别名]
def run(
self, dispatcher, tracker: Tracker, domain: Dict[Text, Any]
) -> List[Dict[Text, Any]]:
conversation_id = tracker.sender_id
dispatcher.utter_message(
f"The ID of this conversation is: " f"{conversation_id}."
)
dispatcher.utter_message(
f"Trigger an intent with "
f'curl -H "Content-Type: application/json" '
f'-X POST -d \'{{"name": "EXTERNAL_dry_plant", '
f'"entities": {{"plant": "Orchid"}}}}\' '
f"http://localhost:5005/conversations/{conversation_id}/"
f"trigger_intent"
)
return []
示例14: submit
# 需要导入模块: import rasa_sdk [as 别名]
# 或者: from rasa_sdk import Tracker [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 []
示例15: run
# 需要导入模块: import rasa_sdk [as 别名]
# 或者: from rasa_sdk import Tracker [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()]