Converting GenerableContent to JSON string

Hey, I receive GenerableContent as follows:

let response = try await session.respond(to: "", schema: generationSchema)

And it wraps GeneratedJSON which seems to be private.

What is the best way to get a string / raw value out of it? I noticed it could theoretically be accessed via transcriptEntries but it's not ideal.

Hello,

Take a look at the sample project Generate dynamic game content with guided generation and tools to see how you can use generated content in string format.

Thanks. I had a look and appears there's String(describing: response.content) used, however, that does not output (rawValue) - an actual JSON string, but instead:

"FoundationModels.GeneratedJSON(storage: FoundationModels.GeneratedJSON.Storage.object(properties: [\"name\": FoundationModels.GeneratedJSON(storage: FoundationModels.GeneratedJSON.Storage.string(\"Steve Jobs\"), isComplete: true)], order: nil), isComplete: true)"

As of today, there isn't a good way to grab the string representation for a GeneratedContent value. The only thing you might want to take a look is GeneratedContent.debugDescription, which, as the name indicates, is for debugging purpose. I’d hence suggest that you file a feedback report with your concrete use case – If you do so, please share your report ID here for folks to track. Thanks.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Thank you. FB18758537.

Converting GenerableContent to JSON string
 
 
Q