Skip to content

Commit

Permalink
core[fix]: using async rate limiter methods in async code (#26914)
Browse files Browse the repository at this point in the history
**Description:** Replaced blocking (sync) rate_limiter code in async
methods.

**Issue:** #26913

**Dependencies:** N/A

**Twitter handle:** no need 🤗
  • Loading branch information
esciara committed Sep 26, 2024
1 parent 02f5962 commit c6350d6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libs/core/langchain_core/language_models/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ async def astream(
)

if self.rate_limiter:
self.rate_limiter.acquire(blocking=True)
await self.rate_limiter.aacquire(blocking=True)

generation: Optional[ChatGenerationChunk] = None
try:
Expand Down Expand Up @@ -905,7 +905,7 @@ async def _agenerate_with_cache(
# we usually don't want to rate limit cache lookups, but
# we do want to rate limit API requests.
if self.rate_limiter:
self.rate_limiter.acquire(blocking=True)
await self.rate_limiter.aacquire(blocking=True)

# If stream is not explicitly set, check if implicitly requested by
# astream_events() or astream_log(). Bail out if _astream not implemented
Expand Down

0 comments on commit c6350d6

Please sign in to comment.