mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 11:19:56 +00:00
### Motivation and Context OpenAI has released in their August 6th model the ability to specific a json_schema response format. This allows the model to use the specified Pydantic model or the provided JSON schema representing a "strict" model/class to make sure that it responds with the exact schema that was provided. Note that the strict tool calling will be handled via a separate ADR/work item once agreed upon by all three SK languages. <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> ### Description This PR introduces the ability to specific either a Pydantic model or a non-Pydantic model for the json_schema response format OpenAIChatPromptExecutionSettings. - There are two new code sample concept files showing how to do this with both a Pydantic and a non-Pydantic model. The other code sample shows how to configure a json_schema response format while using function calling. - If the model is unable to respond based on the provided schema, it will contain a `refusal` attribute as part of the chat completion message contents. This will be included in the response as a TextContent item explaining why it couldn't fulfill the request. - Unit tests added for this new functionality. - Handles #7946 <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [X] The code builds clean without any errors or warnings - [X] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [X] All unit tests pass, and I have added new tests where possible - [X] I didn't break anyone 😄