Python: Sets a valid default content filter code to ResponsibleAIPolicyViolation (#4715)

### Motivation and Context

When the RAI response doesn't contain a `code` the class
`ContentFilterAIException` would fail to initialize because it was
setting `""` as content_filter_code. This sets
`"ResponsibleAIPolicyViolation"` instead in that case.

Fixes #4709 

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄

Co-authored-by: Evan Mattson <[email protected]>
This commit is contained in:
Julio Carlos Menendez
2024-01-23 19:24:29 +00:00
committed by GitHub
co-authored by Evan Mattson
parent 79119f1b17
commit a5ce301656
2 changed files with 50 additions and 1 deletions
@@ -75,7 +75,9 @@ class ContentFilterAIException(AIException):
self._param = inner_exception.param
inner_error = inner_exception.body.get("innererror", {})
self._content_filter_code = ContentFilterCodes(inner_error.get("code", ""))
self._content_filter_code = ContentFilterCodes(
inner_error.get("code", ContentFilterCodes.RESPONSIBLE_AI_POLICY_VIOLATION.value)
)
self._content_filter_result = dict(
[
key,