fix: exclude null fields from API payloads to match Node SDK behavior#169
fix: exclude null fields from API payloads to match Node SDK behavior#169dineshreddy91 wants to merge 1 commit intomainfrom
Conversation
GenerationConfig.model_dump() was sending all null fields (response_model, prompt, json_schema, etc.) and AgentSkill null fields (skill_id, name, source, bundle) in every request. This caused bloated payloads with ~20 unnecessary null fields vs the Node SDK which omits them. Changes: - GenerationConfig.model_dump(): default to exclude_none=True, always strip the internal response_model field - document.generate(): only include domain/callback_url when non-None - execute()/image.generate(): same callback_url cleanup Made-with: Cursor
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request streamlines the API payload generation across various client methods to prevent the transmission of null fields. By aligning the Python SDK's behavior with the Node SDK, it ensures that fields such as Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the goal of excluding null fields from API payloads to align the Python SDK with the Node SDK's behavior. The changes across vlmrun/client/predictions.py correctly modify how request data is constructed, ensuring that optional fields like domain and callback_url are only included when they have a value. In vlmrun/client/types.py, the update to GenerationConfig.model_dump to default to exclude_none=True is a clean and robust solution for filtering out null values from the configuration.
The implementations are correct and improve code clarity.
One minor point for consideration in a future change: the execute method in ImagePredictions was not updated and still passes callback_url directly, which could result in sending null. This might be an oversight and could be updated for consistency.
Summary
GenerationConfig.model_dump(): defaults toexclude_none=Trueso null fields likeprompt,json_schema,gql_stmtand all nullAgentSkillsub-fields (skill_id,name,source,bundle) are omitted. Always strips the internalresponse_modelfield (was only stripped when non-None before).document.generate(): only includesdomainin the payload when it has a value (previously always sent"domain": null). Same forcallback_url.execute()/image.generate(): samecallback_urlcleanup.Before (Python SDK sent ~20 null fields):
{"prompt": null, "response_model": null, "json_schema": null, "gql_stmt": null, "max_retries": 3, ..., "skills": [{"type": "skill_reference", "skill_id": null, "skill_name": "invoice-extraction", "version": "latest", "name": null, "description": null, "source": null, "bundle": null}]}After (matches Node SDK):
{"max_retries": 3, "max_tokens": 65535, "temperature": 0.0, "detail": "auto", "confidence": false, "grounding": false, "skills": [{"type": "skill_reference", "skill_name": "invoice-extraction", "version": "latest"}]}Test plan
document.generate(domain="document.invoice", ...)— domain included in payload, works as beforedocument.generate(config=GenerationConfig(skills=[...]))— domain omitted from payloadGenerationConfig(response_model=MyModel).model_dump()— producesjson_schemafield, noresponse_modelGenerationConfig().model_dump()— no null fields in outputMade with Cursor