mirror of
https://github.com/NovaOSS/nova-api.git
synced 2024-11-25 16:43:58 +01:00
changes to rate limits, check commit desc
- made comments in config better - added todo to explain weird config - removed some bad stuff in streaming.py
This commit is contained in:
parent
de954998d2
commit
69bc2e33de
|
@ -10,8 +10,17 @@ costs:
|
|||
gpt-4: 30
|
||||
gpt-4-32k: 100
|
||||
|
||||
# bonuses are multiplier for costs:
|
||||
# final_cost = cost * bonus
|
||||
## Roles Explanation
|
||||
|
||||
# Bonuses: They are a multiplier for costs
|
||||
# They work like: final_cost = cost * bonus
|
||||
# Rate limits: Limit the requests of the user
|
||||
# The rate limit is by how many seconds until a new request can be done.
|
||||
|
||||
## TODO: Setup proper rate limit settings for each role
|
||||
## Current settings are:
|
||||
## **NOT MEANT FOR PRODUCTION. DO NOT USE WITH THESE SETTINGS.**
|
||||
|
||||
roles:
|
||||
owner:
|
||||
bonus: 0.1
|
||||
|
|
|
@ -30,7 +30,7 @@ with open('config/config.yml', encoding='utf8') as f:
|
|||
config = yaml.safe_load(f)
|
||||
|
||||
## Where all rate limit requested data will be stored.
|
||||
# Rate limit data is **not persistent**. I.E It will be deleted on server stop/restart.
|
||||
# Rate limit data is **not persistent** (It will be deleted on server stop/restart).
|
||||
user_last_request_time = {}
|
||||
|
||||
DEMO_PAYLOAD = {
|
||||
|
@ -90,6 +90,9 @@ async def stream(
|
|||
incoming_request (starlette.requests.Request, optional): Incoming request. Defaults to None.
|
||||
"""
|
||||
|
||||
## Rate limits user.
|
||||
# If rate limit is exceeded, error code 429. Otherwise, lets the user pass but notes down
|
||||
# last request time for future requests.
|
||||
if user:
|
||||
role = user.get('role', 'default')
|
||||
rate_limit = config['roles'][role]['rate_limit'].get(payload['model'], 10)
|
||||
|
@ -107,9 +110,6 @@ async def stream(
|
|||
db = UserManager()
|
||||
stats = StatsManager()
|
||||
|
||||
## Check if breaching rate limit
|
||||
|
||||
|
||||
is_chat = False
|
||||
is_stream = payload.get('stream', False)
|
||||
|
||||
|
|
Loading…
Reference in a new issue