Merge pull request #27 from justinh-rahb/ratelimit

Rate Limit Environment Variables
This commit is contained in:
Timothy Jaeryang Baek 2024-05-31 09:51:35 -07:00 committed by GitHub
commit b56782af8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,9 +1,9 @@
import os
from typing import List, Optional
from pydantic import BaseModel
from schemas import OpenAIChatMessage
import time
class Pipeline:
def __init__(self):
# Pipeline filters are only compatible with Open WebUI
@ -33,13 +33,19 @@ class Pipeline:
sliding_window_minutes: Optional[int] = None
# Initialize rate limits
pipelines = os.getenv("RATE_LIMIT_PIPELINES", "*").split(",")
requests_per_minute = int(os.getenv("RATE_LIMIT_REQUESTS_PER_MINUTE", 10))
requests_per_hour = int(os.getenv("RATE_LIMIT_REQUESTS_PER_HOUR", 1000))
sliding_window_limit = int(os.getenv("RATE_LIMIT_SLIDING_WINDOW_LIMIT", 100))
sliding_window_minutes = int(os.getenv("RATE_LIMIT_SLIDING_WINDOW_MINUTES", 15))
self.valves = Valves(
**{
"pipelines": ["*"], # Connect to all pipelines
"requests_per_minute": 10,
"requests_per_hour": 1000,
"sliding_window_limit": 100,
"sliding_window_minutes": 15,
"pipelines": pipelines,
"requests_per_minute": requests_per_minute,
"requests_per_hour": requests_per_hour,
"sliding_window_limit": sliding_window_limit,
"sliding_window_minutes": sliding_window_minutes,
}
)