-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/outbound-moderation' into develop
- Loading branch information
Showing
9 changed files
with
492 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
blocklist,word | ||
competitors,Aegon | ||
competitors,AIA Group | ||
competitors,Alleghany | ||
competitors,Allianz | ||
competitors,Allied World Assurance | ||
competitors,Allstate | ||
competitors,AmTrust Financial Services | ||
competitors,Arch Capital Group | ||
competitors,Argo Group International Holdings | ||
competitors,Aspen Insurance Holdings | ||
competitors,Assicurazioni Generali | ||
competitors,Assurant | ||
competitors,Aviva | ||
competitors,AXA | ||
competitors,Axis Capital Holdings | ||
competitors,Baldwin & Lyons | ||
competitors,China Life Insurance | ||
competitors,China Pacific Insurance | ||
competitors,Chubb | ||
competitors,Cincinnati Financial | ||
competitors,CNA Financial | ||
competitors,Endurance Specialty Holdings | ||
competitors,Everest Re Group | ||
competitors,Fairfax Financial Holdings | ||
competitors,Fidelity National Financial | ||
competitors,First American Financial | ||
competitors,Hanover Insurance Group | ||
competitors,HCC Insurance Holdings | ||
competitors,Legal & General Group | ||
competitors,Liberty Mutual | ||
competitors,Manulife Financial | ||
competitors,Markel | ||
competitors,Marsh & McLennan | ||
competitors,MetLife | ||
competitors,Munich Re | ||
competitors,New York Life Insurance | ||
competitors,Old Republic International | ||
competitors,PartnerRe | ||
competitors,Ping An Insurance | ||
competitors,Progressive | ||
competitors,Prudential Financial | ||
competitors,RenaissanceRe Holdings | ||
competitors,RSA Insurance Group | ||
competitors,Selective Insurance Group | ||
competitors,St. Paul Travelers | ||
competitors,State Farm Insurance | ||
competitors,Swiss Re | ||
competitors,The Hartford | ||
competitors,Torchmark | ||
competitors,Travelers | ||
competitors,Validus Holdings | ||
competitors,Willis Group Holdings | ||
competitors,Zurich Insurance Group |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 14, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Requirement already satisfied: azure-identity==1.15.0 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (1.15.0)\n", | ||
"Requirement already satisfied: azure-ai-contentsafety==1.0.0 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (1.0.0)\n", | ||
"Collecting pandas==2.2.0\n", | ||
" Using cached pandas-2.2.0-cp311-cp311-macosx_11_0_arm64.whl.metadata (19 kB)\n", | ||
"Requirement already satisfied: azure-core<2.0.0,>=1.23.0 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from azure-identity==1.15.0) (1.29.6)\n", | ||
"Requirement already satisfied: cryptography>=2.5 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from azure-identity==1.15.0) (41.0.1)\n", | ||
"Requirement already satisfied: msal<2.0.0,>=1.24.0 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from azure-identity==1.15.0) (1.25.0)\n", | ||
"Requirement already satisfied: msal-extensions<2.0.0,>=0.3.0 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from azure-identity==1.15.0) (1.0.0)\n", | ||
"Requirement already satisfied: isodate<1.0.0,>=0.6.1 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from azure-ai-contentsafety==1.0.0) (0.6.1)\n", | ||
"Requirement already satisfied: numpy<2,>=1.23.2 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from pandas==2.2.0) (1.26.1)\n", | ||
"Requirement already satisfied: python-dateutil>=2.8.2 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from pandas==2.2.0) (2.8.2)\n", | ||
"Requirement already satisfied: pytz>=2020.1 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from pandas==2.2.0) (2023.3)\n", | ||
"Requirement already satisfied: tzdata>=2022.7 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from pandas==2.2.0) (2023.3)\n", | ||
"Requirement already satisfied: anyio<5.0,>=3.0 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from azure-core<2.0.0,>=1.23.0->azure-identity==1.15.0) (3.7.1)\n", | ||
"Requirement already satisfied: requests>=2.21.0 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from azure-core<2.0.0,>=1.23.0->azure-identity==1.15.0) (2.31.0)\n", | ||
"Requirement already satisfied: six>=1.11.0 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from azure-core<2.0.0,>=1.23.0->azure-identity==1.15.0) (1.16.0)\n", | ||
"Requirement already satisfied: typing-extensions>=4.6.0 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from azure-core<2.0.0,>=1.23.0->azure-identity==1.15.0) (4.8.0)\n", | ||
"Requirement already satisfied: cffi>=1.12 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from cryptography>=2.5->azure-identity==1.15.0) (1.15.1)\n", | ||
"Requirement already satisfied: PyJWT<3,>=1.0.0 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from PyJWT[crypto]<3,>=1.0.0->msal<2.0.0,>=1.24.0->azure-identity==1.15.0) (2.8.0)\n", | ||
"Requirement already satisfied: portalocker<3,>=1.0 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from msal-extensions<2.0.0,>=0.3.0->azure-identity==1.15.0) (2.7.0)\n", | ||
"Requirement already satisfied: idna>=2.8 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from anyio<5.0,>=3.0->azure-core<2.0.0,>=1.23.0->azure-identity==1.15.0) (3.4)\n", | ||
"Requirement already satisfied: sniffio>=1.1 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from anyio<5.0,>=3.0->azure-core<2.0.0,>=1.23.0->azure-identity==1.15.0) (1.3.0)\n", | ||
"Requirement already satisfied: pycparser in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from cffi>=1.12->cryptography>=2.5->azure-identity==1.15.0) (2.21)\n", | ||
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from requests>=2.21.0->azure-core<2.0.0,>=1.23.0->azure-identity==1.15.0) (3.2.0)\n", | ||
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from requests>=2.21.0->azure-core<2.0.0,>=1.23.0->azure-identity==1.15.0) (1.26.16)\n", | ||
"Requirement already satisfied: certifi>=2017.4.17 in /Users/clemlesne/.pyenv/versions/3.11.3/lib/python3.11/site-packages (from requests>=2.21.0->azure-core<2.0.0,>=1.23.0->azure-identity==1.15.0) (2023.5.7)\n", | ||
"Using cached pandas-2.2.0-cp311-cp311-macosx_11_0_arm64.whl (11.8 MB)\n", | ||
"Installing collected packages: pandas\n", | ||
" Attempting uninstall: pandas\n", | ||
" Found existing installation: pandas 2.0.3\n", | ||
" Uninstalling pandas-2.0.3:\n", | ||
" Successfully uninstalled pandas-2.0.3\n", | ||
"Successfully installed pandas-2.2.0\n", | ||
"Note: you may need to restart the kernel to use updated packages.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%pip install azure-identity==1.15.0 azure-ai-contentsafety==1.0.0 pandas==2.2.0" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Initialize clients and access keys." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 32, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from azure.ai.contentsafety import BlocklistClient\n", | ||
"from azure.ai.contentsafety.models import TextBlocklist, TextBlocklistItem, AddOrUpdateTextBlocklistItemsOptions\n", | ||
"from azure.core.credentials import AzureKeyCredential\n", | ||
"import pandas as pd\n", | ||
"\n", | ||
"key = AzureKeyCredential(\"19cbfb37271e4d5a9fafba91b35897a5\")\n", | ||
"client = BlocklistClient(\"https://groupama-diva-poc-contentsafety.cognitiveservices.azure.com/\", key)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"List current blocklists." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 37, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"competitors: Competitors blocklist.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"blocklists = client.list_text_blocklists()\n", | ||
"\n", | ||
"if not blocklists:\n", | ||
" print(\"There are no blocklists.\")\n", | ||
"\n", | ||
"for blocklist in blocklists:\n", | ||
" print(f\"{blocklist.blocklist_name}: {blocklist.description}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 38, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Creating blocklist competitors with 53 words\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"name = \"competitors\"\n", | ||
"description = \"Competitors blocklist.\"\n", | ||
"\n", | ||
"df = pd.read_csv(\"blocklist.csv\")\n", | ||
"\n", | ||
"block_items = {}\n", | ||
"for index, row in df.iterrows():\n", | ||
" text = TextBlocklistItem(text=row[\"word\"])\n", | ||
" if row[\"blocklist\"] not in block_items:\n", | ||
" block_items[row[\"blocklist\"]] = []\n", | ||
" block_items[row[\"blocklist\"]].append(text)\n", | ||
"\n", | ||
"for blocklist, words in block_items.items():\n", | ||
" print(f\"Creating blocklist {blocklist} with {len(words)} words\")\n", | ||
" client.create_or_update_text_blocklist(\n", | ||
" blocklist_name=blocklist,\n", | ||
" options=TextBlocklist(blocklist_name=blocklist),\n", | ||
" )\n", | ||
" client.add_or_update_blocklist_items(\n", | ||
" blocklist_name=blocklist,\n", | ||
" options=AddOrUpdateTextBlocklistItemsOptions(\n", | ||
" blocklist_items=words\n", | ||
" )\n", | ||
" )" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.11.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from typing import List | ||
from pydantic import SecretStr | ||
from pydantic_settings import BaseSettings | ||
|
||
|
||
class ContentSafetyModel(BaseSettings, env_prefix="content_safety_"): | ||
access_key: SecretStr | ||
blocklists: List[str] | ||
endpoint: str |
Oops, something went wrong.