<h1 align="center">
<a href="https://prompts.chat">
[](https://github.com/codespaces/new?hide_repo_select=true&machine=basicLinux32gb&repo=725257907&ref=main&devcontainer_path=.devcontainer%2Fdevcontainer.json&geo=UsEast)
Sign in to like and favorite skills
page_type: sample languages:
This template, the application code and configuration it contains, has been built to showcase Microsoft Azure specific services and tools. We strongly advise our customers not to make this code part of their production environments without implementing or enabling additional security features.
For a more comprehensive list of best practices and security recommendations for Intelligent Applications, visit our official documentation.
[!WARNING]
Some of the features used in this repository are in preview. Preview versions are provided without a service level agreement, and they are not recommended for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.
Sample application code is included in this project. You can use or modify this app code or you can rip it out and include your own.
Contoso Outdoor is an online retailer specializing in hiking and camping equipment for outdoor enthusiasts. The website offers an extensive catalog of products - resulting in customers needing product information and recommendations to assist them in making relevant purchases.

This sample implements Contoso Chat - a retail copilot solution for Contoso Outdoor that uses a retrieval augmented generation design pattern to ground chatbot responses in the retailer's product and customer data. Customers can ask questions from the website in natural language, and get relevant responses with potential recommendations based on their purchase history - with responsible AI practices to ensure response quality and safety.

The sample illustrates the end-to-end workflow (GenAIOps) for building a RAG-based copilot code-first with Azure AI and Prompty. By exploring and deploying this sample, you will learn to:
The project template provides the following features:
It also comes with:

To deploy and explore the sample, you will need:
text-embedding-ada-002, gpt-35-turbo. and gpt-4We recommend deployments to
swedencentral or francecentral as regions that can support all these models. In addition to the above, you will also need the ability to:
From a tooling perspective, familiarity with the following is useful:
You have three options for setting up your development environment:
We recommend going with GitHub Codespaces for the fastest start and lowest maintenance overheads. Pick one option below - click to expand the section and view the details.
You can run this template virtually by using GitHub Codespaces. Click this button to open a web-based VS Code instance in your browser:
Once the codespaces environment is ready (this can take several minutes), open a new terminal in that VS Code instance - and proceed to the Development step.
A related option is to use VS Code Dev Containers, which will open the project in your local Visual Studio Code editor using the Dev Containers extension:
Install Docker Desktop (if not installed), then start it.
Open the project in your local VS Code by clicking the button below:
Once the VS Code window shows the project files (this can take several minutes), open a new terminal in that VS Code instance - and proceed to the Development step.
Install the required tools in your local device:
Note for Windows users: If you are not using a container to run this sample, note that our post-provisioning hooks make use of shell scripts. While we update scripts for different local device environments, we recommend using git bash to run samples correctly.
Initialize the project in your local device:
contoso-chat and cd into itazd init -t contoso-chat-openai-prompty
Install dependencies for the project, manually. Note that this is done for you automatically if you use the dev container options above.
cd src/api pip install -r requirements.txt
You can now proceed to the next step - Development - where we will provision the required Azure infrastructure and deploy the application from the template using
azd.
Once you've completed the setup the project (using Codespaces, Dev Containers, or local environment) you should now have a Visual Studio Code editor open, with the project files loaded, and a terminal open for running commands. Let's verify that all required tools are installed.
az version azd version prompty --version python --version
We can now proceed with next steps - click to expand for detailed instructions.
Open a VS Code terminal and authenticate with Azure CLI. Use the
--use-device-code option if authenticating from GitHub Codespaces. Complete the auth workflow as guided.
az login --use-device-code
Now authenticate with Azure Developer CLI in the same terminal. Complete the auth workflow as guided.
azd auth login --use-device-code
You should see: Logged in on Azure. This will create a folder under
.azure/ in your project to store the configuration for this deployment. You may have multiple azd environments if desired.
Run
azd up to provision infrastructure and deploy the application, with one command. (You can also use azd provision, azd deploy separately if needed)
azd up
You will be asked for a subscription for provisioning resources, an environment name that maps to the resource group, and a location for deployment. Refer to the Region Availability guidance to select the region that has the desired models and quota available.
The
azd up command can take 15-20 minutes to complete. Successful completion sees a SUCCESS: ... messages posted to the console. We can now validate the outcomes.
rg-ENVNAME resource group created aboveDeployments link in the Essentials section - wait till all are completed.Overview page - you should see: 35 deployments, 15 resourcesAzure CosmosDB resource in the list
customers database with data items in itAzure AI Search resource in the list
contoso-products index with data items in itAzure Container Apps resource in the list
Application UrlHello World message on pageAll Resources - you should see an AIServices and Hub resourcesAI Project resource listedazd up process also deploys the application as an Azure Container AppApplication Url to view endpoint/docs suffix to default deployed path - to get a Swagger API test pageTry it out to unlock inputs - you see question, customer_id, chat_history
question = "Tell me about the waterproof tents"customer_id = 2chat_history = []We can think about two levels of testing - manual validation and automated evaluation. The first is interactive, using a single test prompt to validate the prototype as we iterate. The second is code-driven, using a test prompt dataset to assess quality and safety of prototype responses for a diverse set of prompt inputs - and score them for criteria like coherence, fluency, relevance and groundedness based on built-in or custom evaluators.
The Contoso Chat application is implemented as a FastAPI application that can be deployed to a hosted endpoint in Azure Container Apps. The API implementation is defined in
src/api/main.py and currently exposes 2 routes:
/ - which shows the default "Hello World" message/api/create_request - which is our chat AI endpoint for test promptsTo test locally, we run the FastAPI dev server, then use the Swagger endpoint at the
/docs route to test the locally-served endpoint in the same way we tested the deployed version/
fastapi dev ./src/api/main.py - it should launch a dev serverOpen in browser to preview the dev server page in a new tab
//docs to the end of the path URL in the browser tab
POST route then click Try it out to unlock inputsquestion = "Tell me about the waterproof tents"customer_id = 2chat_history = []Testing a single prompt is good for rapid prototyping and ideation. But once we have our application designed, we want to validate the quality and safety of responses against diverse test prompts. The sample shows you how to do AI-Assisted Evaluation using custom evaluators implemented with Prompty.
src/api/evaluators/ folderevaluate-chat-flow.ipynb notebook - "Select Kernel" to activateRun all - starts evaluaton flow with data.jsonl test datasetresults.jsonl = the chat model's responses to test inputsevaluated_results.jsonl = the evaluation model's scoring of the responsesWant to get a better understanding of how custom evaluators work? Check out the
src/api/evaluators/custom_evals folder and explore the relevant Prompty assets and their template instructions.
The Prompty tooling also has support for built-in tracing for observability. Look for a
.runs/ subfolder to be created during the evaluation run, with .tracy files containing the trace data. Click one of them to get a trace-view display in Visual Studio Code to help you drill down or debug the interaction flow. This is a new feature so look for more updates in usage soon.
The solution is deployed using the Azure Developer CLI. The
azd up command effectively calls azd provision and then azd deploy - allowing you to provision infrastructure and deploy the application with a single command. Subsequent calls to azd up (e.g., ,after making changes to the application) should be faster, re-deploying the application and updating infrastructure provisioning only if required. You can then test the deployed endpoint as described earlier.
This template currently uses the following models:
gpt35-turbo, gpt-4 and text-embedding-ada-002, which may not be available in all Azure regions, or may lack sufficient quota for your subscription in supported regions. Check for up-to-date region availability and select a region during deployment accordingly
We recommend using francecentral
Pricing for services may vary by region and usage and exact costs are hard to determine. You can estimate the cost of this project's architecture with Azure's pricing calculator with these services:
This template uses Managed Identity for authentication with key Azure services including Azure OpenAI, Azure AI Search, and Azure Cosmos DB. Applications can use managed identities to obtain Microsoft Entra tokens without having to manage any credentials. This also removes the need for developers to manage these credentials themselves and reduces their complexity.
Additionally, we have added a GitHub Action tool that scans the infrastructure-as-code files and generates a report containing any detected issues. To ensure best practices we recommend anyone creating solutions based on our templates ensure that the Github secret scanning setting is enabled in your repo.
The sample has a
docs/workshop folder with step-by-step guidance for developers, to help you deconstruct the codebase, and understand how to to provision, ideate, build, evaluate, and deploy, the application yourself, with your own data.
pip install mkdocs-materialcd docs/workshopmkdocs serveHave issues or questions about the workshop? Submit a new issue with a
documentation tag.
This project has adopted the Microsoft Open Source Code of Conduct. Learn more here:
For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
This project follows below responsible AI guidelines and best practices, please review them before using this project: