forked from phoenix/litellm-mirror
docs(cookbook/proxy_batch_users.ipynb): update cookbook with better instructions
This commit is contained in:
parent
ae7230cf71
commit
a06a0e7b81
1 changed files with 49 additions and 48 deletions
95
cookbook/Proxy_Batch_Users.ipynb
vendored
95
cookbook/Proxy_Batch_Users.ipynb
vendored
|
@ -1,30 +1,21 @@
|
||||||
{
|
{
|
||||||
"nbformat": 4,
|
|
||||||
"nbformat_minor": 0,
|
|
||||||
"metadata": {
|
|
||||||
"colab": {
|
|
||||||
"provenance": []
|
|
||||||
},
|
|
||||||
"kernelspec": {
|
|
||||||
"name": "python3",
|
|
||||||
"display_name": "Python 3"
|
|
||||||
},
|
|
||||||
"language_info": {
|
|
||||||
"name": "python"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"source": [
|
|
||||||
"# Environment Setup"
|
|
||||||
],
|
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"id": "680oRk1af-xJ"
|
"id": "680oRk1af-xJ"
|
||||||
}
|
},
|
||||||
|
"source": [
|
||||||
|
"# Environment Setup"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "X7TgJFn8f88p"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"import csv\n",
|
"import csv\n",
|
||||||
"from typing import Optional\n",
|
"from typing import Optional\n",
|
||||||
|
@ -33,15 +24,15 @@
|
||||||
"\n",
|
"\n",
|
||||||
"proxy_base_url = \"http://0.0.0.0:4000\" # 👈 SET TO PROXY URL\n",
|
"proxy_base_url = \"http://0.0.0.0:4000\" # 👈 SET TO PROXY URL\n",
|
||||||
"master_key = \"sk-1234\" # 👈 SET TO PROXY MASTER KEY"
|
"master_key = \"sk-1234\" # 👈 SET TO PROXY MASTER KEY"
|
||||||
],
|
]
|
||||||
"metadata": {
|
|
||||||
"id": "X7TgJFn8f88p"
|
|
||||||
},
|
|
||||||
"execution_count": null,
|
|
||||||
"outputs": []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "rauw8EOhgBz5"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"## GLOBAL HTTP CLIENT ## - faster http calls\n",
|
"## GLOBAL HTTP CLIENT ## - faster http calls\n",
|
||||||
"class HTTPHandler:\n",
|
"class HTTPHandler:\n",
|
||||||
|
@ -78,27 +69,27 @@
|
||||||
" return response\n",
|
" return response\n",
|
||||||
" except Exception as e:\n",
|
" except Exception as e:\n",
|
||||||
" raise e\n"
|
" raise e\n"
|
||||||
],
|
]
|
||||||
"metadata": {
|
|
||||||
"id": "rauw8EOhgBz5"
|
|
||||||
},
|
|
||||||
"execution_count": null,
|
|
||||||
"outputs": []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"id": "7LXN8zaLgOie"
|
||||||
|
},
|
||||||
"source": [
|
"source": [
|
||||||
"# Import Sheet\n",
|
"# Import Sheet\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Format: | ID | Name | Max Budget |"
|
"Format: | ID | Name | Max Budget |"
|
||||||
],
|
]
|
||||||
"metadata": {
|
|
||||||
"id": "7LXN8zaLgOie"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "oiED0usegPGf"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"async def import_sheet():\n",
|
"async def import_sheet():\n",
|
||||||
" tasks = []\n",
|
" tasks = []\n",
|
||||||
|
@ -126,24 +117,19 @@
|
||||||
" await http_client.close()\n",
|
" await http_client.close()\n",
|
||||||
"\n",
|
"\n",
|
||||||
"asyncio.run(import_sheet())"
|
"asyncio.run(import_sheet())"
|
||||||
],
|
]
|
||||||
"metadata": {
|
|
||||||
"id": "oiED0usegPGf"
|
|
||||||
},
|
|
||||||
"execution_count": null,
|
|
||||||
"outputs": []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"id": "E7M0Li_UgJeZ"
|
||||||
|
},
|
||||||
"source": [
|
"source": [
|
||||||
"# Create Users + Keys\n",
|
"# Create Users + Keys\n",
|
||||||
"\n",
|
"\n",
|
||||||
"- Creates a user\n",
|
"- Creates a user\n",
|
||||||
"- Creates a key with max budget"
|
"- Creates a key with max budget"
|
||||||
],
|
]
|
||||||
"metadata": {
|
|
||||||
"id": "E7M0Li_UgJeZ"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
|
@ -168,7 +154,7 @@
|
||||||
" data=json.dumps({\n",
|
" data=json.dumps({\n",
|
||||||
" \"user_id\": user_id,\n",
|
" \"user_id\": user_id,\n",
|
||||||
" \"key_alias\": f\"{user_id}-key\",\n",
|
" \"key_alias\": f\"{user_id}-key\",\n",
|
||||||
" \"max_budget\": max_budget\n",
|
" \"max_budget\": max_budget # 👈 KEY CHANGE: SETS MAX BUDGET PER KEY\n",
|
||||||
" })\n",
|
" })\n",
|
||||||
" )\n",
|
" )\n",
|
||||||
" print(f\"response: {response.text}\")\n",
|
" print(f\"response: {response.text}\")\n",
|
||||||
|
@ -191,7 +177,8 @@
|
||||||
" data=json.dumps({\n",
|
" data=json.dumps({\n",
|
||||||
" \"user_id\": user_id,\n",
|
" \"user_id\": user_id,\n",
|
||||||
" \"user_alias\": user_name,\n",
|
" \"user_alias\": user_name,\n",
|
||||||
" \"auto_create_key\": False\n",
|
" \"auto_create_key\": False,\n",
|
||||||
|
" # \"max_budget\": max_budget # 👈 [OPTIONAL] Sets max budget per user (if you want to set a max budget across keys)\n",
|
||||||
" })\n",
|
" })\n",
|
||||||
" )\n",
|
" )\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -199,5 +186,19 @@
|
||||||
" return await create_key_with_alias(client=client, user_id=user_id, max_budget=max_budget)\n"
|
" return await create_key_with_alias(client=client, user_id=user_id, max_budget=max_budget)\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"metadata": {
|
||||||
|
"colab": {
|
||||||
|
"provenance": []
|
||||||
|
},
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"name": "python"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 0
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue