How to create a free or coding style of AI chatbot?

MICHELLE ALFARO MACAHIS 0 Reputation points
2024-06-15T14:47:05.49+00:00

How to create a self-made AI chatbot for a hotel reservation for our system based on our given data from database only in provided area or country that can be accessed by other countries?

Azure AI Language
Azure AI Language
An Azure service that provides natural language capabilities including sentiment analysis, entity extraction, and automated question answering.
388 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,627 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 19,626 Reputation points
    2024-06-17T07:55:23.6133333+00:00

    If using Microsoft Bot Framework:

    1. Create a Bot Service:
      • Go to the Azure Portal.
      • Create a new resource and search for "Bot Services".
      • Set up your bot service with the necessary configurations.
    2. Install Bot Framework SDK:
      • Install Bot Framework SDK for your chosen programming language. For Python, you can install it using pip:
             
             pip install botbuilder-core botbuilder-dialogs botbuilder-ai
             
        

    Use a library to connect to your Azure SQL Database. For Python, you can use pyodbc or sqlalchemy.

    
    import pyodbc
    
    connection_string = 'DRIVER={ODBC Driver 17 for SQL Server};SERVER=tcp:<your_server>.database.windows.net;DATABASE=<your_database>;UID=<your_username>;PWD=<your_password>'
    
    connection = pyodbc.connect(connection_string)
    
    cursor = connection.cursor()
    

    Create dialog flows to handle different user interactions like searching for hotels, making reservations...

    
    from botbuilder.core import TurnContext, ActivityHandler
    
    from botbuilder.dialogs import DialogSet, WaterfallDialog, WaterfallStepContext
    
    class HotelReservationBot(ActivityHandler):
    
        def __init__(self, connection):
    
            self.connection = connection
    
            self.dialogs = DialogSet()
    
            self.dialogs.add(WaterfallDialog("main_dialog", [self.start_reservation, self.confirm_reservation]))
    
        async def on_message_activity(self, turn_context: TurnContext):
    
            dialog_context = await self.dialogs.create_context(turn_context)
    
            await dialog_context.continue_dialog()
    
            if dialog_context.active_dialog is None:
    
                await dialog_context.begin_dialog("main_dialog")
    
        async def start_reservation(self, step_context: WaterfallStepContext):
    
            # Logic to start reservation process
    
            return await step_context.prompt("prompt_text", "Welcome to Hotel Reservation. Please provide your destination.")
    
        async def confirm_reservation(self, step_context: WaterfallStepContext):
    
            # Logic to confirm reservation
    
            destination = step_context.result
    
            cursor = self.connection.cursor()
    
            cursor.execute("SELECT * FROM hotels WHERE location = ?", destination)
    
            hotels = cursor.fetchall()
    
            await step_context.context.send_activity(f"Found {len(hotels)} hotels in {destination}.")
    
            return await step_context.end_dialog()
    

    To understand user inputs better, integrate NLU services like LUIS or Dialogflow.

    
    from botbuilder.ai.luis import LuisApplication, LuisRecognizer
    
    luis_app = LuisApplication("<app_id>", "<endpoint_key>", "https://<region>.api.cognitive.microsoft.com/")
    
    luis_recognizer = LuisRecognizer(luis_app)
    
    async def recognize_intent(self, turn_context: TurnContext):
    
        luis_result = await luis_recognizer.recognize(turn_context)
    
        return luis_result.properties["luisResult"]
    
    

    Deploy your bot to Azure App Service for scalability and accessibility and register it with various channels (for example Web Chat, Skype, Facebook Messenger....).

    Links to help you :

    0 comments No comments