firebase-ios-sdk icon indicating copy to clipboard operation
firebase-ios-sdk copied to clipboard

FirebaseGenerable

Open paulb777 opened this issue 2 weeks ago • 7 comments

wip

Add func generateObject<T: FirebaseGenerable>(as type: T.Type, from prompt: String) async throws -> T The new tests pass locally

Summary of Changes

This pull request significantly enhances the Firebase AI SDK by introducing the capability to generate structured Swift objects directly from generative model responses. It achieves this through a new FirebaseGenerable protocol and a Swift macro that automatically creates a schema for Decodable types. This feature streamlines the development workflow for applications requiring structured data output from AI models, reducing boilerplate and improving type safety.

Highlights

  • Structured Object Generation: Introduced a new generateObject function in GenerativeModel that allows generating structured Swift objects directly from the model's response, automating schema generation and JSON decoding.
  • FirebaseGenerable Protocol and Macro: Added a FirebaseGenerable protocol and an associated Swift macro (@FirebaseGenerable) to automatically derive a Schema for Decodable types, simplifying the process of defining the expected output structure for the model.
  • Enhanced Configuration Inheritance: Improved the GenerationConfig to allow for proper inheritance of existing settings when creating a new configuration for object generation, ensuring that parameters like temperature and token limits are respected.
  • Robust Schema Handling for Optional Types: Implemented correct schema generation for optional properties within FirebaseGenerable types, ensuring that the model understands which fields can be null.
  • Comprehensive Error Reporting: Added specific error types (GenerateObjectError) to provide clearer feedback when object generation fails due to issues like missing response text or JSON decoding problems.

paulb777 avatar Nov 22 '25 22:11 paulb777