{ "cells": [ { "cell_type": "markdown", "id": "61b569f7", "metadata": {}, "source": [ "\n", "Basic Usage\n", "------------\n", "\n", "Here's how to use the basic functionality of ai_sentinel:" ] }, { "cell_type": "code", "execution_count": null, "id": "266bd5d3", "metadata": {}, "outputs": [], "source": [ "from ai_sentinel import AzureOpenAIClient, ToxicityGuard\n", "\n", "# Initialize LLM client\n", "client = AzureOpenAIClient(\n", " api_key=\"YOUR-API-KEY\",\n", " model=\"gpt-4o-mini\",\n", " api_version=\"2024-02-01\",\n", " azure_endpoint=\"https://your-resource.openai.azure.com/\"\n", ")\n", "\n", "# Create toxicity guard\n", "guard = ToxicityGuard(client)\n", "\n", "# Analyze text\n", "result = guard.analyze(\"This is a normal message\")\n", "\n", "print(f\"Is toxic: {result.is_toxic}\")\n", "print(f\"Confidence: {result.confidence}\")\n", "print(f\"Categories: {result.categories}\")\n", "print(f\"Reason: {result.reason}\")\n", "print(f\"Severity: {result.score}\")\n" ] }, { "cell_type": "markdown", "id": "633dcc5c", "metadata": {}, "source": [ "Async Usage\n", "------------\n", "\n", "Generate text and validate responses asynchronously." ] }, { "cell_type": "code", "execution_count": null, "id": "bcfb5194", "metadata": {}, "outputs": [], "source": [ "import asyncio\n", "from ai_sentinel import AzureOpenAIClient, ToxicityGuard\n", "\n", "client = AzureOpenAIClient(\n", " api_key=\"YOUR-API-KEY\",\n", " model=\"gpt-4o-mini\",\n", " api_version=\"2024-02-01\",\n", " azure_endpoint=\"https://your-resource.openai.azure.com/\"\n", ")\n", "\n", "async def main() -> None:\n", " guard = ToxicityGuard(client)\n", " response = await guard.analyze_async(\"Text to analyze\")\n", "\n", " print(f\"Is toxic: {result.is_toxic}\")\n", " print(f\"Confidence: {result.confidence}\")\n", " print(f\"Categories: {result.categories}\")\n", " print(f\"Reason: {result.reason}\")\n", " print(f\"Severity: {result.score}\")\n", "\n", "asyncio.run(main()) " ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }