Skip to content

Commit

Permalink
url fix
Browse files Browse the repository at this point in the history
  • Loading branch information
NJ-186 committed Dec 2, 2024
1 parent 5bb4455 commit 13adbb4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion nemoguardrails/library/privateai/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import logging
import os

from urllib.parse import urlparse
from nemoguardrails import RailsConfig
from nemoguardrails.actions import action
from nemoguardrails.library.privateai.request import private_ai_detection_request
Expand All @@ -44,7 +45,8 @@ async def detect_pii(source: str, text: str, config: RailsConfig):
server_endpoint = pai_config.server_endpoint
enabled_entities = getattr(pai_config, source).entities

if "api.private-ai.com" in server_endpoint and not pai_api_key:
parsed_url = urlparse(server_endpoint)
if parsed_url.hostname == "api.private-ai.com" and not pai_api_key:
raise ValueError(
"PAI_API_KEY environment variable required for Private AI cloud API."
)
Expand Down
4 changes: 3 additions & 1 deletion nemoguardrails/library/privateai/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from typing import Any, Dict, List, Optional

import aiohttp
from urllib.parse import urlparse

log = logging.getLogger(__name__)

Expand All @@ -42,7 +43,8 @@ async def private_ai_detection_request(
Returns:
True if PII is detected, False otherwise.
"""
if "api.private-ai.com" in server_endpoint and not api_key:
parsed_url = urlparse(server_endpoint)
if parsed_url.hostname == "api.private-ai.com" and not api_key:
raise ValueError("'api_key' is required for Private AI cloud API.")

payload: Dict[str, Any] = {
Expand Down

0 comments on commit 13adbb4

Please sign in to comment.