mirror of
https://github.com/NovaOSS/nova-api.git
synced 2024-11-29 09:53:57 +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: 30
|
||||||
gpt-4-32k: 100
|
gpt-4-32k: 100
|
||||||
|
|
||||||
# bonuses are multiplier for costs:
|
## Roles Explanation
|
||||||
# final_cost = cost * bonus
|
|
||||||
|
# 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:
|
roles:
|
||||||
owner:
|
owner:
|
||||||
bonus: 0.1
|
bonus: 0.1
|
||||||
|
|
|
@ -30,7 +30,7 @@ with open('config/config.yml', encoding='utf8') as f:
|
||||||
config = yaml.safe_load(f)
|
config = yaml.safe_load(f)
|
||||||
|
|
||||||
## Where all rate limit requested data will be stored.
|
## 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 = {}
|
user_last_request_time = {}
|
||||||
|
|
||||||
DEMO_PAYLOAD = {
|
DEMO_PAYLOAD = {
|
||||||
|
@ -90,6 +90,9 @@ async def stream(
|
||||||
incoming_request (starlette.requests.Request, optional): Incoming request. Defaults to None.
|
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:
|
if user:
|
||||||
role = user.get('role', 'default')
|
role = user.get('role', 'default')
|
||||||
rate_limit = config['roles'][role]['rate_limit'].get(payload['model'], 10)
|
rate_limit = config['roles'][role]['rate_limit'].get(payload['model'], 10)
|
||||||
|
@ -107,9 +110,6 @@ async def stream(
|
||||||
db = UserManager()
|
db = UserManager()
|
||||||
stats = StatsManager()
|
stats = StatsManager()
|
||||||
|
|
||||||
## Check if breaching rate limit
|
|
||||||
|
|
||||||
|
|
||||||
is_chat = False
|
is_chat = False
|
||||||
is_stream = payload.get('stream', False)
|
is_stream = payload.get('stream', False)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue