ChatBot
20 TopicsBuilding a Basic Chatbot with Azure OpenAI
Overview In this turorial, we'll build a simple chatbot that uses Azure OpenAI to generate responses to user queries. To create a basic chatbot, we need to set up a language model resource that enables conversation capabilities. In this tutorial, we will: Set up the Azure OpenAI resource using the Azure AI Foundry portal. Retrieve the API key needed to connect the resource to your chatbot application. Once the API key is configured in your code, you will be able to integrate the language model into your chatbot and enable it to generate responses. By the end of this tutorial, you'll have a working chatbot that can generate responses using the Azure OpenAI model. Signing In and Setting Up Your Azure AI Foundry Workspace Signing In to Azure AI Foundry Open the Azure AI Foundry page in your web browser. Login to your Azure account. If you don't have an account, you can sign up. Setting Up Your Azure AI Foundry Workspace Select + Create project to create a new project. Perform the following tasks: Enter Project name. It must be a unique value. Select Hub you'd like to use (create a new one if needed). Select Create. Setting Up the Azure OpenAI Resource in Azure AI Foundry In this step, you'll learn how to set up the Azure OpenAI resource in Azure AI Foundry. Azure OpenAI is a pre-trained language model that can generate responses to user queries. We'll be using it in our chatbot. Select Models + endpoints from the left side menu. On this page, you can deploy language models and set up Azure AI resources. In this step, we will deploy the Azure OpenAI GPT-4 language model. Select + Deploy model. Select Deploy base model. In this tutorial, we will deploy the GPT-4o model. Select GPT-4o. Select Confirm. Select Deploy. The model will be deployed. Once the deployment is complete, you will see the model listed on the Models + endpoints page. Now that the model is deployed, you can retrieve the API key needed to connect the model to your chatbot application. Select the model you deployed on the Models + endpoints page. ` On the model details page, you can view information about the model, including the API key. We will come back this page later to add the required information into the environment variables. Setting Up the Project and Install the Libraries Now, you will create a folder to work in and set up a virtual environment to develop a program. Creating a Folder to Work Inside It Open a terminal window and type the following command to create a folder named basic-chatbot in the default path. mkdir basic-chatbot Type the following command inside your terminal to navigate to the basic-chatbot folder you created. cd basic-chatbot Creating a Virtual Environment Type the following command inside your terminal to create a virtual environment named .venv. python -m venv .venv Type the following command inside your terminal to activate the virtual environment. .venv\Scripts\activate.bat NOTE If it worked, you should see (.venv) before the command prompt. Installing the Required Packages Type the following commands inside your terminal to install the required packages. openai: A Python library that provides integration with the Azure OpenAI API. python-dotenv: A Python library for managing environment variables stored in an .env file. pip install openai python-dotenv Setting up the Project in Visual Studio Code To create a basic chatbot program, you will need two files: example.py: This file will contain the code to interact with Azure resources. .env: This file will store the Azure credentials and configuration details. NOTE Purpose of the .env File The .env file is essential for storing the Azure information required to connect and use the resources you created. By keeping the Azure credentials in the .env file, you can ensure a secure and organized way to manage sensitive information. Setting Up example.py File Open Visual Studio Code. Select File from the menu bar. Select Open Folder. Select the basic-chatbot folder that you created, which is located at C:\Users\yourUserName\basic-chatbot. In the left pane of Visual Studio Code, right-click and select New File to create a new file named example.py. Add the following code to the example.py file to import the required libraries. from openai import AzureOpenAI from dotenv import load_dotenv import os # Load environment variables from the .env file load_dotenv() # Retrieve environment variables AZURE_OPENAI_ENDPOINT = os.getenv("AZURE_OPENAI_ENDPOINT") AZURE_OPENAI_API_KEY = os.getenv("AZURE_OPENAI_API_KEY") AZURE_OPENAI_MODEL_NAME = os.getenv("AZURE_OPENAI_MODEL_NAME") AZURE_OPENAI_CHAT_DEPLOYMENT_NAME = os.getenv("AZURE_OPENAI_CHAT_DEPLOYMENT_NAME") AZURE_OPENAI_API_VERSION = os.getenv("AZURE_OPENAI_API_VERSION") # Initialize Azure OpenAI client client = AzureOpenAI( api_key=AZURE_OPENAI_API_KEY, api_version=AZURE_OPENAI_API_VERSION, base_url=f"{AZURE_OPENAI_ENDPOINT}/openai/deployments/{AZURE_OPENAI_CHAT_DEPLOYMENT_NAME}" ) print("Chatbot: Hello! How can I assist you today? Type 'exit' to end the conversation.") while True: user_input = input("You: ") if user_input.lower() == "exit": print("Chatbot: Ending the conversation. Have a great day!") break response = client.chat.completions.create( model=AZURE_OPENAI_MODEL_NAME, messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": user_input} ], max_tokens=200 ) print("Chatbot:", response.choices[0].message.content.strip()) Setting Up .env File To set up your development environment, we will create a .env file and store the necessary credentials directly. NOTE Complete folder structure: └── YourUserName . └── basic-chatbot . ├── example.py . └── .env In the left pane of Visual Studio Code, right-click and select New File to create a new file named .env. Add the following code to the .env file to include your Azure information. AZURE_OPENAI_API_KEY=your_azure_openai_api_key AZURE_OPENAI_ENDPOINT=https://your_azure_openai_endpoint AZURE_OPENAI_MODEL_NAME=your_model_name AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=your_deployment_name AZURE_OPENAI_API_VERSION=your_api_version Retrieving Environment Variables from Azure AI Foundry Now, you will retrieve the required information from Azure AI Foundry and update the .env file. Go to the Models + endpoints page and select your deployed model. On the Model Details page, copy the following information in to the .env file.: AZURE_OPENAI_API_KEY AZURE_OPENAI_ENDPOINT AZURE_OPENAI_MODEL_NAME AZURE_OPENAI_CHAT_DEPLOYMENT_NAME Paste this information into the .env file in the respective placeholders. Running the Chatbot Program Type the following command inside your terminal to run the program and see if it can answer questions. python example.py Interact with the chatbot by typing your questions or messages. The chatbot will generate responses based on the Azure OpenAI model you deployed. NOTE You can find the full example of this chatbot, including the code and .env template, in my GitHub repository: GitHub Repository460Views2likes0CommentsStep-by-Step: How to Setup Copilot Chat in VS Code
Copilot Chat is an AI-powered chatbot leveraging OpenAI's GPT-4, designed to enhance your coding workflow. Learn how to set up Copilot Chat step by step in Visual Studio Code (VS Code). Benefit from personalized and flexible coding environments, code analysis, automated unit test generation, and bug fixes. Prerequisites include an active GitHub account and the latest version of VS Code. Elevate your coding efficiency to new heights with Copilot Chat.93KViews7likes6CommentsCreate Your Own Copilot Using Copilot Studio
Hello everyone, I am Suniti, Beta MLSA pursuing my graduation in the field of Data Science. Today, we're diving into creating our very own copilot to guide students towards ‘becoming MLSAs’. But first thing first, let's explore Copilot Studio!14KViews3likes2CommentsI want to present a ppt on how to integrate Chat Bot in MS Teams
I want to present a ppt on how to integrate Chat Bot in MS Teams. I have this documentation(https://learn.microsoft.com/en-us/microsoftteams/platform/bots/what-are-bots). Can anyone assist me to create a ppt from the content so that I can present to our leadership team? Thanks for your advanced support.405Views0likes0Commentsauthentication
Our application has two components. The tab and the bot. We did the authentication to our backend service in the tab part. So we can make API calls to our backend service from the tab component. But when we move to bot, we can't make the API calls from there. As we don't have the session ID and other authentication details. Can someone tell what would be a better approach to send the authentication details from tab to the bot side, so we can make API calls from bot env. as well.603Views0likes3CommentsBuild Your Own Chatbot in Minutes with Power Virtual Agents: No Coding Required!
Learn how to build a chatbot without coding using Power Virtual Agent, a platform by Microsoft. Automate tasks, reduce costs, and improve efficiency with AI-powered chatbots. No programming knowledge required! Discover how Power Virtual Agents work, guiding you through information like a digital librarian. Create your first chatbot by signing up on the Power Virtual Agents website and accessing your dashboard. Customize your bot's name, language, and even enable voice capabilities. Add relevant online content to enhance your bot's responses. Test and publish your bot with just a few clicks. Experience the functionality of your chatbot on the demo website. Explore more resources about Power Virtual Agent and reach out for assistance. Start building chatbots effortlessly today!21KViews2likes1CommentTeams Action Card Action.Submit
const questionCard = require("../adaptiveCards/question.json"); //Code within a method that displays the adaptive card to the user const cardAttachment = { contentType: 'application/vnd.microsoft.card.adaptive', content: questionCard, }; const message = { type: 'message', attachments: [cardAttachment], }; await context.sendActivity(message); //Adaptive Card { "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", "version": "1.5", "body": [ { "type": "TextBlock", "text": "Please enter your question below", "style": "heading" }, { "type": "Input.Text", "id": "question", "placeholder": "Enter question here", "maxLength": 500, "isMultiline": true } ], "actions": [ { "type": "Action.Submit", "title": "OK" "data": } ] } I am trying to read in the users input after they click on the submit button? What information should I put in the data section of my Action.Submit button so that I can get the information that was typed into the input section. as well as how do i create an event listener either in the method I am displaying my card or a seperate method within that file that will process the709Views0likes3Comments