Merge pull request #1859 from BerriAI/litellm_allow_using_budgets_without_keys

[Feat] Budgets for 'user' param passed to /chat/completions, /embeddings etc
This commit is contained in:
Ishaan Jaff 2024-02-06 16:32:25 -08:00 committed by GitHub
commit 73c6ce890b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 187 additions and 7 deletions

View file

@ -1234,6 +1234,28 @@ async def reset_budget(prisma_client: PrismaClient):
)
async def _read_request_body(request):
"""
Asynchronous function to read the request body and parse it as JSON or literal data.
Parameters:
- request: The request object to read the body from
Returns:
- dict: Parsed request data as a dictionary
"""
import ast, json
request_data = {}
body = await request.body()
body_str = body.decode()
try:
request_data = ast.literal_eval(body_str)
except:
request_data = json.loads(body_str)
return request_data
# LiteLLM Admin UI - Non SSO Login
html_form = """
<!DOCTYPE html>