當前位置: 首頁>>代碼示例>>Python>>正文


Python executor.CollectingDispatcher方法代碼示例

本文整理匯總了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)] 
開發者ID:RasaHQ,項目名稱:carbon-bot,代碼行數:18,代碼來源:actions.py

示例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()] 
開發者ID:Cheukting,項目名稱:rasa_workshop,代碼行數:23,代碼來源:actions.py

示例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 [] 
開發者ID:Cheukting,項目名稱:rasa_workshop,代碼行數:21,代碼來源:actions.py

示例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}'."
            ) 
開發者ID:RasaHQ,項目名稱:rasa-sdk,代碼行數:27,代碼來源:actions.py

示例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 
開發者ID:RasaHQ,項目名稱:rasa-sdk,代碼行數:19,代碼來源:forms.py

示例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 [] 
開發者ID:RasaHQ,項目名稱:rasa-sdk,代碼行數:25,代碼來源:forms.py

示例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"} 
開發者ID:RasaHQ,項目名稱:rasa-sdk,代碼行數:20,代碼來源:test_forms.py

示例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} 
開發者ID:botfront,項目名稱:rasa-for-botfront,代碼行數:19,代碼來源:actions.py

示例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} 
開發者ID:botfront,項目名稱:rasa-for-botfront,代碼行數:26,代碼來源:actions.py

示例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] 
開發者ID:botfront,項目名稱:rasa-for-botfront,代碼行數:23,代碼來源:actions.py

示例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 [] 
開發者ID:RasaHQ,項目名稱:rasa-demo,代碼行數:21,代碼來源:actions.py

示例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()] 
開發者ID:RasaHQ,項目名稱:rasa-demo,代碼行數:23,代碼來源:actions.py

示例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 [] 
開發者ID:pengyou200902,項目名稱:Doctor-Friende,代碼行數:19,代碼來源:actions.py

示例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 [] 
開發者ID:nghuyong,項目名稱:rasa-faq-bot,代碼行數:16,代碼來源:actions.py

示例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 [] 
開發者ID:cedextech,項目名稱:rasa-chatbot-templates,代碼行數:10,代碼來源:actions.py


注:本文中的rasa_sdk.executor.CollectingDispatcher方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。