Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/backend/event_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ def track_event_if_configured(event_name: str, event_data: dict):
instrumentation_key = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
if instrumentation_key:
track_event(event_name, event_data)
else:
logging.warning(f"Skipping track_event for {event_name} as Application Insights is not configured")
# else:
# logging.warning(f"Skipping track_event for {event_name} as Application Insights is not configured")
2 changes: 1 addition & 1 deletion src/backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ opentelemetry-instrumentation-fastapi
opentelemetry-instrumentation-openai
opentelemetry-exporter-otlp-proto-http

semantic-kernel
semantic-kernel[azure]
azure-ai-projects
openai
azure-ai-inference
Expand Down
29 changes: 15 additions & 14 deletions src/backend/utils_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ async def rai_success(description: str) -> bool:

CHECK_ENDPOINT = os.getenv("AZURE_OPENAI_ENDPOINT")
API_VERSION = os.getenv("AZURE_OPENAI_API_VERSION")
DEPLOYMENT_NAME = os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME")
DEPLOYMENT_NAME = os.getenv("AZURE_OPENAI_MODEL_NAME")

if not all([CHECK_ENDPOINT, API_VERSION, DEPLOYMENT_NAME]):
logging.error("Missing required environment variables for RAI check")
Expand Down Expand Up @@ -189,19 +189,20 @@ async def rai_success(description: str) -> bool:

# Send request
response = requests.post(url, headers=headers, json=payload, timeout=30)
response.raise_for_status() # Raise exception for non-200 status codes
response_json = response.json()

if (
response_json.get("choices")
and "message" in response_json["choices"][0]
and "content" in response_json["choices"][0]["message"]
and response_json["choices"][0]["message"]["content"] == "FALSE"
or response_json.get("error")
and response_json["error"]["code"] != "content_filter"
):
return True
return False
if response.status_code == 400 or response.status_code == 200:
response_json = response.json()

if (
response_json.get("choices")
and "message" in response_json["choices"][0]
and "content" in response_json["choices"][0]["message"]
and response_json["choices"][0]["message"]["content"] == "TRUE"
or response_json.get("error")
and response_json["error"]["code"] == "content_filter"
):
return False
response.raise_for_status() # Raise exception for non-200 status codes including 400 but not content_filter
return True

except Exception as e:
logging.error(f"Error in RAI check: {str(e)}")
Expand Down
Loading
Loading