Skip to content

Commit f9dbccc

Browse files
authored
Merge pull request #109 from microsoft/azd-semantickernel-marktayl
RAI fixes
2 parents 2c63e64 + 9810754 commit f9dbccc

File tree

4 files changed

+18
-585
lines changed

4 files changed

+18
-585
lines changed

src/backend/event_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ def track_event_if_configured(event_name: str, event_data: dict):
77
instrumentation_key = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
88
if instrumentation_key:
99
track_event(event_name, event_data)
10-
else:
11-
logging.warning(f"Skipping track_event for {event_name} as Application Insights is not configured")
10+
# else:
11+
# logging.warning(f"Skipping track_event for {event_name} as Application Insights is not configured")

src/backend/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ opentelemetry-instrumentation-fastapi
1414
opentelemetry-instrumentation-openai
1515
opentelemetry-exporter-otlp-proto-http
1616

17-
semantic-kernel
17+
semantic-kernel[azure]
1818
azure-ai-projects
1919
openai
2020
azure-ai-inference

src/backend/utils_kernel.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ async def rai_success(description: str) -> bool:
155155

156156
CHECK_ENDPOINT = os.getenv("AZURE_OPENAI_ENDPOINT")
157157
API_VERSION = os.getenv("AZURE_OPENAI_API_VERSION")
158-
DEPLOYMENT_NAME = os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME")
158+
DEPLOYMENT_NAME = os.getenv("AZURE_OPENAI_MODEL_NAME")
159159

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

190190
# Send request
191191
response = requests.post(url, headers=headers, json=payload, timeout=30)
192-
response.raise_for_status() # Raise exception for non-200 status codes
193-
response_json = response.json()
194-
195-
if (
196-
response_json.get("choices")
197-
and "message" in response_json["choices"][0]
198-
and "content" in response_json["choices"][0]["message"]
199-
and response_json["choices"][0]["message"]["content"] == "FALSE"
200-
or response_json.get("error")
201-
and response_json["error"]["code"] != "content_filter"
202-
):
203-
return True
204-
return False
192+
if response.status_code == 400 or response.status_code == 200:
193+
response_json = response.json()
194+
195+
if (
196+
response_json.get("choices")
197+
and "message" in response_json["choices"][0]
198+
and "content" in response_json["choices"][0]["message"]
199+
and response_json["choices"][0]["message"]["content"] == "TRUE"
200+
or response_json.get("error")
201+
and response_json["error"]["code"] == "content_filter"
202+
):
203+
return False
204+
response.raise_for_status() # Raise exception for non-200 status codes including 400 but not content_filter
205+
return True
205206

206207
except Exception as e:
207208
logging.error(f"Error in RAI check: {str(e)}")

0 commit comments

Comments
 (0)