mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Add a rate limiter for the transcribe API endpoint
This commit is contained in:
@@ -642,6 +642,8 @@ To get started, just start typing below. You can also type / to see a list of co
|
||||
flashStatusInChatInput("⛔️ Configure speech-to-text model on server.")
|
||||
} else if (err.status === 422) {
|
||||
flashStatusInChatInput("⛔️ Audio file to large to process.")
|
||||
} else if (err.status === 429) {
|
||||
flashStatusInChatInput("⛔️ " + err.statusText);
|
||||
} else {
|
||||
flashStatusInChatInput("⛔️ Failed to transcribe audio.")
|
||||
}
|
||||
|
||||
@@ -606,7 +606,13 @@ async def chat_options(
|
||||
|
||||
@api.post("/transcribe")
|
||||
@requires(["authenticated"])
|
||||
async def transcribe(request: Request, common: CommonQueryParams, file: UploadFile = File(...)):
|
||||
async def transcribe(
|
||||
request: Request,
|
||||
common: CommonQueryParams,
|
||||
file: UploadFile = File(...),
|
||||
rate_limiter_per_minute=Depends(ApiUserRateLimiter(requests=1, subscribed_requests=10, window=60)),
|
||||
rate_limiter_per_day=Depends(ApiUserRateLimiter(requests=10, subscribed_requests=600, window=60 * 60 * 24)),
|
||||
):
|
||||
user: KhojUser = request.user.object
|
||||
audio_filename = f"{user.uuid}-{str(uuid.uuid4())}.webm"
|
||||
user_message: str = None
|
||||
|
||||
Reference in New Issue
Block a user