mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-23 07:09:31 +00:00
core[patch]: Correct doc-string for InMemoryRateLimiter (#24730)
Correct the documentaiton string.
This commit is contained in:
parent
d5b4b7e05c
commit
9be6b5a20f
@ -105,23 +105,31 @@ class InMemoryRateLimiter(BaseRateLimiter):
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from langchain_core import InMemoryRateLimiter
|
import time
|
||||||
|
|
||||||
from langchain_core.runnables import RunnableLambda, InMemoryRateLimiter
|
from langchain_core.rate_limiters import InMemoryRateLimiter
|
||||||
|
|
||||||
rate_limiter = InMemoryRateLimiter(
|
rate_limiter = InMemoryRateLimiter(
|
||||||
requests_per_second=100, check_every_n_seconds=0.1, max_bucket_size=10
|
requests_per_second=0.1, # <-- Can only make a request once every 10 seconds!!
|
||||||
|
check_every_n_seconds=0.1, # Wake up every 100 ms to check whether allowed to make a request,
|
||||||
|
max_bucket_size=10, # Controls the maximum burst size.
|
||||||
)
|
)
|
||||||
|
|
||||||
def foo(x: int) -> int:
|
from langchain_anthropic import ChatAnthropic
|
||||||
return x
|
model = ChatAnthropic(
|
||||||
|
model_name="claude-3-opus-20240229",
|
||||||
|
rate_limiter=rate_limiter
|
||||||
|
)
|
||||||
|
|
||||||
|
for _ in range(5):
|
||||||
|
tic = time.time()
|
||||||
|
model.invoke("hello")
|
||||||
|
toc = time.time()
|
||||||
|
print(toc - tic)
|
||||||
|
|
||||||
foo_ = RunnableLambda(foo)
|
|
||||||
chain = rate_limiter | foo_
|
|
||||||
assert chain.invoke(1) == 1
|
|
||||||
|
|
||||||
.. versionadded:: 0.2.24
|
.. versionadded:: 0.2.24
|
||||||
"""
|
""" # noqa: E501
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
Loading…
Reference in New Issue
Block a user