Skip to content

Commit f8cd475

Browse files
committed
url fix
1 parent 5bb4455 commit f8cd475

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

nemoguardrails/library/privateai/actions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import logging
1919
import os
2020

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

47-
if "api.private-ai.com" in server_endpoint and not pai_api_key:
48+
parsed_url = urlparse(server_endpoint)
49+
if parsed_url.hostname == "api.private-ai.com" and not pai_api_key:
4850
raise ValueError(
4951
"PAI_API_KEY environment variable required for Private AI cloud API."
5052
)

nemoguardrails/library/privateai/request.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from typing import Any, Dict, List, Optional
2121

2222
import aiohttp
23+
from urllib.parse import urlparse
2324

2425
log = logging.getLogger(__name__)
2526

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

4850
payload: Dict[str, Any] = {

0 commit comments

Comments
 (0)