Skip to content

Commit

Permalink
reformat file with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheepsta300 committed Sep 11, 2024
1 parent c1943e4 commit fe863b3
Showing 1 changed file with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AzureContentSafetyTextTool(BaseTool):
A tool that interacts with the Azure AI Content Safety API.
This tool queries the Azure AI Content Safety API to analyze text for harmful
content and identify sentiment. It requires an API key and endpoint,
content and identify sentiment. It requires an API key and endpoint,
which can be set up as described in the following guide:
https://learn.microsoft.com/python/api/overview/azure/ai-contentsafety-readme?view=azure-python
Expand All @@ -34,7 +34,7 @@ class AzureContentSafetyTextTool(BaseTool):
Analyzes the provided text to assess its sentiment and safety,
returning the analysis results.
_run(query: str,
_run(query: str,
run_manager: Optional[CallbackManagerForToolRun] = None) -> str:
Uses the tool to analyze the given query and returns the result.
Raises a RuntimeError if an exception occurs.
Expand All @@ -48,7 +48,7 @@ class AzureContentSafetyTextTool(BaseTool):
description: str = (
"A wrapper around Azure AI Content Safety. "
"Useful for when you need to identify the sentiment of text and whether"
" or not a text is harmful."
" or not a text is harmful."
"Input must be text (str)."
)

Expand All @@ -70,20 +70,18 @@ def __init__(
be fetched from the environment variable 'CONTENT_SAFETY_API_KEY'.
content_safety_endpoint (Optional[str]):
The endpoint URL for Azure Content Safety API. If not provided, it
will be fetched from the environment variable
will be fetched from the environment variable
'CONTENT_SAFETY_ENDPOINT'.
Raises:
ImportError: If the 'azure-ai-contentsafety' package is not installed.
ValueError: If API key or endpoint is not provided and environment
variables are missing.
"""
content_safety_key = content_safety_key or os.environ[
"CONTENT_SAFETY_API_KEY"
]
content_safety_endpoint = content_safety_endpoint or os.environ[
"CONTENT_SAFETY_ENDPOINT"
]
content_safety_key = content_safety_key or os.environ["CONTENT_SAFETY_API_KEY"]
content_safety_endpoint = (
content_safety_endpoint or os.environ["CONTENT_SAFETY_ENDPOINT"]
)
try:
import azure.ai.contentsafety as sdk
from azure.core.credentials import AzureKeyCredential
Expand Down Expand Up @@ -150,7 +148,4 @@ def _run(
try:
return self._sentiment_analysis(query)
except Exception as e:
raise RuntimeError(
f"Error while running AzureContentSafetyTextTool: {e}"
)

raise RuntimeError(f"Error while running AzureContentSafetyTextTool: {e}")

0 comments on commit fe863b3

Please sign in to comment.