Skip to content

[ai] Add JSON serialization for Messages and Content Blocks #512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 19, 2025

Conversation

loreto
Copy link
Contributor

@loreto loreto commented Jun 19, 2025

Summary

This PR builds on top of #511.

  • Implements JSON marshaling/unmarshaling for all message types (SystemMessage, UserMessage, AssistantMessage, ToolMessage) and content blocks.
  • Includes type discriminators in serialized JSON and proper validation during deserialization.

How was it tested?

Added tests.

Community Contribution License

All community contributions in this pull request are licensed to the project maintainers under the terms of the Apache 2 License.

By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the Community Contribution License.

loreto added 2 commits June 19, 2025 10:33
- Add custom JSON unmarshaling for CallOptions to handle polymorphic ToolDefinition interface
- Add JSON unmarshaling for ProviderMetadata
- Implement automatic "type" field inclusion for FunctionTool and ProviderDefinedTool JSON marshaling
- Refactor Anthropic provider to use generic convertArgs helper for flexible tool argument conversion
- Support both struct-based and map[string]any tool arguments
- Add comprehensive tests for JSON marshaling/unmarshaling
Implements JSON marshaling/unmarshaling for all message types
(SystemMessage, UserMessage, AssistantMessage, ToolMessage) and content blocks.
Includes type discriminators in serialized JSON and proper validation during
deserialization. This enables API communication and data persistence for AI prompts.
@loreto loreto requested review from mikeland73 and Copilot June 19, 2025 18:22
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

Base automatically changed from daniel/ai-json/1 to main June 19, 2025 20:07
@loreto loreto merged commit 437737e into main Jun 19, 2025
13 checks passed
@loreto loreto deleted the daniel/ai-json/2 branch June 19, 2025 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants