|
| 1 | +--- |
| 2 | +title: Overview of the Azure AI Generative SDK packages |
| 3 | +titleSuffix: Azure AI Studio |
| 4 | +description: This article provides overview of the Azure AI Generative SDK packages. |
| 5 | +author: eric-urban |
| 6 | +manager: nitinme |
| 7 | +ms.service: azure-ai-studio |
| 8 | +ms.topic: overview |
| 9 | +ms.date: 12/15/2023 |
| 10 | +ms.author: eur |
| 11 | +--- |
| 12 | + |
| 13 | +# Overview of the Azure AI Generative SDK packages |
| 14 | + |
| 15 | +[!INCLUDE [Azure AI Studio preview](../includes/preview-ai-studio.md)] |
| 16 | + |
| 17 | +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). |
| 18 | + |
| 19 | +[Source code](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/ai/azure-ai-generative) | [Package (PyPI)](https://pypi.org/project/azure-ai-generative/) | [API reference documentation](/python/api/overview/azure/ai-generative-readme) |
| 20 | + |
| 21 | +This package is tested with Python 3.7, 3.8, 3.9 and 3.10. |
| 22 | + |
| 23 | +For a more complete set of Azure libraries, see [https://aka.ms/azsdk/python/all](https://aka.ms/azsdk/python/all). |
| 24 | + |
| 25 | +## Getting started |
| 26 | + |
| 27 | +### Prerequisites |
| 28 | + |
| 29 | +- Python 3.7 or later is required to use this package. |
| 30 | +- You must have an [Azure subscription](https://portal.azure.com). |
| 31 | +- An [Azure AI project](./create-projects.md) in your Azure subscription. |
| 32 | + |
| 33 | + |
| 34 | +### Install the package |
| 35 | + |
| 36 | +Install the Azure AI generative package for Python with pip: |
| 37 | + |
| 38 | +```bash |
| 39 | +pip install azure-ai-generative[index,evaluate,promptflow] |
| 40 | +pip install azure-identity |
| 41 | +``` |
| 42 | + |
| 43 | +## Key concepts |
| 44 | + |
| 45 | +The `[index,evaluate,promptflow]` syntax specifies extra packages that you can optionally remove if you don't need the functionality: |
| 46 | + |
| 47 | +- `[index]` adds the ability to build indexes on your local development environment. |
| 48 | +- `[evaluate]` adds the ability to run evaluation and calculate metrics in your local development environment. |
| 49 | +- `[promptflow]` adds the ability to develop with prompt flow connected to your Azure AI project. |
| 50 | + |
| 51 | + |
| 52 | +## Usage |
| 53 | + |
| 54 | + |
| 55 | +### Connecting to Projects |
| 56 | +The generative package includes the [azure-ai-resources](https://pypi.org/project/azure-ai-resources) package and uses the `AIClient` for connecting to your project. |
| 57 | + |
| 58 | +First, create an `AI Client`: |
| 59 | + |
| 60 | +```python |
| 61 | +from azure.ai.resources.client import AIClient |
| 62 | +from azure.identity import DefaultAzureCredential |
| 63 | + |
| 64 | +ai_client = AIClient( |
| 65 | + credential=DefaultAzureCredential(), |
| 66 | + subscription_id='subscription_id', |
| 67 | + resource_group_name='resource_group', |
| 68 | + project_name='project_name' |
| 69 | +) |
| 70 | +``` |
| 71 | + |
| 72 | +### Using the generative package |
| 73 | + |
| 74 | +Azure AI Generative Python SDK offers the following key capabilities. |
| 75 | + |
| 76 | +To build an index locally, import the `build_index` function: |
| 77 | + |
| 78 | +```python |
| 79 | +from azure.ai.generative.index import build_index |
| 80 | +``` |
| 81 | + |
| 82 | +To run a local evaluation, import the `evaluate` function: |
| 83 | +```python |
| 84 | +from azure.ai.generative.evaluate import evaluate |
| 85 | +``` |
| 86 | + |
| 87 | +To deploy chat functions and prompt flows, import the `deploy` function: |
| 88 | +```python |
| 89 | +from azure.ai.resources.entities.deployment import Deployment |
| 90 | +``` |
| 91 | + |
| 92 | + |
| 93 | +## Examples |
| 94 | + |
| 95 | +See our [samples repository](https://github.com/Azure-Samples/azureai-samples) for examples of how to use the Azure AI Generative Python SDK. |
| 96 | + |
| 97 | +## Logs and telemetry |
| 98 | + |
| 99 | +### General |
| 100 | + |
| 101 | +Azure AI clients raise exceptions defined in Azure Core. |
| 102 | + |
| 103 | +```python |
| 104 | +from azure.core.exceptions import HttpResponseError |
| 105 | + |
| 106 | +try: |
| 107 | + ai_client.compute.get("cpu-cluster") |
| 108 | +except HttpResponseError as error: |
| 109 | + print("Request failed: {}".format(error.message)) |
| 110 | +``` |
| 111 | + |
| 112 | +### Logging |
| 113 | + |
| 114 | +This library uses the standard logging library for logging. Basic information about HTTP sessions (URLs, headers, etc.) is logged at INFO level. |
| 115 | + |
| 116 | +Detailed `DEBUG` level logging, including request/response bodies and unredacted headers, can be enabled on a client with the `logging_enable` argument. |
| 117 | + |
| 118 | + |
| 119 | +### Telemetry |
| 120 | + |
| 121 | +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. |
| 122 | + |
| 123 | +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, set the environment variable `"AZURE_AI_GENERATIVE_ENABLE_LOGGING"` to `"False"`. |
| 124 | + |
| 125 | + |
| 126 | +## Next steps |
| 127 | + |
| 128 | +- [Get started building a sample copilot application](https://github.com/azure/aistudio-copilot-sample) |
| 129 | +- [Get started with the Azure AI SDK](./sdk-install.md) |
| 130 | +- [Azure SDK for Python reference documentation](/python/api/overview/azure/ai) |
0 commit comments