fix: handle empty objects for providers#540
Conversation
WalkthroughThe changes add serialization exclusion metadata to specific dataclass fields in the agent websocket options, ensuring fields are omitted from serialization when they are Changes
Possibly related PRs
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Pylint (3.3.7)examples/agent/no_mic/main.py📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code Graph Analysis (1)examples/agent/no_mic/main.py (1)
🔇 Additional comments (1)
✨ Finishing Touches
🧪 Generate Unit Tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (2)
deepgram/clients/agent/v1/websocket/options.py (2)
178-178: Same serialization gap forListen.providerSee earlier comment – the predicate should also recognise an empty
Providerinstance.
195-195: Same serialization gap forSpeak.providerEmpty
Provider()objects will still leak into the wire format.
🧹 Nitpick comments (4)
deepgram/clients/agent/v1/websocket/options.py (3)
158-159:__post_init__guard is getting unwieldyThe triple condition is beginning to hurt readability and is now duplicated in every model.
Consider extracting a small helper (e.g._is_empty_provider(obj)) or re-using the lambda above to keep the rule in a single place.
181-182: Duplication of post-init logic
Listen.__post_init__repeats the same conversion logic found inThinkandSpeak.
Factor this into a mix-in or utility to avoid three copies.
201-202: Repeated conversion guardAs above, refactor to a shared helper to ease future maintenance.
examples/agent/simple/main.py (1)
45-45: Verbosity level cranked toSPAM– deliberate?
verboselogs.SPAMis extremely chatty and will flood stdout in examples.
If this is meant only for local debugging, consider downgrading toDEBUGor gating it behind an environment variable so sample users aren’t overwhelmed.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
deepgram/clients/agent/v1/websocket/options.py(5 hunks)examples/agent/simple/main.py(1 hunks)
🔇 Additional comments (1)
deepgram/clients/agent/v1/websocket/options.py (1)
218-220:listen/think/speakdefault instances always serialiseBecause
default_factoryeagerly builds non-empty dataclass objects, theexcludepredicate is never true, so empty agent sections still appear in outbound JSON.If the intent is to omit untouched sections, switch to
default=Noneand create them lazily, or enhance the predicate to treat default instances as empty.
|
When Testing I fixed this in this PR and closed out PR #539 . Now it passes. |
| "speaker_playback": "true", | ||
| }, | ||
| # verbose=verboselogs.DEBUG, | ||
| verbose=verboselogs.SPAM, |
There was a problem hiding this comment.
@naomi-lgbt did you want to change this to SPAM or leave it as DEBUG?
Proposed changes
Types of changes
What types of changes does your code introduce to the community Python SDK?
Put an
xin the boxes that applyChecklist
Put an
xin the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Further comments
Summary by CodeRabbit