feat: omit None fields on Content, add optional id to function call/response, and add Part helpers (#11) #16

Merged
andreban merged 1 commits from feat/content-none-and-part-helpers into main 2026-10-26 19:45:55 +00:00
Owner

Fixes #11

Summary

  • Adds #[serde(skip_serializing_if = "Option::is_none")] to Content::role and Content::parts so None fields are omitted from JSON rather than serialized as null.
  • Adds Content::system_prompt(prompt) convenience constructor for system instruction contents without a role.
  • Adds optional id: Option<String> (with skip_serializing_if = "Option::is_none") to FunctionCallData and FunctionResponseData.
  • Adds builder-style helpers and constructors on Part:
    • Part::with_thought_signature(sig) to attach thought_signature.
    • Part::with_id(id) to set id on function call or response data.
    • Part::function_call_with_id(id, name, args) and Part::function_response_with_id(id, name, response) constructors.
    • FunctionResponsePart::inline_data(mime_type, data) constructor.
    • Part::add_function_response_part(part) and Part::add_function_response_inline_data(mime_type, data) for multimodal function responses.

Testing

  • Added unit tests in src/types/common.rs:
    • content_omits_unset_role_and_parts: verifies None role/parts are omitted from JSON and roundtrip cleanly.
    • function_call_id_handling: verifies id serialization and deserialization on FunctionCallData.
    • function_response_id_handling: verifies id serialization and deserialization on FunctionResponseData.
    • part_builder_helpers: verifies fluent builder methods for thought_signature and FunctionResponsePart media blocks.
  • cargo test (32 passed) and cargo clippy pass cleanly.
Fixes #11 ## Summary - Adds `#[serde(skip_serializing_if = "Option::is_none")]` to `Content::role` and `Content::parts` so `None` fields are omitted from JSON rather than serialized as `null`. - Adds `Content::system_prompt(prompt)` convenience constructor for system instruction contents without a role. - Adds optional `id: Option<String>` (with `skip_serializing_if = "Option::is_none"`) to `FunctionCallData` and `FunctionResponseData`. - Adds builder-style helpers and constructors on `Part`: - `Part::with_thought_signature(sig)` to attach `thought_signature`. - `Part::with_id(id)` to set `id` on function call or response data. - `Part::function_call_with_id(id, name, args)` and `Part::function_response_with_id(id, name, response)` constructors. - `FunctionResponsePart::inline_data(mime_type, data)` constructor. - `Part::add_function_response_part(part)` and `Part::add_function_response_inline_data(mime_type, data)` for multimodal function responses. ## Testing - Added unit tests in `src/types/common.rs`: - `content_omits_unset_role_and_parts`: verifies `None` role/parts are omitted from JSON and roundtrip cleanly. - `function_call_id_handling`: verifies `id` serialization and deserialization on `FunctionCallData`. - `function_response_id_handling`: verifies `id` serialization and deserialization on `FunctionResponseData`. - `part_builder_helpers`: verifies fluent builder methods for `thought_signature` and `FunctionResponsePart` media blocks. - `cargo test` (32 passed) and `cargo clippy` pass cleanly.
andreban added 1 commit 2026-10-26 19:40:46 +00:00
andreban merged commit 01a4300bb3 into main 2026-10-26 19:45:55 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: andreban/gemini-rs#16