Repository navigation
Commit bce5801
authored
Python: fix(google_ai): report more Gemini finish reasons as content_filter (#14632)
### Motivation and Context
`finish_reason_from_google_ai_to_semantic_kernel` only mapped `SAFETY`
to `FinishReason.CONTENT_FILTER`. Gemini also ends a response for
`RECITATION`, `BLOCKLIST`, `PROHIBITED_CONTENT` and `SPII` (and the
image variants available across the supported google-genai range), and
for those the message came back with `finish_reason=None`,
indistinguishable from an unrecognised value or an unfinished response.
### Description
- `SAFETY`, `RECITATION`, `BLOCKLIST`, `PROHIBITED_CONTENT`, `SPII`,
`IMAGE_SAFETY` and `IMAGE_PROHIBITED_CONTENT` map to
`FinishReason.CONTENT_FILTER`.
- `STOP` and `MAX_TOKENS` are unchanged; other reasons (`OTHER`,
`MALFORMED_FUNCTION_CALL`, ...) still return `None`.
- A parametrized unit test covers the new reasons; its 6 cases fail on
`main` and pass with the change. `tests/unit/connectors/ai/google`
passes (158).
- The deprecated `vertex_ai` connector is left as is.
### Contribution Checklist
- [x] The code builds clean without any errors or warnings
- [x] The PR follows the SK Contribution Guidelines
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
This change was made with Claude Code; the tests were run against `main`
and the branch.1 parent 5377800 commit bce5801
2 files changed
Lines changed: 29 additions & 1 deletion
File tree
- python
- semantic_kernel/connectors/ai/google/google_ai/services
- tests/unit/connectors/ai/google/google_ai/services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
34 | 46 | | |
35 | 47 | | |
36 | 48 | | |
| |||
47 | 59 | | |
48 | 60 | | |
49 | 61 | | |
50 | | - | |
| 62 | + | |
51 | 63 | | |
52 | 64 | | |
53 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
36 | 52 | | |
37 | 53 | | |
38 | 54 | | |
| |||
0 commit comments