Skip to content

Commit 4a6a8e3

Browse files
committed
Update docs metadata
1 parent 94fa30e commit 4a6a8e3

File tree

2 files changed

+117
-23
lines changed

2 files changed

+117
-23
lines changed

docs-ref-services/preview/ai-inference-readme.md

Lines changed: 105 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
title: Azure AI Inference client library for Python
33
keywords: Azure, python, SDK, API, azure-ai-inference, ai
4-
ms.date: 08/28/2024
4+
ms.date: 10/16/2024
55
ms.topic: reference
66
ms.devlang: python
77
ms.service: ai
88
---
9-
# Azure AI Inference client library for Python - version 1.0.0b4
9+
# Azure AI Inference client library for Python - version 1.0.0b5
1010

1111

1212
Use the Inference client library (in preview) to:
@@ -21,15 +21,15 @@ The Inference client library supports AI models deployed to the following servic
2121

2222
* [GitHub Models](https://github.com/marketplace/models) - Free-tier endpoint for AI models from different providers
2323
* Serverless API endpoints and Managed Compute endpoints - AI models from different providers deployed from [Azure AI Studio](https://ai.azure.com). See [Overview: Deploy models, flows, and web apps with Azure AI Studio](https://learn.microsoft.com/azure/ai-studio/concepts/deployments-overview).
24-
* Azure OpenAI Service - OpenAI models deployed from [Azure OpenAI Studio](https://oai.azure.com/). See [What is Azure OpenAI Service?](https://learn.microsoft.com/azure/ai-services/openai/overview). Although we recomendation you use the official [OpenAI client library](https://pypi.org/project/openai/) in your production code for this service, you can use the Azure AI Inference client library to easily compare the performance of OpenAI models to other models, using the same client library and Python code.
24+
* Azure OpenAI Service - OpenAI models deployed from [Azure OpenAI Studio](https://oai.azure.com/). See [What is Azure OpenAI Service?](https://learn.microsoft.com/azure/ai-services/openai/overview). Although we recommend you use the official [OpenAI client library](https://pypi.org/project/openai/) in your production code for this service, you can use the Azure AI Inference client library to easily compare the performance of OpenAI models to other models, using the same client library and Python code.
2525

2626
The Inference client library makes services calls using REST API version `2024-05-01-preview`, as documented in [Azure AI Model Inference API](https://aka.ms/azureai/modelinference).
2727

2828
[Product documentation](https://aka.ms/azureai/modelinference)
29-
| [Samples](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b4/sdk/ai/azure-ai-inference/samples)
29+
| [Samples](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b5/sdk/ai/azure-ai-inference/samples)
3030
| [API reference documentation](https://aka.ms/azsdk/azure-ai-inference/python/reference)
3131
| [Package (Pypi)](https://aka.ms/azsdk/azure-ai-inference/python/package)
32-
| [SDK source code](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b4/sdk/ai/azure-ai-inference/azure/ai/inference)
32+
| [SDK source code](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b5/sdk/ai/azure-ai-inference/azure/ai/inference)
3333

3434
## Getting started
3535

@@ -50,7 +50,7 @@ Studio.
5050
* An [OpenAI Model from the catalog](https://oai.azure.com/resource/models) deployed through Azure OpenAI Studio.
5151
* The endpoint URL of your model, in the form `https://<your-resouce-name>.openai.azure.com/openai/deployments/<your-deployment-name>`, where `your-resource-name` is your globally unique AOAI resource name, and `your-deployment-name` is your AI Model deployment name.
5252
* Depending on your authentication preference, you either need an API key to authenticate against the service, or Entra ID credentials. The API key is a 32-character string.
53-
* An api-version. Latest preview or GA version listed in the `Data plane - inference` row in [the API Specs table](https://learn.microsoft.com/azure/ai-services/openai/reference#api-specs). At the time of writing, latest GA version was "2024-06-01".
53+
* An api-version. Latest preview or GA version listed in the `Data plane - inference` row in [the API Specs table](https://aka.ms/azsdk/azure-ai-inference/azure-openai-api-versions). At the time of writing, latest GA version was "2024-06-01".
5454

5555
### Install the package
5656

@@ -66,6 +66,12 @@ To update an existing installation of the package, use:
6666
pip install --upgrade azure-ai-inference
6767
```
6868

69+
If you want to install Azure AI Inferencing package with support for OpenTelemetry based tracing, use the following command:
70+
71+
```bash
72+
pip install azure-ai-inference[opentelemetry]
73+
```
74+
6975
## Key concepts
7076

7177
### Create and authenticate a client directly, using API key or GitHub token
@@ -92,9 +98,8 @@ client = ChatCompletionsClient(
9298
# For Azure OpenAI endpoint
9399
client = ChatCompletionsClient(
94100
endpoint=endpoint, # Of the form https://<your-resouce-name>.openai.azure.com/openai/deployments/<your-deployment-name>
95-
credential=AzureKeyCredential(""), # Pass in an empty value.
96-
headers={"api-key": key},
97-
api_version="2024-06-01", # AOAI api-version. Update as needed.
101+
credential=AzureKeyCredential(key),
102+
api_version="2024-06-01", # Azure OpenAI api-version. See https://aka.ms/azsdk/azure-ai-inference/azure-openai-api-versions
98103
)
99104
```
100105

@@ -124,13 +129,13 @@ client = ChatCompletionsClient(
124129

125130
_Note: At the time of writing, only Managed Compute endpoints and Azure OpenAI endpoints support Entra ID authentication.
126131

127-
To use an Entra ID token credential, first install the [azure-identity](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b4/sdk/identity/azure-identity) package:
132+
To use an Entra ID token credential, first install the [azure-identity](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b5/sdk/identity/azure-identity) package:
128133

129134
```python
130135
pip install azure.identity
131136
```
132137

133-
You will need to provide the desired credential type obtained from that package. A common selection is [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b4/sdk/identity/azure-identity#defaultazurecredential) and it can be used as follows:
138+
You will need to provide the desired credential type obtained from that package. A common selection is [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b5/sdk/identity/azure-identity#defaultazurecredential) and it can be used as follows:
134139

135140
```python
136141
from azure.ai.inference import ChatCompletionsClient
@@ -147,7 +152,7 @@ client = ChatCompletionsClient(
147152
endpoint=endpoint,
148153
credential=DefaultAzureCredential(exclude_interactive_browser_credential=False),
149154
credential_scopes=["https://cognitiveservices.azure.com/.default"],
150-
api_version="2024-06-01", # AOAI api-version. Update as needed.
155+
api_version="2024-06-01", # Azure OpenAI api-version. See https://aka.ms/azsdk/azure-ai-inference/azure-openai-api-versions
151156
)
152157
```
153158

@@ -220,13 +225,13 @@ AI model information is displayed (if available) when you `print(client)`.
220225

221226
The `ChatCompletionsClient` has a method named `complete`. The method makes a REST API call to the `/chat/completions` route on the provided endpoint, as documented in [the REST API reference](https://learn.microsoft.com/azure/ai-studio/reference/reference-model-inference-chat-completions).
222227

223-
See simple chat completion examples below. More can be found in the [samples](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b4/sdk/ai/azure-ai-inference/samples) folder.
228+
See simple chat completion examples below. More can be found in the [samples](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b5/sdk/ai/azure-ai-inference/samples) folder.
224229

225230
### Text Embeddings
226231

227232
The `EmbeddingsClient` has a method named `embedding`. The method makes a REST API call to the `/embeddings` route on the provided endpoint, as documented in [the REST API reference](https://learn.microsoft.com/azure/ai-studio/reference/reference-model-inference-embeddings).
228233

229-
See simple text embedding example below. More can be found in the [samples](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b4/sdk/ai/azure-ai-inference/samples) folder.
234+
See simple text embedding example below. More can be found in the [samples](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b5/sdk/ai/azure-ai-inference/samples) folder.
230235

231236
<!--
232237
### Image Embeddings
@@ -250,7 +255,7 @@ The examples create a synchronous client assuming a Serverless API or Managed Co
250255
construction code as descirbed in [Key concepts](#key-concepts) to have it work with GitHub Models endpoint or Azure OpenAI
251256
endpoint. Only mandatory input settings are shown for simplicity.
252257

253-
See the [Samples](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b4/sdk/ai/azure-ai-inference/samples) folder for full working samples for synchronous and asynchronous clients.
258+
See the [Samples](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b5/sdk/ai/azure-ai-inference/samples) folder for full working samples for synchronous and asynchronous clients.
254259

255260
### Chat completions example
256261

@@ -279,10 +284,10 @@ print(response.choices[0].message.content)
279284

280285
The following types or messages are supported: `SystemMessage`,`UserMessage`, `AssistantMessage`, `ToolMessage`. See also samples:
281286

282-
* [sample_chat_completions_with_tools.py](https://github.com/Azure/azure-sdk-for-python/blob/azure-ai-inference_1.0.0b4/sdk/ai/azure-ai-inference/samples/sample_chat_completions_with_tools.py) for usage of `ToolMessage`.
283-
* [sample_chat_completions_with_image_url.py](https://github.com/Azure/azure-sdk-for-python/blob/azure-ai-inference_1.0.0b4/sdk/ai/azure-ai-inference/samples/sample_chat_completions_with_image_url.py) for usage of `UserMessage` that
287+
* [sample_chat_completions_with_tools.py](https://github.com/Azure/azure-sdk-for-python/blob/azure-ai-inference_1.0.0b5/sdk/ai/azure-ai-inference/samples/sample_chat_completions_with_tools.py) for usage of `ToolMessage`.
288+
* [sample_chat_completions_with_image_url.py](https://github.com/Azure/azure-sdk-for-python/blob/azure-ai-inference_1.0.0b5/sdk/ai/azure-ai-inference/samples/sample_chat_completions_with_image_url.py) for usage of `UserMessage` that
284289
includes sending an image URL.
285-
* [sample_chat_completions_with_image_data.py](https://github.com/Azure/azure-sdk-for-python/blob/azure-ai-inference_1.0.0b4/sdk/ai/azure-ai-inference/samples/sample_chat_completions_with_image_data.py) for usage of `UserMessage` that
290+
* [sample_chat_completions_with_image_data.py](https://github.com/Azure/azure-sdk-for-python/blob/azure-ai-inference_1.0.0b5/sdk/ai/azure-ai-inference/samples/sample_chat_completions_with_image_data.py) for usage of `UserMessage` that
286291
includes sending image data read from a local file.
287292

288293
Alternatively, you can provide the messages as dictionary instead of using the strongly typed classes like `SystemMessage` and `UserMessage`:
@@ -539,9 +544,90 @@ For more information, see [Configure logging in the Azure libraries for Python](
539544

540545
To report issues with the client library, or request additional features, please open a GitHub issue [here](https://github.com/Azure/azure-sdk-for-python/issues)
541546

547+
## Tracing
548+
549+
The Azure AI Inferencing API Tracing library provides tracing for Azure AI Inference client library for Python. Refer to Installation chapter above for installation instructions.
550+
551+
### Setup
552+
553+
The environment variable AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED controls whether the actual message contents will be recorded in the traces or not. By default, the message contents are not recorded as part of the trace. When message content recording is disabled any function call tool related function names, function parameter names and function parameter values are also not recorded in the trace. Set the value of the environment variable to "true" (case insensitive) for the message contents to be recorded as part of the trace. Any other value will cause the message contents not to be recorded.
554+
555+
You also need to configure the tracing implementation in your code by setting `AZURE_SDK_TRACING_IMPLEMENTATION` to `opentelemetry` or configuring it in the code with the following snippet:
556+
557+
<!-- SNIPPET:sample_chat_completions_with_tracing.trace_setting -->
558+
559+
```python
560+
from azure.core.settings import settings
561+
settings.tracing_implementation = "opentelemetry"
562+
```
563+
564+
<!-- END SNIPPET -->
565+
566+
Please refer to [azure-core-tracing-documentation](https://learn.microsoft.com/python/api/overview/azure/core-tracing-opentelemetry-readme) for more information.
567+
568+
### Exporting Traces with OpenTelemetry
569+
570+
Azure AI Inference is instrumented with OpenTelemetry. In order to enable tracing you need to configure OpenTelemetry to export traces to your observability backend.
571+
Refer to [Azure SDK tracing in Python](https://learn.microsoft.com/python/api/overview/azure/core-tracing-opentelemetry-readme?view=azure-python-preview) for more details.
572+
573+
Refer to [Azure Monitor OpenTelemetry documentation](https://learn.microsoft.com/azure/azure-monitor/app/opentelemetry-enable?tabs=python) for the details on how to send Azure AI Inference traces to Azure Monitor and create Azure Monitor resource.
574+
575+
### Instrumentation
576+
577+
Use the AIInferenceInstrumentor to instrument the Azure AI Inferencing API for LLM tracing, this will cause the LLM traces to be emitted from Azure AI Inferencing API.
578+
579+
<!-- SNIPPET:sample_chat_completions_with_tracing.instrument_inferencing -->
580+
581+
```python
582+
from azure.ai.inference.tracing import AIInferenceInstrumentor
583+
# Instrument AI Inference API
584+
AIInferenceInstrumentor().instrument()
585+
```
586+
587+
<!-- END SNIPPET -->
588+
589+
590+
It is also possible to uninstrument the Azure AI Inferencing API by using the uninstrument call. After this call, the traces will no longer be emitted by the Azure AI Inferencing API until instrument is called again.
591+
592+
<!-- SNIPPET:sample_chat_completions_with_tracing.uninstrument_inferencing -->
593+
594+
```python
595+
AIInferenceInstrumentor().uninstrument()
596+
```
597+
598+
<!-- END SNIPPET -->
599+
600+
### Tracing Your Own Functions
601+
The @tracer.start_as_current_span decorator can be used to trace your own functions. This will trace the function parameters and their values. You can also add further attributes to the span in the function implementation as demonstrated below. Note that you will have to setup the tracer in your code before using the decorator. More information is available [here](https://opentelemetry.io/docs/languages/python/).
602+
603+
<!-- SNIPPET:sample_chat_completions_with_tracing.trace_function -->
604+
605+
```python
606+
from opentelemetry.trace import get_tracer
607+
tracer = get_tracer(__name__)
608+
609+
# The tracer.start_as_current_span decorator will trace the function call and enable adding additional attributes
610+
# to the span in the function implementation. Note that this will trace the function parameters and their values.
611+
@tracer.start_as_current_span("get_temperature") # type: ignore
612+
def get_temperature(city: str) -> str:
613+
614+
# Adding attributes to the current span
615+
span = trace.get_current_span()
616+
span.set_attribute("requested_city", city)
617+
618+
if city == "Seattle":
619+
return "75"
620+
elif city == "New York City":
621+
return "80"
622+
else:
623+
return "Unavailable"
624+
```
625+
626+
<!-- END SNIPPET -->
627+
542628
## Next steps
543629

544-
* Have a look at the [Samples](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b4/sdk/ai/azure-ai-inference/samples) folder, containing fully runnable Python code for doing inference using synchronous and asynchronous clients.
630+
* Have a look at the [Samples](https://github.com/Azure/azure-sdk-for-python/tree/azure-ai-inference_1.0.0b5/sdk/ai/azure-ai-inference/samples) folder, containing fully runnable Python code for doing inference using synchronous and asynchronous clients.
545631

546632
## Contributing
547633

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Name": "azure-ai-inference",
3-
"Version": "1.0.0b4",
3+
"Version": "1.0.0b5",
44
"DevVersion": null,
55
"DirectoryPath": "sdk/ai/azure-ai-inference",
66
"ServiceDirectory": "ai",
@@ -10,9 +10,17 @@
1010
"SdkType": "client",
1111
"IsNewSdk": true,
1212
"ArtifactName": "azure-ai-inference",
13-
"ReleaseStatus": "2024-08-30",
14-
"DependentPackages": null,
13+
"ReleaseStatus": "2024-10-16",
14+
"IncludedForValidation": false,
15+
"AdditionalValidationPackages": [
16+
""
17+
],
18+
"ArtifactDetails": {
19+
"name": "azure-ai-inference",
20+
"safeName": "azureaiinference"
21+
},
1522
"Namespaces": [
1623
"azure.ai.inference"
17-
]
24+
],
25+
"DependentPackages": null
1826
}

0 commit comments

Comments
 (0)