Commit 5c8c55a
fix: use Modality enum for RunConfig.response_modalities
Merge #4889
## Description
Fixes #4869
`RunConfig.response_modalities` is typed as `Optional[list[str]]`, but it gets assigned to `LiveConnectConfig.response_modalities` which expects `Optional[list[Modality]]` (an enum from `google-genai`). This type mismatch causes Pydantic to emit a `PydanticSerializationUnexpectedValue` warning on every live streaming session, polluting production logs.
## Changes
- **`run_config.py`**: Changed `response_modalities` type from `Optional[list[str]]` to `Optional[list[types.Modality]]`
- **`runners.py`**: Updated two string literal `'AUDIO'` usages to `types.Modality.AUDIO` for consistency
This is backwards compatible — `Modality` is a string enum, so Pydantic automatically coerces string values like `'AUDIO'` to `Modality.AUDIO`.
## Testing Plan
Added 4 new unit tests in `test_run_config.py`:
- `test_response_modalities_accepts_enum` — enum values are stored correctly
- `test_response_modalities_coerces_string_to_enum` — string values still work (backwards compat)
- `test_response_modalities_coerces_lowercase_string_to_enum` — lowercase string values also work (backwards compat)
- `test_response_modalities_serialization_no_warning` — `LiveConnectConfig.model_dump()` produces no Pydantic warnings
Co-authored-by: Liang Wu <wuliang@google.com>
COPYBARA_INTEGRATE_REVIEW=#4889 from brucearctor:fix/response-modalities-type e67f715
PiperOrigin-RevId: 9346598351 parent 2f729b5 commit 5c8c55a
3 files changed
Lines changed: 35 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | | - | |
| 199 | + | |
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1554 | 1554 | | |
1555 | 1555 | | |
1556 | 1556 | | |
1557 | | - | |
| 1557 | + | |
1558 | 1558 | | |
1559 | 1559 | | |
1560 | 1560 | | |
| |||
2021 | 2021 | | |
2022 | 2022 | | |
2023 | 2023 | | |
2024 | | - | |
| 2024 | + | |
2025 | 2025 | | |
2026 | 2026 | | |
2027 | 2027 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
70 | 102 | | |
71 | 103 | | |
72 | 104 | | |
| |||
0 commit comments