-
Notifications
You must be signed in to change notification settings - Fork 763
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
Structured output improvements (continuation of PR 5522) #5560
Structured output improvements (continuation of PR 5522) #5560
Conversation
Structured outputs in OpenAI require an `object` schema object. By detecting this situation and wrapping always in a `Payload<T>(T Data)` record, we significantly improve the developer experience by making the API transparent to that limitation (which might even be a temporary one?). The approach works for both OpenAI as well as Azure Inference without native structured outputs. In order to signal a wrapped result to the `ChatCompletion<T>`, we use the `AdditionalProperties` dictionary with a non-standard `$wrapped` property which is a typical convention for JSON properties that are not intended for end-user consumption (like $schema). Fixes #5521
Rather than relying on the type system, since a source-generated serializer options would not be able to deal with it.
So the decision was to move forward with this? Yay! 🚀 |
Yeah, I'd like to go ahead optimistically. It seems to work reliably on OpenAI models. On (say) If @stephentoub or @eiriktsarpalis think otherwise, please say so. |
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/ChatClientStructuredOutputExtensions.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/ChatClientStructuredOutputExtensions.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/ChatClientStructuredOutputExtensions.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/ChatClientStructuredOutputExtensions.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/ChatClientStructuredOutputExtensions.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/ChatClientStructuredOutputExtensions.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/ChatClientStructuredOutputExtensions.cs
Show resolved
Hide resolved
…tStructuredOutputExtensions.cs Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
Continuation of #5522. I had to start a new PR because #5522 has complicated merge conflicts and after fixing them, I can't rebase and push because it's on a branch. However this is still primarily the work of @kzu (thanks!).
Microsoft Reviewers: Open in CodeFlow