Developers rejoice! OpenAI's new structured output function is online, and API responses are more reliable!

OpenAI A new feature, Structured Outputs, is introduced, which aims to make the output generated by the model strictly followDevelopersThe JSON schema provided.

Developers rejoice! OpenAI's new structured output function is online, and API responses are more reliable!

Last year at DevDay, OpenAI first introduced JSON Schema, which provides an important foundation for developers to build reliable applications. While JSON Schema improves the reliability of models generating valid JSON output, it does not ensure that the model's response conforms to a specific schema. Today's structured output feature is designed to solve this problem.

As AI is widely used in applications, generating structured data from unstructured input has become a core use case. Developers use OpenAI API Build powerful assistants that can get data through function calls, answer questions, and extract structured data for data entry. In the past, developers often needed to use open source tools, repeated requests, etc. to ensure that the output of the model conforms to the format required by the system. Now, the structured output function greatly improves the reliability of the output by constraining the OpenAI model to match the pattern provided by the developer.

Complex JSON schema structured output score 100%

It is worth mentioning that in the evaluation of complex JSON patterns, the new model gpt-4o-2024-08-06 achieved a perfect 100% score for structured output, while the previous gpt-4-0613 scored less than 40%. This means that the new model performs better in generating output that conforms to a specific pattern.

Developers rejoice! OpenAI's new structured output function is online, and API responses are more reliable!

How to use structured output

Using structured output is very simple, OpenAI has introduced two forms for the API: one is a function call made by the tool, and the other is a new option for the response format, where developers can provide a JSON schema through the json_schema parameter. When strict mode is enabled, the output of the model will strictly conform to the provided schema.

1. Function calls: You can get structured output through tools by setting strict: true in the function definition. This feature is available for all models that support tools, including all models gpt-4-0613 and gpt-3.5-turbo-0613 and higher. When structured output is enabled, the model output will match the provided tool definition.

2. New option for response_format parameter: Developers can now provide a JSON schema via json_schema, a new option for the response_format parameter. This is useful when the model is not calling a tool, but responding to the user in a structured way. This feature is available for our latest GPT-4o models: gpt-4o-2024-08-06 and gpt-4o-mini-2024-07-18 released today. When response_format is provided with strict: true, the model output will match the provided schema.

Security is a top priority for OpenAI, and new features will run under existing security policies, and models can still reject unsafe requests. At the same time, to simplify the development process, we have added a rejection string value to help developers programmatically detect whether the model has generated a rejection message.

Native SDK support

OpenAI’s Python and Node SDKs have also been updated to support native functionality for structured output. Developers only need to provide Pydantic or Zod objects, and OpenAI’s SDK will automatically handle data type conversion and parsing of JSON responses.

Today’s press conference will show you that structured output will bring more convenience to developers’ work and help them create excellent applications more easily.

Official blog: https://openai.com/index/introducing-structured-outputs-in-the-api/

 

statement:The content is collected from various media platforms such as public websites. If the included content infringes on your rights, please contact us by email and we will deal with it as soon as possible.
Information

Former NetEase Cloud Music vice president startup Seele launches Koko AI to allow virtual characters to interact face to face

2024-8-7 9:45:07

Information

Israeli company launches open source speech recognition model Whisper Medusa with 50% speed increase

2024-8-7 10:08:13

Search