-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the dagster-openai integration library (#19697)
## Summary & Motivation This PR adds a new `dagster-openai` library to our set of libraries. The main goal of this library is to log the Open AI API usage in the metadata. To do so, we need to wrap the methods called through the client, get the results and update the metadata. Initial code snippets was hardcoding 3 methods, but we want to give the user some flexibility. Constraints: - Results must be captured at the method level - the data we seek is included in the OpenAI API response. The results can't be captured at the client level, at teardown for instance. - Not all the methods existing in the OpenAI library should be wrap (private methods, etc.) - Methods are overloaded in the API Resource classes, so wrapping the methods should be done on the instance. **Solution** Implement `OpenAIResource.get_client`, `OpenAIResource.get_client_for_asset` and the function wrapper `with_usage_metadata`. By default, for assets, the methods for the 3 main API Endpoint classes, `Completions`, `Chat` and `Embeddings`, are wrapped when instantiating the client - wrapping the methods allows to log the usage metadata provided in an OpenAI Completion response. If another endpoint should be wrapped, a user can use `with_usage_metadata` to it and log the metadata. `OpenAIResource.get_client` can be used for assets and ops, but the metadata will not be logged for ops. `OpenAIResource.get_client_for_asset` can only be used with assets and the metadata will be logged. ## TO-DOs - [x] implement the resource - [x] add docstrings - [x] implement tests ## How I Tested These Changes Local implementation BK Dogfood in Purina with a toy example
- Loading branch information
1 parent
1c96516
commit 8cdc68f
Showing
15 changed files
with
1,175 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[run] | ||
branch = True |
Oops, something went wrong.