1. Define an Entity and Slot Update your domain.yml to define an entity (destination) and a corresponding slot. yaml Копирај кȏд entities: - destination slots: destination: type: text responses: utter_ask_destination: - text: "Where would you like to travel to?" actions: - action_provide_flight_info 2. Define Training Data to Extract Entity Update your nlu.yml with training examples for extracting the destination entity. yaml Копирај кȏд version: "3.1" nlu: - intent: request_flight examples: | - I want to get a flight to [Berlin](destination) - Any flights to [Berlin](destination)? - Book a flight to [Paris](destination) - Find flights to [New York](destination) - Get me a ticket to [Tokyo](destination) 3. Define the Rule In rules.yml, create a rule that triggers the action when the entity is detected. yaml Копирај кȏд version: "3.1" rules: - rule: Provide flight information steps: - intent: request_flight - action: action_provide_flight_info 4. Create a Custom Action Create a custom action (action_provide_flight_info) in your actions.py file to handle the response. python Копирај кȏд from typing import Any, Text, Dict, List from rasa_sdk import Action, Tracker from rasa_sdk.executor import CollectingDispatcher class ActionProvideFlightInfo(Action): def name(self) -> Text: return "action_provide_flight_info" def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: # Get the destination entity from the user's input destination = tracker.get_slot("destination") if destination: response = f"Let me check flights to {destination} for you." else: response = "Can you tell me the destination you'd like to travel to?" dispatcher.utter_message(text=response) return [] 5. Test Your Bot Train your model: bash Копирај кȏд rasa train Run your bot: bash Копирај кȏд rasa shell Test with inputs like: "I want to get a flight to Berlin." "Any flights to Paris?" Explanation Entity Recognition: The destination entity is extracted using Rasa's NLU model. Slot Management: The destination entity value is automatically stored in the destination slot. Custom Action: The action_provide_flight_info generates a response based on the slot value. Let me know if you need help with further customization! Кажеш: if i say now Zagreb will the model be able to find me flights to zagreb automatcailly or i have to include zagreb as well in there ChatGPT је рекао: ChatGPT The model can extract entities like "Zagreb" without explicitly including them in the training data, provided the NLU model is trained with a diverse and representative dataset for the destination entity. Here's how it works and what you can do to improve recognition: How Entity Recognition Works Pre-trained Models: Rasa uses spaCy or its DIETClassifier for entity recognition. These models can generalize to unseen examples if you've provided sufficient variations in your training data. Generalization: If your training data includes examples like [Berlin](destination), [Paris](destination), and [Tokyo](destination), the model can generalize to new cities like "Zagreb" because it learns patterns rather than specific instances. What Happens If You Say "Zagreb"? If the model generalizes well: It should recognize "Zagreb" as a destination entity without explicitly including it in the training data. If recognition fails: It might not extract "Zagreb" correctly. You can improve this by: Adding More Training Data: Include examples with different cities to enhance the model's understanding of destination. Using Regex Features: Define a regex pattern for cities to assist the model. Improving Recognition for Unseen Cities 1. Add Diverse Training Examples Expand nlu.yml with generic phrases and various city names. yaml Копирај кȏд nlu: - intent: request_flight examples: | - I want to get a flight to [London](destination) - Can you find flights to [Rome](destination)? - Book a ticket to [Madrid](destination) - Are there flights to [Vienna](destination)? 2. Use Regex for City Names In nlu.yml, add a regex pattern for common city names. yaml Копирај кȏд regex: - name: destination pattern: "(?i)(Berlin|Paris|Tokyo|Zagreb|[A-Za-z ]+)" This helps the model identify destination entities more reliably. 3. Use Lookup Tables Create a lookup table of city names for better generalization. Add it to nlu.yml. yaml Копирај кȏд nlu: - lookup: destination examples: | - Berlin - Paris - Tokyo - Zagreb - Vienna - New York - [Add more city names here] 4. Enable Fallbacks If the model fails to recognize the city, you can implement fallback logic in your custom action to prompt the user to clarify. Conclusion You don’t need to explicitly include "Zagreb" in the training data, but: Adding diverse examples helps. Using regex or lookup tables improves accuracy. The model should generalize well if trained properly. If "Zagreb" isn't recognized, you'll notice during testing, and you can fine-tune the model accordingly.