Skip to content

Commit 0049a8d

Browse files
feat(closes OPEN-10097): create Azure Content Understanding tracer
1 parent 60c4841 commit 0049a8d

File tree

3 files changed

+530
-0
lines changed

3 files changed

+530
-0
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "2722b419",
6+
"metadata": {},
7+
"source": [
8+
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openlayer-ai/openlayer-python/blob/main/examples/tracing/azure-content-understanding/azure_content_understanding_tracing.ipynb)\n",
9+
"\n",
10+
"\n",
11+
"# <a id=\"top\">Azure Content Understanding tracing quickstart</a>\n",
12+
"\n",
13+
"This notebook illustrates how to get started monitoring Azure Content Understanding with Openlayer."
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": null,
19+
"id": "020c8f6a",
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"!pip install openlayer azure-ai-contentunderstanding azure-identity"
24+
]
25+
},
26+
{
27+
"cell_type": "markdown",
28+
"id": "75c2a473",
29+
"metadata": {},
30+
"source": [
31+
"## 1. Set the environment variables"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": null,
37+
"id": "f3f4fa13",
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"import os\n",
42+
"\n",
43+
"# Azure Content Understanding env variables\n",
44+
"os.environ[\"AZURE_CONTENT_UNDERSTANDING_ENDPOINT\"] = \"YOUR_AZURE_CONTENT_UNDERSTANDING_ENDPOINT_HERE\"\n",
45+
"os.environ[\"AZURE_CONTENT_UNDERSTANDING_KEY\"] = \"YOUR_AZURE_CONTENT_UNDERSTANDING_KEY_HERE\"\n",
46+
"\n",
47+
"# Openlayer env variables\n",
48+
"os.environ[\"OPENLAYER_API_KEY\"] = \"YOUR_OPENLAYER_API_KEY_HERE\"\n",
49+
"os.environ[\"OPENLAYER_INFERENCE_PIPELINE_ID\"] = \"YOUR_OPENLAYER_INFERENCE_PIPELINE_ID_HERE\""
50+
]
51+
},
52+
{
53+
"cell_type": "markdown",
54+
"id": "9758533f",
55+
"metadata": {},
56+
"source": [
57+
"## 2. Import the `trace_azure_content_understanding` function and create the client"
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": null,
63+
"id": "e60584fa",
64+
"metadata": {},
65+
"outputs": [],
66+
"source": [
67+
"from azure.ai.contentunderstanding import ContentUnderstandingClient\n",
68+
"from azure.core.credentials import AzureKeyCredential\n",
69+
"\n",
70+
"from openlayer.lib import trace_azure_content_understanding, configure\n",
71+
"\n",
72+
"# Configure if you want to upload documents to Openlayer storage\n",
73+
"configure(\n",
74+
" attachment_upload_enabled=True, # upload binary/file attachments\n",
75+
" url_upload_enabled=True, # also download & re-upload external URLs\n",
76+
" )\n",
77+
"\n",
78+
"client = trace_azure_content_understanding(\n",
79+
" ContentUnderstandingClient(\n",
80+
" endpoint=os.environ.get(\"AZURE_CONTENT_UNDERSTANDING_ENDPOINT\"),\n",
81+
" credential=AzureKeyCredential(os.environ.get(\"AZURE_CONTENT_UNDERSTANDING_KEY\")),\n",
82+
" api_version=\"2025-11-01\",\n",
83+
" )\n",
84+
")"
85+
]
86+
},
87+
{
88+
"cell_type": "markdown",
89+
"id": "72a6b954",
90+
"metadata": {},
91+
"source": [
92+
"## 3. Use your traced client normally"
93+
]
94+
},
95+
{
96+
"cell_type": "markdown",
97+
"id": "76a350b4",
98+
"metadata": {},
99+
"source": [
100+
"That's it! Now you can continue using your Azure Content Understanding client normally. The data is automatically published to Openlayer and you can start creating tests around it!"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": null,
106+
"id": "e00c1c79",
107+
"metadata": {},
108+
"outputs": [],
109+
"source": [
110+
"from azure.ai.contentunderstanding.models import AnalysisInput\n",
111+
"\n",
112+
"analyzer_id = \"prebuilt-read\"\n",
113+
"url = \"https://contentunderstanding.ai.azure.com/assets/prebuilt/read_healthcare.png\"\n",
114+
"\n",
115+
"\n",
116+
"poller = client.begin_analyze(\n",
117+
" analyzer_id=analyzer_id,\n",
118+
" inputs=[AnalysisInput(url=url)],\n",
119+
")\n",
120+
"result = poller.result()"
121+
]
122+
},
123+
{
124+
"cell_type": "code",
125+
"execution_count": null,
126+
"id": "abaf6987-c257-4f0d-96e7-3739b24c7206",
127+
"metadata": {},
128+
"outputs": [],
129+
"source": []
130+
}
131+
],
132+
"metadata": {
133+
"kernelspec": {
134+
"display_name": "hr-benefits",
135+
"language": "python",
136+
"name": "python3"
137+
},
138+
"language_info": {
139+
"codemirror_mode": {
140+
"name": "ipython",
141+
"version": 3
142+
},
143+
"file_extension": ".py",
144+
"mimetype": "text/x-python",
145+
"name": "python",
146+
"nbconvert_exporter": "python",
147+
"pygments_lexer": "ipython3",
148+
"version": "3.12.13"
149+
}
150+
},
151+
"nbformat": 4,
152+
"nbformat_minor": 5
153+
}

src/openlayer/lib/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"trace_async_openai",
1212
"trace_async",
1313
"trace_bedrock",
14+
"trace_azure_content_understanding",
1415
"trace_oci_genai",
1516
"trace_oci", # Alias for backward compatibility
1617
"trace_litellm",
@@ -138,6 +139,26 @@ def trace_bedrock(client):
138139
return bedrock_tracer.trace_bedrock(client)
139140

140141

142+
def trace_azure_content_understanding(client):
143+
"""Trace Azure Content Understanding analyses."""
144+
# pylint: disable=import-outside-toplevel
145+
try:
146+
from azure.ai.contentunderstanding import ContentUnderstandingClient
147+
except ImportError:
148+
raise ImportError(
149+
"azure-ai-contentunderstanding is required for Azure Content Understanding tracing. "
150+
"Install with: pip install azure-ai-contentunderstanding"
151+
)
152+
153+
from .integrations import azure_content_understanding_tracer
154+
155+
if not isinstance(client, ContentUnderstandingClient):
156+
raise ValueError(
157+
"Invalid client. Please provide a ContentUnderstandingClient."
158+
)
159+
return azure_content_understanding_tracer.trace_azure_content_understanding(client)
160+
161+
141162
def trace_oci_genai(client, estimate_tokens: bool = True):
142163
"""Trace OCI GenAI chat completions.
143164

0 commit comments

Comments
 (0)