@@ -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