Bird
0
0

Which approach correctly implements this behavior?

hard📝 Application Q15 of 15
LangChain - LLM and Chat Model Integration
You want to build a Langchain client that automatically retries API calls up to 3 times with increasing wait times (1s, 2s, 4s) when a rate limit error occurs. Which approach correctly implements this behavior?
AUse a loop with try-except catching RateLimitError, sleep increasing seconds, and break on success
BCall client.call() once and if it fails, immediately call it 3 more times without waiting
CWrap client.call() in a single try-except and retry only once after a fixed 5 second wait
DIgnore RateLimitError and rely on API to reset limits automatically
Step-by-Step Solution
Solution:
  1. Step 1: Understand retry logic with increasing wait times

    Retries should be in a loop, catching errors, waiting longer each time before retrying.
  2. Step 2: Evaluate options for correct retry pattern

    Use a loop with try-except catching RateLimitError, sleep increasing seconds, and break on success uses a loop with try-except, sleeps 1, 2, then 4 seconds, and stops on success, matching requirements.
  3. Final Answer:

    Use a loop with try-except catching RateLimitError, sleep increasing seconds, and break on success -> Option A
  4. Quick Check:

    Loop with increasing wait and try-except = correct retry [OK]
Quick Trick: Loop retries with increasing sleep and try-except [OK]
Common Mistakes:
  • Retrying without wait or fixed wait only
  • Retrying fixed times without catching errors
  • Ignoring errors and not retrying

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes