spring-projects / spring-ai

An Application Framework for AI Engineering
https://docs.spring.io/spring-ai/reference/index.html
Apache License 2.0
3.33k stars 855 forks source link

Support for native Structured Output provided by recent OpenAI models #1201

Closed kkolago closed 3 months ago

kkolago commented 3 months ago

Recently OpenAI released gpt-4o-2024-08-06 model that natively supports Structured Output (https://openai.com/index/introducing-structured-outputs-in-the-api/). It would be good to consider using this native mechanism in Spring AI for OpenAI. According to OpenAI their Structured Output allowed model to follow even complex JSON schemas with much higher reliability than before.

Expected Behavior

Spring AI could use native Structed Output for OpenAI models that support it.

Current Behavior

Currently Spring AI has great implementation of Structured Output. It's best part is that it is generic, but sometimes it's not 100% reliable. It is possible that using native Structured Output would improve it's reliability when it comes to following desired JSON schema.

ThomasVitale commented 3 months ago

@kkolago thanks for the feature request. @tzolov has implemented support for OpenAI Structured Output in https://github.com/spring-projects/spring-ai/issues/1196 right after the OpenAI announcement. You can find more information on how to use it in this blog post: https://spring.io/blog/2024/08/09/spring-ai-embraces-openais-structured-outputs-enhancing-json-response

kkolago commented 3 months ago

Amazing. Thank you for the link. :)