DMflow.chat
An all-in-one chatbot integrating Facebook, Instagram, Telegram, LINE, and web platforms, supporting ChatGPT and Gemini models. Features include history retention, push notifications, marketing campaigns, and customer service transfer.
OpenAI has added a structured output feature to its API, significantly improving the reliability of AI models in generating valid JSON. This feature not only allows developers to build stable applications more easily but also opens new possibilities for AI to generate structured data from unstructured input.
In the field of artificial intelligence, generating structured data from unstructured input has always been a core application scenario. Whether it is obtaining data through function calls, extracting structured information for data entry, or establishing multi-step agent workflows, developers are continuously exploring how to enable AI to better accomplish these tasks.
However, developers previously often had to rely on open-source tools, meticulously designed prompts, and even repeated request attempts to ensure that the AI model’s output conforms to the format required by their systems. This process was not only time-consuming and laborious but also potentially affected the stability and reliability of applications.
The structured output feature introduced by OpenAI addresses this issue through two key methods:
The results of this feature are impressive. In the evaluation of complex JSON schemas, the new model equipped with the structured output feature, gpt-4o-2024-08-06, achieved a score of 100%, far surpassing the less than 40% score of the previous model, gpt-4-0613.
OpenAI provides two ways to use structured output in the API:
Developers can set strict: true
in the function definition to enable structured output. This is applicable to all models supporting tools, including gpt-4-0613 and gpt-3.5-turbo-0613 and higher versions.
Developers can use the new json_schema
option in the response_format
parameter to provide a JSON Schema. This is particularly suitable for cases where the model needs to respond to users in a structured manner, rather than during tool calls.
OpenAI has implemented structured output using a technique known as “constrained sampling” or “constrained decoding.” This method restricts the model’s output to valid token ranges that comply with the provided JSON schema, ensuring the output’s validity.
The specific implementation steps are as follows:
This approach can handle not only simple JSON structures but also complex schemas involving nested or recursive data structures, which are difficult to achieve with Finite State Machine (FSM)-based methods.
The structured output feature opens up many new possibilities for developers. Here are some potential applications:
Although the structured output feature is powerful, developers should be aware of the following points:
max_tokens
limit or other stop conditions.parallel_tool_calls: false
.The structured output feature is now fully available in the OpenAI API:
Developers can start using the structured output feature by referring to OpenAI’s official documentation.
Q: How does the structured output feature improve the reliability of JSON generation? A: Structured output improves the reliability of JSON generation to 100% by constraining the model output and optimizing the model’s ability to understand complex JSON schemas.
Q: Which OpenAI models are applicable to the structured output feature? A: Structured output applies to all models supporting function calls, including the latest gpt-4o series and gpt-3.5-turbo series.
Q: Will using the structured output feature affect the API’s response speed? A: The first use of a new JSON schema may have some delay, but subsequent requests will not be affected, and the response speed will be fast.
Q: What are the limitations of the structured output feature? A: Main limitations include supporting only a subset of JSON schemas, inability to prevent all types of model errors, and incompatibility with parallel function calls.
Q: How can I start using the structured output feature? A: Developers can refer to OpenAI’s official documentation to learn how to enable and configure the structured output feature in API calls.
An all-in-one chatbot integrating Facebook, Instagram, Telegram, LINE, and web platforms, supporting ChatGPT and Gemini models. Features include history retention, push notifications, marketing campaigns, and customer service transfer.
GPT-4o-2024 Makes a Stunning Debut: OpenAI’s Latest AI Model Brings Revolutionary Breakthroughs O...
Evolution of the ChatGPT Models: From 3.5 to 4.0, and then to 4o and 4o Mini - A Comprehensive Co...
OpenAI Offers Limited-Time Free Fine-Tuning Service for GPT-4o Mini Model OpenAI is currently of...
Prompt Engineering: Strategies and Techniques to Optimize Outputs from Large Language Models Thi...
from OpenAI ChatGPT-4o mini Overview On July 18th, OpenAI introduced ChatGPT-4o mini, a cut...
DMflow.chat’s Gemini 1.5 Flash: User Manual and Performance Analysis DMflow.chat’s latest vers...