deepgram / deepgram-python-sdk

Official Python SDK for Deepgram's automated speech recognition APIs.
https://developers.deepgram.com
MIT License
218 stars 58 forks source link

Examine JSON DataClasses and Remove `Optional` for Those That are Required #317

Closed dvonthenen closed 7 months ago

dvonthenen commented 7 months ago

Proposed changes

Addresses issue: https://github.com/deepgram/deepgram-python-sdk/issues/310

~IMPORTANT: This builds on top of this PR: https://github.com/deepgram/deepgram-python-sdk/pull/314 and https://github.com/deepgram/deepgram-python-sdk/pull/316. Do not merge until those PRs are merged.~

~For a cleaner diff between this PR and its dependency https://github.com/deepgram/deepgram-python-sdk/pull/316, please look at this compare for convenience: https://github.com/dvonthenen/deepgram-python-sdk/compare/audit-legacy-v2-syntax...dvonthenen:deepgram-python-sdk:remove-optional-dataclass~

IMPORTANT IMPLEMENTATION DETAIL TO REVIEWER/USER: Any parameter on any class that is present when a feature is enabled/disabled, but is missing when a different feature is enabled/disabled, MUST be marked Optional and will be omitted from the JSON (that's the field/lambda function stuff you see in the code).

If the removal of property isn't done, this is the undesired JSON output that is currently happening:

{
    "alternatives": null,
    "callback": null,
    "callback_method": null,
    "custom_intent": null,
    "custom_intent_mode": null,
    "custom_topics": null,
    "custom_topic_mode": null,
    "detect_entities": null,
    "detect_language": null,
    "detect_topics": null,
    "diarize": null,
    "diarize_version": null,
    "dictation": null,
    "extra": null,
    "filler_words": null,
    "intents": null,
    "keywords": null,
    "language": null,
    "measurements": null,
    "model": "nova-2",
    "multichannel": null,
    "numerals": null,
    "paragraphs": null,
    "profanity_filter": null,
    "punctuate": null,
    "redact": null,
    "replace": null,
    "search": null,
    "sentiment": null,
    "smart_format": true,
    "summarize": null,
    "tag": null,
    "tier": null,
    "topics": null,
    "utt_split": null,
    "utterances": null,
    "version": null
}

Making the fields optional as in this PR, yields the following:

{
    "model": "nova-2",
    "smart_format": true
}

Notable changes in this PR:

Exercised each of the examples and made sure the expected values were there.

Types of changes

What types of changes does your code introduce to the community Python SDK? Put an x in the boxes that apply

Checklist

Put an x in 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