-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Describe the bug
When using the SDK to send a RealtimeAudioEvent, the code fails due to a Pydantic validation error. The event_type is passed as an instance of SendEvents.INPUT_AUDIO_BUFFER_APPEND, which is an Enum, but downstream validation requires a literal string ("input_audio_buffer.append"). This causes a literal_error
The issue does not occur on Windows with Semantic-kernel 1.27.1, but fails on macOS with both 1.27.1 and latest version of SDK Semantic-kernel 1.27.2, likely due to stricter validation or platform differences in how values are handled or validated.
To Reproduce
Steps to reproduce the behavior:
1. Create a RealtimeAudioEvent with AudioContent, passing base64-encoded audio data as data.
2. Call realtime_client.send(event) on macOS.
3. Internally, the send() method calls _create_openai_realtime_client_event(...) with event_type=SendEvents.INPUT_AUDIO_BUFFER_APPEND.
4. throws a validation error:
error: Input should be 'input_audio_buffer.append' [type=literal_error, input_value=<SendEvents.INPUT_AUDIO_B...ut_audio_buffer.append'>, input_type=SendEvents]
For further information visit https://errors.pydantic.dev/2.8/v/literal_error
2025-04-08 23:49:57,521 - ERROR - Error processing WebSocket message: 1 validation error for InputAudioBufferAppendEvent
type
Expected behavior
The SDK should work consistently across platforms and not raise validation errors when using SendEvents.INPUT_AUDIO_BUFFER_APPEND, since it inherits from str. Pydantic should recognize it as a valid literal match, or the Enum’s .value should be passed to avoid strict type mismatch.
Screenshots
N/A
Platform
- Language: Python
- Source: pip package semantic-kernel==1.27.2
- AI model: N/A
- IDE: VS Code
- OS: macOS
Additional context
Although SendEvents inherits from str, passing the Enum directly still fails validation under stricter enforcement (as observed on macOS).
-
Solution that fixed the issue on macOS:
Changing this line in the internal send() method:`event_type = SendEvents.INPUT_AUDIO_BUFFER_APPEND` to: `event_type = SendEvents.INPUT_AUDIO_BUFFER_APPEND.value`This ensures that a raw string ("input_audio_buffer.append") is passed, which satisfies the Literal[...] type check enforced by Pydantic.
Recommendation: update internal calls to always use .value when passing SendEvents values into anything validated with Pydantic.