refactor(meta): unify response types into Actions #671
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What:
Description:
During development of #658 I learned the Conversation API has both items (ListInputItems) and output (Response output) that the Response API offers - they are an exact duplication. This is an insane level of duplication of code with the strict typing in place. Earlier iterations of this library had simple endpoints (completion, chat, etc) - as AI has evolved so has the endpoints which means we need to get creative.
The Response API is massive and we are missing a chunk of typed support, this means following the pattern of other endpoints we have a typed response for the Create endpoint, the Retrieve endpoint, the List endpoint, etc. For the most part these endpoints duplicate logic for parsing nested structures like items, data, tools, tool choices, etc.
This massive amount of duplication has led to bugs (#667) where a new typed thing may be added but not added to all endpoints which is a poor developer experience. You add support for a type and it should naturally work in create, retrieve, etc.
I've introduced
Actions/Responses
(sub-folder after Responses) to house a few parsers:For Response/Conversation classes this means the parsing of complex objects becomes as easy as this.
So code that needs these objects can unify their parsing into one central area. This is a big because updating types and concrete implementations across 6 files is terrible and it shows with how often PRs fail CI.
So now when I return to #658 I can leverage those helpers without adding an insane amount of duplication.
I want the complex types to be managed in these Actions and classes that leverage those Actions (Create, Retrieve and List) can import the types from the Actions. That means they are managed in 1 place!