-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Fix responses.parse() memory leak from runtime generic schema rebuilds #3092
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from typing import TYPE_CHECKING, List, Iterable, cast | ||
| from typing import TYPE_CHECKING, Any, List, Iterable, cast | ||
| from typing_extensions import TypeVar, assert_never | ||
|
|
||
| import pydantic | ||
|
|
@@ -67,22 +67,28 @@ def parse_response( | |
| continue | ||
|
|
||
| content_list.append( | ||
| construct_type_unchecked( | ||
| type_=ParsedResponseOutputText[TextFormatT], | ||
| value={ | ||
| **item.to_dict(), | ||
| "parsed": parse_text(item.text, text_format=text_format), | ||
| }, | ||
| cast( | ||
| Any, | ||
| construct_type_unchecked( | ||
| type_=ParsedResponseOutputText, | ||
| value={ | ||
| **item.to_dict(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may be missing your concern, but I don’t think
If your concern is with the use of |
||
| "parsed": parse_text(item.text, text_format=text_format), | ||
| }, | ||
| ), | ||
| ) | ||
| ) | ||
|
|
||
| output_list.append( | ||
| construct_type_unchecked( | ||
| type_=ParsedResponseOutputMessage[TextFormatT], | ||
| value={ | ||
| **output.to_dict(), | ||
| "content": content_list, | ||
| }, | ||
| cast( | ||
| Any, | ||
| construct_type_unchecked( | ||
| type_=ParsedResponseOutputMessage, | ||
| value={ | ||
| **output.to_dict(), | ||
| "content": content_list, | ||
| }, | ||
| ), | ||
| ) | ||
| ) | ||
| elif output.type == "function_call": | ||
|
|
@@ -129,12 +135,15 @@ def parse_response( | |
| else: | ||
| output_list.append(output) | ||
|
|
||
| return construct_type_unchecked( | ||
| type_=ParsedResponse[TextFormatT], | ||
| value={ | ||
| **response.to_dict(), | ||
| "output": output_list, | ||
| }, | ||
| return cast( | ||
| ParsedResponse[TextFormatT], | ||
| construct_type_unchecked( | ||
| type_=ParsedResponse, | ||
| value={ | ||
| **response.to_dict(), | ||
| "output": output_list, | ||
| }, | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.