[AI] Add GenerativeModel.generateObject(_:prompt:)#15868
[AI] Add GenerativeModel.generateObject(_:prompt:)#15868andrewheard wants to merge 3 commits intomainfrom
GenerativeModel.generateObject(_:prompt:)#15868Conversation
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. |
Generated by 🚫 Danger |
WIP - Added a
generateObject(_:prompt:)method toGenerativeModelbased on the Android implementation ofgenerateObject(jsonSchema:prompt:)/GenerateObjectResponse. This approach uses the "Decoder Spy" technique to automatically generate a JSON Schema from aDecodabletype without a macro and works on iOS 15+. TheSchemaConstraintsProviderprotocol allows additional constraints (similar to@Guide).Usage Example
Note: See the integration tests for examples with additional constraints provided by conforming to
SchemaConstraintsProvider.Auto-Generated JSON Schema
Example Output
GameCharacter(firstName: "Kaelan", middleName: nil, lastName: "Stonehaven", age: 32, backstory: "Sir Kaelan Stonehaven, born to a lineage of knights, seemed destined for a life of steel and valor. However, deep within his family\'s ancestral castle, an ancient pact with a forgotten nature spirit stirred. On his 18th birthday, while performing a solitary vigil in the crypts, a surge of emerald light infused him. He awoke with the ability to commune with stone and earth, and to mend his wounds with moss and root. He secretly trained with an old hermit who revealed the forgotten druidic bloodline that ran through Kaelan\'s veins, a power suppressed by generations of mundane knighthood. He now serves his kingdom, his silver armor shimmering not just from polish, but from the subtle, protective magic woven into its very mithril threads, guarding the realm not just with his sword, but with the ancient, living power of the earth.")Cross-Platform Consistency
The
GenerateObjectResponseshould likely return the type directly andgenerateObject(_:prompt:)could throw, including theGenerateContentResponse, rather than going through an additionalgetObject()call. This approach was only taken to align as closely as possible across platforms.#no-changelog