0% found this document useful (0 votes)
71 views7 pages

Build and Deploy Your AI Chatbot Using GitHub Copilot 1

This document provides a step-by-step guide for building and deploying an AI chatbot using GitHub Copilot, AI Foundry SDK, and AI Foundry Services. It outlines prerequisites, environment setup, chatbot coding, prompt scripting, and deployment to Azure, making it accessible for both beginners and experienced developers. The guide emphasizes the use of modern tools to create efficient and modular chatbots with advanced features.

Uploaded by

karankumar71038
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views7 pages

Build and Deploy Your AI Chatbot Using GitHub Copilot 1

This document provides a step-by-step guide for building and deploying an AI chatbot using GitHub Copilot, AI Foundry SDK, and AI Foundry Services. It outlines prerequisites, environment setup, chatbot coding, prompt scripting, and deployment to Azure, making it accessible for both beginners and experienced developers. The guide emphasizes the use of modern tools to create efficient and modular chatbots with advanced features.

Uploaded by

karankumar71038
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Build and Deploy Your AI Chatbot Using GitHub Copilot, AI Foundry SDK,

and AI Foundry Services


Introduction:
Building an AI chatbot has never been more accessible, thanks to modern tools like GitHub Copilot and
Microsoft’s AI Foundry SDK. With these tools, you can create a chatbot that leverages AI Foundry
Services available at ai.azure.com for intelligent, dynamic responses. This blog will guide you step-by-
step through the process, incorporating advanced features like Prompt Scripting to enhance chatbot
functionality.
Whether you're a beginner or a seasoned developer, this project is perfect for learning how to harness
cutting-edge AI and cloud technologies.

Prerequisites:
Before starting, ensure you have the following:
 Python 3.9 or higher installed.
 Visual Studio Code with the Python extension.
 GitHub Copilot installed (free for students via GitHub Education).
 Access to AI Foundry Services at ai.azure.com.
Step 1: Setting Up Your Environment
1.1 Install Visual Studio Code and Extensions
1. Download and install Visual Studio Code.
2. Open VS Code and navigate to Extensions (Ctrl + Shift + X).
3. Install the following extensions:
o Python: Automatically installs Python and dependencies.

o GitHub Copilot: For AI-powered coding assistance.

o GitHub Copilot for Azure: For Azure integration and deployment.

1.2 Set Up a Project Folder


1. Create a new project folder in VS Code (e.g., AI_Chatbot).
2. Open a terminal in VS Code (`Ctrl + ``) and verify Python installation:

python --version
Step 2: Understanding the Chatbot
Explain the project’s purpose:
 Accepting user inputs through a web interface.
 Using AI Foundry Services to generate conversational responses.
 Demonstrating Prompt Scripting for modular, reusable AI prompts.

Step 3: Writing the Chatbot Code


3.1 Cloning a Repository (Optional)
1. If using a pre-built solution, fork or clone the repository:

git clone <repository-url>


cd AI_Chatbot

Ensure the requirements.txt file is present in the folder.


3.2 Creating a requirements.txt File
If building from scratch:
1. Create a requirements.txt file in the project folder.
2. Use GitHub Copilot to suggest dependencies: Prompt: "What dependencies are needed for Flask
and AI Foundry SDK?" Copilot suggests:

flask
ai-foundry-sdk

3.3 Install Dependencies


Install dependencies in the terminal:

pip install -r requirements.txt


3.4 Writing the Flask Application
Use GitHub Copilot to scaffold the app: Prompt: "Create a Flask app that integrates with AI Foundry
Services and Prompt Scripting." Copilot generates:

from flask import Flask, request, jsonify


from ai_foundry_sdk import FoundryClient

app = Flask(__name__)
client = FoundryClient(api_key="YOUR_API_KEY")

@app.route("/chat", methods=["POST"])
def chat():
user_input = request.json.get("message")
response = client.chat(user_input, prompt_script="general-conversation")
return jsonify({"response": response})

if __name__ == "__main__":
app.run(debug=True)
Replace "YOUR_API_KEY" with your API key from ai.azure.com.
Step 4: Understanding Prompt Scripting
What is Prompt Scripting?
Prompt Scripting is a method to pre-define reusable, modular AI prompts. It reduces the number of tokens
used by sending only the necessary context for each API call, improving efficiency.
Example Script Explanation:
1. Create a file scripts.py:

scripts = {
"greeting": "You are a friendly assistant. Respond warmly to greetings.",
"farewell": "You are a formal assistant. Respond politely to farewells.",
}

This defines modular responses for specific intents (e.g., greetings or farewells).
2. Use the script in the app:

from scripts import scripts

@app.route("/chat", methods=["POST"])
def chat():
user_input = request.json.get("message")
script = scripts.get(request.json.get("script"), "general-conversation")
response = client.chat(user_input, prompt_script=script)
return jsonify({"response": response})
Step 5: Deploying the Chatbot
5.1 Local Testing
Run the app locally to verify:

python app.py

Access it at http://127.0.0.1:5000.
5.2 Deploying to Azure
1. Use GitHub Copilot for guidance: Prompt: "Deploy this Flask app to Azure App Service."
Copilot provides:

az webapp up --runtime "PYTHON:3.9" --name <app-name>

2. Automate deployment with Azure Developer CLI (AZD): Prompt: "Set up and deploy using
AZD." Copilot suggests:

azd init
azd auth login
azd up
Step 6: Enhancing the Chatbot
Suggestions for advanced features:
 Error Handling: Add robust error handling using Copilot.
 Persistent Memory: Integrate a database for multi-turn conversations.
 Contextual Conversations: Extend Prompt Scripting for complex workflows.

Conclusion
By following this guide, you’ve built and deployed an AI chatbot using modern tools like the AI Foundry
SDK, AI Foundry Services, and GitHub Copilot. With Prompt Scripting, you’ve optimized efficiency
while simplifying modular design. This approach highlights the power of combining cutting-edge AI
tools with cloud-based deployment.

You might also like