-
-
Notifications
You must be signed in to change notification settings - Fork 332
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
Add parallel request queuing for Typhoeus request replacement #196
Conversation
Thanks a lot @cguess ! A few questions, to help me understand:
|
@alexrudall happy to answer!
|
Thanks so much for this @cguess . Would you mind adding a section to the README in this PR? How to use this stuff. I generally try to aim docs at a junior dev / with copy-paste commands |
Will do!
…-Christopher Guess
***@***.***
US/WhatsApp/Signal: +1 262.893.1037
PGP: AAE7 5171 0D81 B45B – https://keybase.io/cguess
On Tuesday, Mar 07, 2023 at 08:53, Alex ***@***.*** ***@***.***)> wrote:
Thanks so much for this @cguess (https://github.com/cguess) . Would you mind adding a section to the README in this PR? How to use this stuff. I generally try to aim docs at a junior dev / with copy-paste commands
—
Reply to this email directly, view it on GitHub (#196 (comment)), or unsubscribe (https://github.com/notifications/unsubscribe-auth/AACOYQSJEXVKVA3GGAOW34TW25DYHANCNFSM6AAAAAAVIBCKII).
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@alexrudall I've aded the instructions, I hope they're simple enough. |
Recommend closing. |
@bf4 why? This does work and significantly speeds up requests, if there's more work to be done on it let me know. |
@cguess sorry for the very slow response! In the end we went with Faraday for its modularity and popularity vs Typhoeus. I really appreciate this work and would love to include it somehow, I guess we would need to add the ability to select Typhoeus as an optional dependency and (https://github.com/dleavitt/faraday-typhoeus)[https://github.com/dleavitt/faraday-typhoeus] would love to hear your thoughts if you're still interested in this. Thanks |
All Submissions:
This PR branches off the #194 PR to add optional batch and queuing of requests to better handle large data sets. This is especially useful for generating embeddings of large data sets. In testing it takes the total time to do 32k embeddings from ~5 hours to ~10 minutes.
Usage
To use this new functionality there are two new optional parameters added to the initializer:
client = OpenAI::Client.new(access_token: "xxxxx", rate_limit: 2500, max_concurrency: 10)
New Defaults:
rate_limit
: 2500. The limit for OpenAI is 3000 requests/minute however the timing for it seems to be off a bit so we back off a bit to ensure success without slamming against the limit unpredictably.max_concurrency
: 200. This is the limit default for Typhoeus, but you can change this depending on what you need/can handle. In my testing this doesn't significantly change the the time it takes.After initialization this PR adds a
queue_
version of all the functions that take a block to handle the response i.e.After queuing, a user calls
client.run_queued_requests
to begin the execution. Each finished block will run as the request finishes.Errors and such should be managed in the response block.
Notes:
Client
class and a few of the methods have more than ten lines. I'd recommend relaxing these rules if the team is OK with that, there's no way I could consider to refactor the lengths without adding a significant amount of complexity.VHS
andRSpec
enough to do this properly (I'm aminitest
guy for 17 years). I'm happy to add them if there's help to do so.ruby-limiter
an up-to-date and maintained gem by Shopify (so it's legit) to manage the rate limiting, otherwise you pretty instantly slam up agains the OpenAI rate limiting and it's a lot of work to manage outside this gem.