Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "2722b419",
"metadata": {},
"source": [
"[![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",
"\n",
"\n",
"# <a id=\"top\">Azure Content Understanding tracing quickstart</a>\n",
"\n",
"This notebook illustrates how to get started monitoring Azure Content Understanding with Openlayer."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "020c8f6a",
"metadata": {},
"outputs": [],
"source": [
"!pip install openlayer azure-ai-contentunderstanding azure-identity"
]
},
{
"cell_type": "markdown",
"id": "75c2a473",
"metadata": {},
"source": [
"## 1. Set the environment variables"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f3f4fa13",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"# Azure Content Understanding env variables\n",
"os.environ[\"AZURE_CONTENT_UNDERSTANDING_ENDPOINT\"] = \"YOUR_AZURE_CONTENT_UNDERSTANDING_ENDPOINT_HERE\"\n",
"os.environ[\"AZURE_CONTENT_UNDERSTANDING_KEY\"] = \"YOUR_AZURE_CONTENT_UNDERSTANDING_KEY_HERE\"\n",
"\n",
"# Openlayer env variables\n",
"os.environ[\"OPENLAYER_API_KEY\"] = \"YOUR_OPENLAYER_API_KEY_HERE\"\n",
"os.environ[\"OPENLAYER_INFERENCE_PIPELINE_ID\"] = \"YOUR_OPENLAYER_INFERENCE_PIPELINE_ID_HERE\""
]
},
{
"cell_type": "markdown",
"id": "9758533f",
"metadata": {},
"source": [
"## 2. Import the `trace_azure_content_understanding` function and create the client"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e60584fa",
"metadata": {},
"outputs": [],
"source": [
"from azure.core.credentials import AzureKeyCredential\n",
"from azure.ai.contentunderstanding import ContentUnderstandingClient\n",
"from azure.ai.contentunderstanding.models import AnalysisInput\n",
"\n",
"from openlayer.lib import configure, trace_azure_content_understanding\n",
"\n",
"# Configure if you want to upload documents to Openlayer storage\n",
"configure(\n",
" attachment_upload_enabled=True, # upload binary/file attachments\n",
" url_upload_enabled=True, # also download & re-upload external URLs\n",
")\n",
"\n",
"client = trace_azure_content_understanding(\n",
" ContentUnderstandingClient(\n",
" endpoint=os.environ.get(\"AZURE_CONTENT_UNDERSTANDING_ENDPOINT\"),\n",
" credential=AzureKeyCredential(os.environ.get(\"AZURE_CONTENT_UNDERSTANDING_KEY\")),\n",
" api_version=\"2025-11-01\",\n",
" )\n",
")"
]
},
{
"cell_type": "markdown",
"id": "72a6b954",
"metadata": {},
"source": [
"## 3. Use your traced client normally"
]
},
{
"cell_type": "markdown",
"id": "76a350b4",
"metadata": {},
"source": [
"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!"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e00c1c79",
"metadata": {},
"outputs": [],
"source": [
"analyzer_id = \"prebuilt-read\"\n",
"url = \"https://contentunderstanding.ai.azure.com/assets/prebuilt/read_healthcare.png\"\n",
"\n",
"poller = client.begin_analyze(\n",
" analyzer_id=analyzer_id,\n",
" inputs=[AnalysisInput(url=url)],\n",
")\n",
"result = poller.result()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "abaf6987-c257-4f0d-96e7-3739b24c7206",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "hr-benefits",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
21 changes: 21 additions & 0 deletions src/openlayer/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"trace_async_openai",
"trace_async",
"trace_bedrock",
"trace_azure_content_understanding",
"trace_oci_genai",
"trace_oci", # Alias for backward compatibility
"trace_litellm",
Expand Down Expand Up @@ -138,6 +139,26 @@ def trace_bedrock(client):
return bedrock_tracer.trace_bedrock(client)


def trace_azure_content_understanding(client):
"""Trace Azure Content Understanding analyses."""
# pylint: disable=import-outside-toplevel
try:
from azure.ai.contentunderstanding import ContentUnderstandingClient
except ImportError:
raise ImportError(
"azure-ai-contentunderstanding is required for Azure Content Understanding tracing. "
"Install with: pip install azure-ai-contentunderstanding"
)

from .integrations import azure_content_understanding_tracer

if not isinstance(client, ContentUnderstandingClient):
raise ValueError(
"Invalid client. Please provide a ContentUnderstandingClient."
)
return azure_content_understanding_tracer.trace_azure_content_understanding(client)


def trace_oci_genai(client, estimate_tokens: bool = True):
"""Trace OCI GenAI chat completions.

Expand Down
Loading