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
1 change: 1 addition & 0 deletions .github/workflows/update-labs-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ on:
permissions:
contents: write
pull-requests: write
issues: write

jobs:
update-labs-config:
Expand Down
4 changes: 2 additions & 2 deletions docs/labs-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@
"authors": [
"vieiraae"
],
"githubPath": "https://github.com/Azure-Samples/AI-Gateway/tree/main/labs/content-safety",
"githubPath": "https://github.com/seilorjunior/AI-Gateway/tree/main/labs/content-safety",
"tags": [],
"lastCommitDate": "2026-02-04T13:09:52.730Z"
"lastCommitDate": "2026-02-19T18:19:32.694Z"
},
{
"id": "finops-framework",
Expand Down
3 changes: 1 addition & 2 deletions labs/backend-pool-load-balancing-tf/policy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<backend>
<retry count="2"
interval="0"
first-fast-retry="true"
condition="@(context.Response.StatusCode == 429 || (context.Response.StatusCode == 503 && !context.Response.StatusReason.Contains("Backend pool") && !context.Response.StatusReason.Contains("is temporarily unavailable")))">
first-fast-retry="true" condition="@(context.Response.StatusCode == 429 || context.Response.StatusCode == 503)">
<forward-request buffer-request-body="true" />
</retry>
</backend>
Expand Down
2 changes: 1 addition & 1 deletion labs/backend-pool-load-balancing/policy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</inbound>
<backend>
<!--Set count to one less than the number of backends in the pool to try all backends until the backend pool is temporarily unavailable.-->
<retry count="2" interval="0" first-fast-retry="true" condition="@(context.Response.StatusCode == 429 || (context.Response.StatusCode == 503 && !context.Response.StatusReason.Contains("Backend pool") && !context.Response.StatusReason.Contains("is temporarily unavailable")))">
<retry count="2" interval="0" first-fast-retry="true" condition="@(context.Response.StatusCode == 429 || context.Response.StatusCode == 503)">
<!--Switch back to same backend pool which will have automatically removed the faulty backend -->
<set-backend-service backend-id="{backend-id}" />
<forward-request buffer-request-body="true" />
Expand Down
42 changes: 35 additions & 7 deletions labs/content-safety/content-safety.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"metadata": {}
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ \u001b[1;32mNotebook initialized\u001b[0m ⌚ 14:09:29.586513 \n"
]
}
],
"source": [
"import os, sys, json\n",
"sys.path.insert(1, '../../shared') # add the shared directory to the Python path\n",
Expand Down Expand Up @@ -81,9 +89,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"⚙️ \u001b[1;34mRunning: az account show \u001b[0m\n",
"✅ \u001b[1;32mRetrieved az account\u001b[0m ⌚ 14:09:39.477474 [0m:4s]\n",
"👉🏽 \u001b[1;34mCurrent user: seilorjunior@microsoft.com\u001b[0m\n",
"👉🏽 \u001b[1;34mTenant ID: 16b3c013-d300-468d-ac64-7eda0820b6d3\u001b[0m\n",
"👉🏽 \u001b[1;34mSubscription ID: 08a7f106-3eed-4add-8328-3d18b01d8ef1\u001b[0m\n"
]
}
],
"source": [
"output = utils.run(\"az account show\", \"Retrieved az account\", \"Failed to get the current az account\")\n",
"\n",
Expand Down Expand Up @@ -111,7 +131,15 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"⚙️ \u001b[1;34mRunning: az group show --name lab-content-safety \u001b[0m\n"
]
}
],
"source": [
"# Create the resource group if doesn't exist\n",
"utils.create_resource_group(resource_group_name, resource_group_location)\n",
Expand Down Expand Up @@ -226,7 +254,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "myenv",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -240,7 +268,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.5"
"version": "3.13.12"
}
},
"nbformat": 4,
Expand Down
33 changes: 18 additions & 15 deletions labs/content-safety/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,8 @@ module foundryModule '../../modules/cognitive-services/v3/foundry.bicep' = {
}
}

// 3. APIM Inference API
module inferenceAPIModule '../../modules/apim/v2/inference-api.bicep' = {
name: 'inferenceAPIModule'
params: {
policyXml: loadTextContent('policy.xml')
aiServicesConfig: foundryModule.outputs.extendedAIServicesConfig
inferenceAPIType: inferenceAPIType
inferenceAPIPath: inferenceAPIPath
configureCircuitBreaker: true
}
}

resource apim 'Microsoft.ApiManagement/service@2024-06-01-preview' existing = {
name: 'apim-${resourceSuffix}'
dependsOn: [
inferenceAPIModule
]
}

// 4. Content Safety
Expand Down Expand Up @@ -146,6 +131,24 @@ resource contentSafetyBackend 'Microsoft.ApiManagement/service/backends@2024-06-
}
}
}
dependsOn: [
apimModule
]
}

// 3. APIM Inference API - Must be deployed after Content Safety backend
module inferenceAPIModule '../../modules/apim/v2/inference-api.bicep' = {
name: 'inferenceAPIModule'
params: {
policyXml: loadTextContent('policy.xml')
aiServicesConfig: foundryModule.outputs.extendedAIServicesConfig
inferenceAPIType: inferenceAPIType
inferenceAPIPath: inferenceAPIPath
configureCircuitBreaker: true
}
dependsOn: [
contentSafetyBackend
]
}

// ------------------
Expand Down