/contoso-chat

This sample has the full End2End process of creating RAG application with Prompt Flow and AI Studio. It includes GPT 3.5 Turbo LLM application code, evaluations, deployment automation with AZD CLI, GitHub actions for evaluation and deployment and intent mapping for multiple LLM task mapping.

Primary LanguageJupyter NotebookMIT LicenseMIT

name description languages products page_type urlFragment
Contoso Chat - RAG-based Retail copilot with Azure AI Studio
Build, evaluate, and deploy, a RAG-based retail copilot using Azure AI with Promptflow.
python
bicep
azdeveloper
prompty
azure-openai
azure-cognitive-search
azure
azure-cosmos-db
sample
contoso-chat

Contoso Chat: RAG-based Retail copilot with Azure AI Studio

Contoso Chat is the signature Python sample demonstrating how to build, evaluate, and deploy, a retail copilot application end-to-end with Azure AI Studio using Promptflow (flex-flow) with Prompty assets.

Open in GitHub Codespaces Open in Dev Containers


Table of Contents

What is this sample?

In this sample we build, evaluate and deploy a support chat agent for Contoso Outdoors, a fictitious retailer who sells hiking and camping equipment. The implementation uses a Retrieval Augmented Generation approach to answer customer queries with responses grounded in the company's product catalog and customer purchase history.

The sample uses the following Azure technologies:

  • Azure AI Search to create and manage search indexes for product catalog data
  • Azure Cosmos DB to store and manage customer purchase history data
  • Azure OpenAI to deploy and manage key models for our copilot workflow
    • text-embeddings-ada-002 for vectorizing user queries
    • gpt-4 for AI-assisted evaluation
    • gpt-35-turbo for generating chat responses

By exploring and deploying this sample, you will learn to:

  • Build a retail copilot application using the RAG pattern.
  • Define and engineer prompts using the Prompty asset.
  • Design, run & evaluate a copilot using the Promptflow framework.
  • Provision and deploy the solution to Azure using the Azure Developer CLI.
  • Explore and understand Responsible AI practices for evaluation and content safety.

Version History

This is the signature sample for showcasing end-to-end development of a copilot application code-first on the Azure AI platform and has been actively used for training developer audiences and partners at signature events including Microsoft AI Tour and Microsoft Build. This section maintains links to prior versions associated with the relevant events and workshops for reference.

Version Description
v0 : #cc2e808 Microsoft AI Tour 2023-24 (dag-flow, jnja template) - Skillable Lab
v1 : msbuild-lab322 Microsoft Build 2024 (dag-flow, jnja template) - Skillable Lab
v2 : main Latest version (flex-flow, prompty asset)- Azure AI Template

This sample builds the chat AI (copilot backend) that can be deployed to Azure AI Studio as a hosted API (endpoint) for integrations with front-end applications. For demonstration purposes only, the chat UI (retail front-end website) was prototyped in a second sample: contoso-web that provides the user experience shown below. Revisit this section for future updates on chat-UI samples that are Azure AI template ready for convenience.

Image shows a retailer website with backpacks - and a chat session with a customer

Key Features

The project comes with:

  • Sample model configurations, chat and evaluation prompts for a RAG-based copilot app.
  • Prompty assets to simplify prompt creation & iteration for this copilot scenario.
  • Sample product and customer data for the retail copilot scenario.
  • Sample application code for copilot chat and evaluation workflows.
  • Sample azd-template configuration for managing the application on Azure.
  • Managed Identity configuration as a best practice for managing sensitive credentials.

This is also a signature sample for demonstrating the end-to-end capabilities of the Azure AI platform. Expect regular updates to showcase cutting-edge features and best practices for generative AI development.

Architecture Diagram

The Contoso Chat application implements a retrieval augmented generation pattern to ground the model responses in your data. The architecture diagram below illustrates the key components and services used for implementation and highlights the use of Azure Managed Identity to reduce developer complexity in managing sensitive credentials.

Architecture Diagram

Getting Started

1. Pre-Requisites

You will also need to validate the following requirements:

![!Note] In this template, we have pre-configured Azure AI Search for deployment in eastus, while all other resources get deployed to the default location specified during the azd-driven deployment. This is primarily due to the limited regional availability of the semantic ranker feature at present. By using a default location for the search resource, we can now be more flexible in selecting the location for deploying other resources (e.g., to suit your model quota availability).

2. Setup Environment

You have three options for getting started with this template:

  • GitHub Codespaces - Cloud-hosted dev container (pre-built environment)
  • VS Code Dev Containers - Locally-hosted dev container (pre-built environment)
  • Manual Setup - Local environment setup (for advanced users)

We recommend the first option for the quickest start with minimal effort required. The last option requires the most user effort offers maximum control over your setup. All three options are documented below - pick one.

Once you complete setup, use these commands to validate the install:

2.1 Using GitHub Codespaces

  1. Click the button to launch this repository in GitHub Codespaces.

    Open in GitHub Codespaces

  2. This should launch a new browser tab for GitHub Codespaces setup. The process may take a few minutes to complete.

  3. Once ready, the tab will refresh to show a Visual Studio Code editor in the browser.

  4. Open the terminal in VS Code and validate install with these commands:

    • azd version - Azure Developer CLI is installed (v1.8.2+)
    • pf version - Promptflow is installed (v1.10.0+)
    • az version - Azure CLI is installed (v2.60+)
    • python3 --version - Python3 is installed (v3.11+)
  5. Sign into your Azure account from the VS Code terminal

    azd auth login --use-device-code
  6. Congratulations! You are ready to move to the Azure Deployment step.

2.2 Using VS Code Dev Containers

A related option is VS Code Dev Containers, which will open the project in your local VS Code using the Dev Containers extension:

  1. Start Docker Desktop (install it if not already installed)

  2. Open the project by clickjing the button below:

    Open in Dev Containers

  3. Once ready, the tab will refresh to show a Visual Studio Code editor in the browser.

  4. Open the terminal in VS Code and validate install with these commands:

    • azd version - Azure Developer CLI is installed (v1.8.2+)
    • pf version - Promptflow is installed (v1.10.0+)
    • az version - Azure CLI is installed (v2.60+)
    • python3 --version - Python3 is installed (v3.11+)
  5. Sign into your Azure account from the VS Code terminal

    azd auth login
  6. Congratulations! You are ready to move to the Azure Deployment step.

2.3 Manual Setup (Local Environment)

  • Verify you have Python3 installed on your machine.
    • Install dependencies with pip install -r requirements.txt
  • Install Azure CLI
  • Install Azure Developer CLI
    • Windows: winget install microsoft.azd
    • Linux: curl -fsSL https://aka.ms/install-azd.sh | bash
    • MacOS: brew tap azure/azd && brew install azd
  • Validate install with these commands:
    • azd version - Azure Developer CLI is installed (v1.8.2+)
    • pf version - Promptflow is installed (v1.10.0+)
    • az version - Azure CLI is installed (v2.60+)
    • python3 --version - Python3 is installed (v3.11+)

3. Azure Deployment

Complete these steps in the same terminal that you used previously, to authenticate with Azure.

  1. Provision Azure resources and deploy your application with one command. The process should ask you for an environment name (maps to resource group) and a location (Azure region) and subscription for deployment.
    azd up
  2. Verify that your application was provisioned correctly.
    • Visit the Azure Portal and verify the resource group (above) was created.
    • Visit the Azure AI Studio site and verify the AI project was created.
  3. Congratulations! Your setup step is complete.

Local Development

The core functionality of the copilot application is developed using the Promptflow framework with Python. In this project, we use the Promptflow extension in Visual Studio Code, with its pf commandline tool, for all our local development needs.

🚨 TODO

More details can be found in the documentation section of this repo.

Costs

You can estimate the cost of this project's architecture with Azure's pricing calculator

  • Azure OpenAI - Standard tier, GPT-4, GPT-35-turbo and Ada models. See Pricing
  • Azure AI Search - Basic tier, Semantic Ranker enabled See Pricing
  • Azure Cosmos DB for NoSQL - Serverless, Free Tier See Pricing

Security Guidelines

We recommend using keyless authentication for this project. Read more about why you should use managed identities on our blog.

Resources


Troubleshooting

Have questions or issues to report? Please open a new issue after first verifying that the same question or issue has not already been reported. In the latter case, please add any additional comments you may have, to the existing issue.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.