-
Notifications
You must be signed in to change notification settings - Fork 279
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
If the structured data contains nested lists, the response time increases exponentially as the size of these lists grows #277
Comments
can you show some timings on what is slow? Either manually or a screenshot of a logfire trace. If it's just OpenAI that's slow, there's not much PydanticAI can do about that. |
As highlighted in the [OpenAI article on Structured Outputs](https://openai.com/index/introducing-structured-outputs-in-the-api/), it’s mentioned that the first API response with a new schema can take up to 10 seconds. In my use case, where the model is called twice to build a nested structure, this results in a latency of over 20 seconds per request, which is not ideal for real-time applications. This latency seems to be a known issue, but for anyone building serious applications with Structured Responses in LLM, this delay can be a significant bottleneck. How do you envision handling this latency with valid structured data for real-time use cases? Do you expect this delay to improve over time, or should we reconsider using structured data in scenarios that require fast responses? Additional Info: Sfstructured data in performance-critical applications, and any guidance on improving this would be greatly appreciated. https://openai.com/index/introducing-structured-outputs-in-the-api/ Limitations and restrictionsThere are a few limitations to keep in mind when using Structured Outputs:
|
@samuelcolvin - Here is the log fire output you wanted - I just ran to 3 day forecast ( list of 3 elements with hourly data )
Also, the logfire console output is below. |
Summary:
We have noticed a significant delay in the response time when generating structured weather data with a
List[DailyForecast]
andList[HourlyForecast]
. The time taken for the request grows almost exponentially as the number of forecast days increases.This issue arises when generating structured data, where
WeatherData
contains aforecasts
field with a list ofDailyForecast
objects, and eachDailyForecast
contains a list ofHourlyForecast
objects.Issue Description:
When running the code to fetch weather data, the
number_of_days
(which controls how many days of forecasts are requested) directly impacts the time taken to generate the structured data. As the number of days increases, the time taken grows exponentially. Here is the summary of iterations:Full Sample Output:
Possible Causes:
We are unsure whether the delay is due to OpenAI’s structured data or the tool calling process. However, we suspect that OpenAI's handling of larger structured data may be the bottleneck. As the data size grows, particularly with nested lists like
HourlyForecast
withinDailyForecast
, the response time increases dramatically.Expected Behavior:
The agent should not experience exponential delays when the
number_of_days
increases. The response time should remain consistent, even if the data complexity increases due to nested structures.Environment Details:
0.0.12
1.57.2
3.10.x
Code:
The text was updated successfully, but these errors were encountered: