Enterprise fix

This commit is contained in:
NovaOSS Admins 2023-10-15 20:50:13 +00:00
parent fa1200fba3
commit 45c6a14dc0

View file

@ -71,10 +71,10 @@ async def handle(incoming_request: fastapi.Request):
if ban_reason: if ban_reason:
return await errors.error(403, f'Your NovaAI account has been banned. Reason: \'{ban_reason}\'.', 'Contact the staff for an appeal.') return await errors.error(403, f'Your NovaAI account has been banned. Reason: \'{ban_reason}\'.', 'Contact the staff for an appeal.')
# Checking for enterprise status is_enterprise_key = 'enterprise' in user.get('role', 'default')
enterprise_keys = os.environ.get('ENTERPRISE_KEYS')
if path.startswith('/enterprise/v1') and user.get('api_key') not in enterprise_keys.split(): if path.startswith('/enterprise/v1') and not is_enterprise_key:
return await errors.error(403, 'Enterprise API is not available.', 'Contact the staff for an upgrade.') return await errors.error(403, 'Enterprise API is not available for your API key.', 'Contact the staff for an upgrade.')
if 'account/credits' in path: if 'account/credits' in path:
return fastapi.responses.JSONResponse({'credits': user['credits']}) return fastapi.responses.JSONResponse({'credits': user['credits']})
@ -87,10 +87,13 @@ async def handle(incoming_request: fastapi.Request):
role = user.get('role', 'default') role = user.get('role', 'default')
try: if 'enterprise' in role:
role_cost_multiplier = config['roles'][role]['bonus'] role_cost_multiplier = 0.1
except KeyError: else:
role_cost_multiplier = 1 try:
role_cost_multiplier = config['roles'][role]['bonus']
except KeyError:
role_cost_multiplier = 1
cost = round(cost * role_cost_multiplier) cost = round(cost * role_cost_multiplier)