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

Blocking sync code is used when using rate limiting in async code #26913

Closed
5 tasks done
esciara opened this issue Sep 26, 2024 · 1 comment
Closed
5 tasks done

Blocking sync code is used when using rate limiting in async code #26913

esciara opened this issue Sep 26, 2024 · 1 comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate Flagged for investigation.

Comments

@esciara
Copy link
Contributor

esciara commented Sep 26, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

Not applicable as current code runs but is blocked by non async code.

Error Message and Stack Trace (if applicable)

N/A

Description

Async code is using sync (blocking code) when using rate limiting in two places:

In BaseChatModel.astream():

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

In BaseChatModel._agenerate_with_cache():

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

System Info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000
Python Version: 3.12.2 (main, Feb 27 2024, 16:53:46) [Clang 15.0.0 (clang-1500.1.0.2.5)]

Package Information

langchain_core: 0.3.6
langchain: 0.3.1
langchain_community: 0.3.1
langsmith: 0.1.128
langchain_openai: 0.2.1
langchain_text_splitters: 0.3.0

Optional packages not installed

langgraph
langserve

Other Dependencies

aiohttp: 3.10.6
async-timeout: Installed. No version info available.
dataclasses-json: 0.6.7
httpx: 0.27.2
jsonpatch: 1.33
numpy: 1.26.4
openai: 1.48.0
orjson: 3.10.7
packaging: 24.1
pydantic: 2.9.2
pydantic-settings: 2.5.2
PyYAML: 6.0.2
requests: 2.32.3
SQLAlchemy: 2.0.35
tenacity: 8.5.0
tiktoken: 0.7.0
typing-extensions: 4.12.2

@langcarl langcarl bot added the investigate Flagged for investigation. label Sep 26, 2024
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Sep 26, 2024
eyurtsev pushed a commit that referenced this issue Sep 26, 2024
**Description:** Replaced blocking (sync) rate_limiter code in async
methods.

**Issue:** #26913

**Dependencies:** N/A

**Twitter handle:** no need 🤗
@eyurtsev
Copy link
Collaborator

Closing as this was fixed with your PR! thank you

Sheepsta300 pushed a commit to Sheepsta300/langchain that referenced this issue Oct 1, 2024
…ai#26914)

**Description:** Replaced blocking (sync) rate_limiter code in async
methods.

**Issue:** langchain-ai#26913

**Dependencies:** N/A

**Twitter handle:** no need 🤗
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate Flagged for investigation.
Projects
None yet
Development

No branches or pull requests

2 participants