Package: azure-ai-generative
Azure AI Generative Package client library for PythonThe 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 leverage 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|Product documentation|SamplesThis package has been tested with Python 3.8, 3.9, 3.10, 3.11 and 3.12.For a more complete set of Azure libraries, seehttps://aka.ms/azsdk/python/all.Getting startedPrerequisitesPython 3.7 or later is required to use this package.You must have anAzure subscription.AnAzure Machine Learning Workspace.AnAzure AI Studio project.Install the packageInstall the Azure AI generative package for Python with pip:pip install azure-ai-generative[index,evaluate,promptflow]
pip install azure-identityKey conceptsThe[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 projectUsageConnecting to ProjectsThe generative package includes the azure-ai-resources package and uses theAIClientfor connecting to your project.First, create anAI Client:fromazure.ai.resources.clientimportAIClientfromazure.identityimportDefaultAzureCredentialai_client=AIClient(credential=DefaultAzureCredential(),subscription_id='subscription_id',resource_group_name='resource_group',project_name='project_name')Using the generative packageAzure AI Generative Python SDK offers the following key capabilities.To build an index locally, import the build_index function:fromazure.ai.generative.indeximportbuild_indexTo run a local evaluation, import the evaluate function:fromazure.ai.generative.evaluateimportevaluateTo deploy chat functions and prompt flows, import the deploy function:fromazure.ai.resources.entities.deploymentimportDeploymentFor sample usage of these, refer to this sampleExamplesSee oursamples repositoryfor examples of how to use the Azure AI Generative Python SDK.TroubleshootingGeneralAzure AI clients raise exceptions defined in Azure Core.fromazure.core.exceptionsimportHttpResponseErrortry:ai_client.compute.get("cpu-cluster")exceptHttpResponseErroraserror:print("Request failed:{}".format(error.message))LoggingThis 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 thelogging_enableargument.See full SDK logging documentation with examples here.TelemetryThe 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 will not 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 cannot 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".Next stepsSee oursamples repositoryfor examples of how to use the Azure AI Generative Python SDK.ContributingIf you encounter any bugs or have suggestions, please file an issue in theIssuessection of the project.Release History1.0.0b7 (2024-02-07)Other ChangesBug fixes1.0.0b6 (2024-02-06)Other ChangesRecursive Text Splitter is now enabled by default for local index builds which mimics behavior of cloud index buildsBug fixes1.0.0b5 (2024-02-02)Features AddedSupports evaluate() on chatBugs FixedFix promptflow evaluation bugsOther ChangesDuplicate cleanup1.0.0b4 (2024-02-01)Features AddedSupport custom metrics for evaluationOther ChangesSwitched evaluate() function to run on promptflow engineUse openai v1 environment variable1.0.0b3 (2024-01-30)Other ChangesSupport for Python 3.121.0.0b2 (2023-11-30)Features AddedAdded new format to export data to in qa generator.Other ChangesDependency improvements.1.0.0b1 (2023-11-10)Features AddedTry use langchain VectorStore and fallback to vendor.Add azure-search-documents 11.4.0b11 and above support.Invoke OpenAI with dynamic batch size.Fix LangChain importing pathFirst preview.