-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Upstash Rate Limiter with callback not working correctly #7279
Comments
Hey there, @kunalhexus! I'm here to help you with any bugs, questions, or contributions you have. Let's tackle this together while we wait for a human maintainer. The issue you're encountering with the Here are a few suggestions to address this:
If these steps do not resolve the issue, you might need to look into the implementation details of |
Hi @kunalhexus, I just tried this myself and reproduced the behavior. The chain doesn't stop. It seems something was changed after implementing Upstash Ratelimit callback. I have found this workaround for now:
In the meantime, I will open a PR to fix this. |
In my case, I was able to reproduce the issue when I added the ratelimitHandler to the callbacks in invoke. However, it works properly when the ratelimitHandler is added to the model’s callbacks. export async function getArchitecture(input: string) {
const cache = new UpstashRedisCache({
client: redis,
ttl: process.env.NODE_ENV === "production" ? CACHE_TTL : DEV_CACHE_TTL,
});
const ratelimitHandler = new UpstashRatelimitHandler(userId, {
requestRatelimit,
});
const { success } = await requestRatelimit.limit(userId);
try {
const model = new ChatGoogleGenerativeAI({
model: "gemini-1.5-flash",
temperature: 1.0,
cache,
callbacks: [ratelimitHandler], // it works
});
const architecture = await model.pipe(parser).invoke(formattedPrompt, {
callbacks: [ratelimitHandler], // unhandledRejection: UpstashRatelimitError: Request limit reached!
});
return { architecture, success };
} catch (error) {
throw error;
}
} |
Checklist
Issue with current documentation:
I am following the instructions on this link for setting up rate limiting with upstash.
I am using
chain.streamEvents
for streaming, passing the rate limit handler to callbacks.On server side, I am able to see the rate limit error, but the chain still continues to run and return the correct response.
Doing something like below is not catching the exception
Idea or request for content:
Looking for correct way to use rate limiter with langchain
The text was updated successfully, but these errors were encountered: