I’m trying to cap some API calls in Streamlit.
I’m using the RateLimit lib (ratelimit · PyPI) which works perfectly fine in a Colab.
This package simply decorates any function that makes an API call - e.g.
However it doesn’t work in Streamlit as the script re-runs every time, which I believe may reset the rate limit settings every time?
Things I’ve tried so far:
#2 putting my function in a different file.
FYI, here’s (part of) the GPT3 code which works in a Colab
from ratelimit import limits FIFTEEN_MINUTES = 900 @limits(calls=2, period=FIFTEEN_MINUTES) def responseFunction(): response = openai.Completion.create( engine="davinci", prompt="Social media post: \"The new episode of The Mandalorian was rubbish\"\nSentiment (positive, neutral, negative):") return response responseFunction()
I’ll keep trying other things and will post my findings here
Btw, regarding the API calls, ideally I would like to cap them globally. In other words, I’d like to deploy/share the app then only allow a certain amount of API calls per hour, or per day.