Skip to content

luigiw/azureai-basic-python

 
 

Repository files navigation

page_type languages products urlFragment name description
sample
azdeveloper
bicep
python
azure
azure-openai
azure-ai
azure-cognitive-search
azure-container-apps
azureai-basic-python
Azure AI basic template (Python)
Creates an Azure AI Studio hub, project and required dependent resources including Azure AI Services, Azure AI Search and more. Deploys a simple chat application.

Azure AI Studio Starter Template

Open in GitHub Codespaces Open in Dev Containers

This project creates an Azure AI Studio hub, project and connected resources including Azure AI Services, AI Search and more. It also deploys a simple chat application to Azure Container Apps.

Features

This template creates everything you need to get started with Azure AI Studio:

The template also includes dependent resources required by all AI Hub resources:

Architecture diagram

Architecture diagram showing that user input used in conjunction with user identity to call app code running in Azure Container apps that processes the user input and generates a response to the user. The app code leverages Azure AI projects, Azure AI model inference, prompty, and Azure AI Search.

Getting started

You have a few options for getting started with this template. The quickest way to get started is GitHub Codespaces, since it will setup all the tools for you, but you can also set it up locally.

GitHub Codespaces

You can run this template virtually by using GitHub Codespaces. The button will open a web-based VS Code instance in your browser:

  1. Open the template (this may take several minutes):

    Open in GitHub Codespaces

  2. Open a terminal window

  3. Continue with the deploying steps

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:

    Open in Dev Containers

  3. In the VS Code window that opens, once the project files show up (this may take several minutes), open a terminal window.

  4. Continue with the deploying steps

Local environment

If you're not using one of the above options for opening the project, then you'll need to:

  1. Make sure the following tools are installed:

  2. Download the project code:

    azd init -t azureai-basic-python
  3. Open the project folder in your terminal or editor.

  4. Continue with the deploying steps.

Deploying

Once you've opened the project in Codespaces, in Dev Containers, or locally, you can deploy it to Azure.

Azure account setup

  1. Sign up for a free Azure account and create an Azure Subscription.
  2. Check that you have the necessary permissions:

Deploying with azd

  1. Login to Azure:

    azd auth login
  2. (Optional) If you would like to customize the deployment to disable resources, customize resource names, or customize the models, you can follow those steps now.

  3. Provision and deploy all the resources:

    azd up

    It will prompt you to provide an azd environment name (like "azureaiapp"), select a subscription from your Azure account, and select a location which has quota for all the resources. Then it will provision the resources in your account and deploy the latest code. If you get an error or timeout with deployment, changing the location can help, as there may be availability constraints for the resources.

  4. When azd has finished deploying, you'll see an endpoint URI in the command output. Visit that URI, and you should see the app! 🎉

  5. You can now proceed to run the development server to test the app locally, or if you are done trying out the app, you can delete the resources by running azd down.

Bringing an existing AI project resource

If you have an existing AI project resource, you can bring it into the Azure AI Studio Starter Template by setting the following environment variable:

azd env set AZURE_EXISTING_AIPROJECT_CONNECTION_STRING "<connection-string>"

You can find the connection string on the overview page of your Azure AI project.

If you do not have a deployment named "gpt-4o-mini" in your existing AI project, you should either create one in Azure AI studio or follow the steps in Customizing model deployments to specify a different model.

Development server

Make sure you first deployed the app to Azure before running the development server.

  1. Create a Python virtual environment and activate it.

    On Windows:

    py -3 -m venv .venv
    .venv\scripts\activate

    On Linux:

    python3 -m venv .venv
    source .venv/bin/activate
  2. Navigate to the src directory:

    cd src
  3. Install required Python packages:

    python -m pip install -r requirements.txt
  4. Run the local server:

    python -m uvicorn "api.main:create_app" --factory --reload
  5. Click 'http://127.0.0.1:8000' in the terminal, which should open a new tab in the browser.

  6. Enter your message in the box.

Guidance

Costs

Pricing varies per region and usage, so it isn't possible to predict exact costs for your usage. The majority of the Azure resources used in this infrastructure are on usage-based pricing tiers. However, Azure Container Registry has a fixed cost per registry per day.

You can try the Azure pricing calculator for the resources:

  • Azure AI Studio: Free tier. Pricing
  • Azure AI Search: Standard tier, S1. Pricing is based on the number of documents and operations. Pricing
  • Azure Storage Account: Standard tier, LRS. Pricing is based on storage and operations. Pricing
  • Azure Key Vault: Standard tier. Pricing is based on the number of operations. Pricing
  • Azure AI Services: S0 tier, defaults to gpt-4o-mini and text-embedding-ada-002 models. Pricing is based on token count. Pricing
  • Azure Container App: Consumption tier with 0.5 CPU, 1GiB memory/storage. Pricing is based on resource allocation, and each month allows for a certain amount of free usage. Pricing
  • Azure Container Registry: Basic tier. Pricing
  • Log analytics: Pay-as-you-go tier. Costs based on data ingested. Pricing

⚠️ To avoid unnecessary costs, remember to take down your app if it's no longer in use, either by deleting the resource group in the Portal or running azd down.

Security guidelines

This template uses Azure AI Studio connections to communicate between resources, which stores keys in Azure Key Vault. This template also uses Managed Identity for local development and deployment.

To ensure continued best practices in your own repository, we recommend that anyone creating solutions based on our templates ensure that the Github secret scanning setting is enabled.

You may want to consider additional security measures, such as:

Resources

Links to documentation for the resources used in this template.

About

Basic sample for deploying chat web apps with Azure AI Studio and SDKs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Bicep 92.4%
  • HTML 3.9%
  • Python 2.8%
  • PowerShell 0.4%
  • Shell 0.3%
  • CSS 0.1%
  • Dockerfile 0.1%