Overview of the Azure AI Generative SDK packages

Note

Azure AI Studio is currently in public preview. This preview is provided without a service-level agreement, and we don't recommend it 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.

The Azure AI Generative package is part of the Azure AI SDK for Python and contains functionality for building, evaluating and deploying Generative AI applications that use Azure AI services. The default installation of the package contains capabilities for cloud-connected scenarios, and by installing extras you can also run operations locally (such as building indexes and calculating metrics).

Source code | Package (PyPI) | API reference documentation

This package is tested with Python 3.7, 3.8, 3.9 and 3.10.

For a more complete set of Azure libraries, see https://aka.ms/azsdk/python/all.

Getting started

Prerequisites

Install the package

Install the Azure AI generative package for Python with pip:

pip install azure-ai-generative[index,evaluate,promptflow]
pip install azure-identity

Key concepts

The [index,evaluate,promptflow] syntax specifies extra packages that you can optionally remove if you don't need the functionality:

  • [index] adds the ability to build indexes on your local development environment.
  • [evaluate] adds the ability to run evaluation and calculate metrics in your local development environment.
  • [promptflow] adds the ability to develop with prompt flow connected to your Azure AI project.

Usage

Connecting to Projects

The generative package includes the azure-ai-resources package and uses the AIClient for connecting to your project.

First, create an AI Client:

from azure.ai.resources.client import AIClient
from azure.identity import DefaultAzureCredential

ai_client = AIClient(
    credential=DefaultAzureCredential(),
    subscription_id='subscription_id',
    resource_group_name='resource_group',
    project_name='project_name'
)

Using the generative package

Azure AI Generative Python SDK offers the following key capabilities.

To build an index locally, import the build_index function:

from azure.ai.generative.index import build_index

To run a local evaluation, import the evaluate function:

from azure.ai.generative.evaluate import evaluate

To deploy chat functions and prompt flows, import the deploy function:

from azure.ai.resources.entities.deployment import Deployment

Examples

See our samples repository for examples of how to use the Azure AI Generative Python SDK.

Logs and telemetry

General

Azure AI clients raise exceptions defined in Azure Core.

from azure.core.exceptions import HttpResponseError

try:
    ai_client.compute.get("cpu-cluster")
except HttpResponseError as error:
    print("Request failed: {}".format(error.message))

Logging

This library uses the standard logging library for logging. Basic information about HTTP sessions (URLs, headers, etc.) is logged at INFO level.

Detailed DEBUG level logging, including request/response bodies and unredacted headers, can be enabled on a client with the logging_enable argument.

Telemetry

The Azure AI Generative Python SDK includes a telemetry feature that collects usage and failure data about the SDK and sends it to Microsoft when you use the SDK in a Jupyter Notebook only. Telemetry won't be collected for any use of the Python SDK outside of a Jupyter Notebook.

Telemetry data helps the SDK team understand how the SDK is used so it can be improved and the information about failures helps the team resolve problems and fix bugs. The SDK telemetry feature is enabled by default for Jupyter Notebook usage and can't be enabled for non-Jupyter scenarios.

To opt out of the telemetry feature in a Jupyter scenario:

  • When using the azure-ai-generative package, set both of the following environment variables to "False": "AZURE_AI_GENERATIVE_ENABLE_LOGGING" and "AZURE_AI_RESOURCES_ENABLE_LOGGING". Both environment variables need to be set to "False" since azure-ai-generative is dependent on azure-ai-resources.
  • When using the azure-ai-resources package, set the environment variable "AZURE_AI_RESOURCES_ENABLE_LOGGING" to "False".

Next steps