Skip to content
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

refactor(2671): move retry logic and implement tokio_retry #2674

Conversation

onyedikachi-david
Copy link

@onyedikachi-david onyedikachi-david commented Aug 12, 2024

Summary:
This refactor enhances the of API calls by leveraging tokio_retry
for automatic retries with an exponential backoff strategy.

  • Moved retry logic from InferTypeName to Wizard struct
  • Implemented tokio_retry with ExponentialBackoff strategy

Issue Reference(s):
Fixes #2671
/claim #2671

Build & Testing:

  • I ran cargo test successfully.
  • I have run ./lint.sh --mode=fix to fix all linting issues raised by ./lint.sh --mode=check.

Checklist:

  • I have added relevant unit & integration tests.
  • I have updated the documentation accordingly.
  • I have performed a self-review of my code.
  • PR follows the naming convention of <type>(<optional scope>): <title>

@github-actions github-actions bot added the type: chore Routine tasks like conversions, reorganization, and maintenance work. label Aug 12, 2024
@ssddOnTop
Copy link
Member

duplicate of #2673

@onyedikachi-david onyedikachi-david changed the title refactor(2671): implement tokio_retry for API rate limiting refactor(2671): move retry logic and implement tokio_retry Aug 12, 2024
@onyedikachi-david
Copy link
Author

duplicate of #2673

Not at all, if not for slow compilation on my laptop i would have submitted before now. @ssddOnTop

src/cli/llm/wizard.rs Outdated Show resolved Hide resolved
@tusharmath tusharmath marked this pull request as draft August 13, 2024 08:42
Copy link

codecov bot commented Aug 13, 2024

Codecov Report

Attention: Patch coverage is 0% with 51 lines in your changes missing coverage. Please review.

Project coverage is 86.25%. Comparing base (865d1e5) to head (dc811b8).
Report is 22 commits behind head on main.

Files Patch % Lines
src/cli/llm/wizard.rs 0.00% 37 Missing ⚠️
src/cli/llm/infer_type_name.rs 0.00% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2674      +/-   ##
==========================================
- Coverage   86.31%   86.25%   -0.07%     
==========================================
  Files         255      255              
  Lines       24673    24691      +18     
==========================================
  Hits        21297    21297              
- Misses       3376     3394      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@onyedikachi-david onyedikachi-david marked this pull request as ready for review August 13, 2024 11:43
{
Ok(response) => Ok(A::try_from(response)?),
Err(genai::Error::WebModelCall { webc_error, .. }) => {
if webc_error.to_string().contains("429") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pattern match instead of performing a string comparison — webc::Error::ResponseFailedStatus { status: 429, body: _ }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The webc module is not publicly exposed, so i cant match with it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gotten a workaround. I'll make a push soon.

}))?)
}
}
Err(e) => Ok(Err(Error::GenAI(e))?),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just check for the condition here that the status code is 429

@tusharmath
Copy link
Contributor

Moving to draft to reduce noise and improve CI efficiency. Once you are ready just mark it as "ready to review". Feel free to give a shoutout on the #contributors channel on Discord if you want immediate attention.

Copy link

Action required: PR inactive for 5 days.
Status update or closure in 10 days.

@github-actions github-actions bot added state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. and removed state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. labels Aug 19, 2024
@onyedikachi-david onyedikachi-david marked this pull request as ready for review August 20, 2024 23:29
Copy link

Action required: PR inactive for 5 days.
Status update or closure in 10 days.

@tusharmath tusharmath marked this pull request as draft August 27, 2024 18:12
@tusharmath
Copy link
Contributor

Moving to draft to reduce noise and improve CI efficiency. Once you are ready just mark it as "ready to review". Feel free to give a shoutout on the #contributors channel on Discord if you want immediate attention.

@onyedikachi-david onyedikachi-david marked this pull request as ready for review August 27, 2024 21:06
Comment on lines +24 to +25
impl From<genai::Error> for Error {
fn from(err: genai::Error) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might not need so much code since this is merged — jeremychone/rust-genai@736bbec

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, great.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tusharmath Pls, why is this repo: https://github.dev/laststylebender14/rust-genai being used instead of the main genai repo: https://github.com/jeremychone/rust-genai

jeremychone's latest lib.rs:

// region:    --- Modules

mod support;

mod client;
mod common;
mod error;

// -- Flatten
pub use client::*;
pub use common::*;
pub use error::{Error, Result};

// -- Public Modules
pub mod adapter;
pub mod chat;
pub mod resolver;
pub mod webc;

// endregion: --- Modules

laststylebender14's latest commit hash lib.rs:

// region:    --- Modules

mod support;
mod webc;

mod client;
mod common;
mod error;

// -- Flatten
pub use client::*;
pub use common::*;
pub use error::{Error, Result};

// -- Public Modules
pub mod adapter;
pub mod chat;
pub mod resolver;

// endregion: --- Modules

So the webc is still private.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laststylebender14 can you update your Repo with the latest changes? Also can you transfer ownership to tailcallhq

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onyedikachi-david I have taken the latest changes here — https://github.com/tailcallhq/rust-genai

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please apply discussed changes:

Copy link

github-actions bot commented Sep 8, 2024

Action required: PR inactive for 5 days.
Status update or closure in 10 days.

@github-actions github-actions bot added the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Sep 8, 2024
Copy link

PR closed after 10 days of inactivity.

@github-actions github-actions bot closed this Sep 18, 2024
@tusharmath tusharmath reopened this Sep 24, 2024
@github-actions github-actions bot removed the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Sep 24, 2024
Copy link

Action required: PR inactive for 5 days.
Status update or closure in 10 days.

@github-actions github-actions bot added the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Sep 29, 2024
.exec_chat(self.model.as_str(), q.try_into()?, None)
.await?;
A::try_from(response)
let retry_strategy = ExponentialBackoff::from_millis(1000).map(jitter).take(5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the base for the strategy is too high, please, check the doc, it'll be 1 sec -> 16 minutes -> 277 hours -> ... in that case.

Consider:

  • change the base the way base ^ attempt is reasonable
  • you may use the factor option to simplify the math
  • specify max_delay to limit maximum delay
  • don't use jitter, it adds randomness making it harder to mitigate 429 status

Comment on lines 128 to 129
let mut delay = 3;
loop {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loop is not needed anymore

Comment on lines +24 to +25
impl From<genai::Error> for Error {
fn from(err: genai::Error) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please apply discussed changes:

@meskill meskill marked this pull request as draft October 7, 2024 13:33
@meskill
Copy link
Contributor

meskill commented Oct 7, 2024

Hey @onyedikachi-david thanks for the pr. Would you able to finish this based on the discussions?

@github-actions github-actions bot removed the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Oct 7, 2024
@onyedikachi-david
Copy link
Author

Hey @onyedikachi-david thanks for the pr. Would you able to finish this based on the discussions?

Okay. I'll push the needed changes in few hours time.

@onyedikachi-david
Copy link
Author

webc isn't public in this repo: https://github.com/tailcallhq/rust-genai; hence I can't implement some of the requested changes.

Copy link

Action required: PR inactive for 5 days.
Status update or closure in 10 days.

@github-actions github-actions bot added the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Oct 14, 2024
Copy link

PR closed after 10 days of inactivity.

@github-actions github-actions bot closed this Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 Bounty claim state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. type: chore Routine tasks like conversions, reorganization, and maintenance work.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor: Move retry logic from infer_type_name to wizard
4 participants