From c9b05828ff532601b93c9d1ac2f6510ea0814778 Mon Sep 17 00:00:00 2001 From: John HU Date: Thu, 11 Apr 2024 00:18:35 +0000 Subject: [PATCH] Fix image generation pre call hook call type --- litellm/proxy/proxy_server.py | 92 +++++++++++++++++------------------ 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index dc1e011d63..372c9e8b08 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -352,9 +352,9 @@ async def user_api_key_auth( ### LITELLM-DEFINED AUTH FUNCTION ### #### IF JWT #### """ - LiteLLM supports using JWTs. + LiteLLM supports using JWTs. - Enable this in proxy config, by setting + Enable this in proxy config, by setting ``` general_settings: enable_jwt_auth: true @@ -3249,8 +3249,6 @@ async def completion( user_api_key_dict=user_api_key_dict, data=data, call_type="completion" ) - start_time = time.time() - ### ROUTE THE REQUESTs ### router_model_names = llm_router.model_names if llm_router is not None else [] # skip router if user passed their key @@ -3847,11 +3845,9 @@ async def image_generation( ### CALL HOOKS ### - modify incoming data / reject request before calling the model data = await proxy_logging_obj.pre_call_hook( - user_api_key_dict=user_api_key_dict, data=data, call_type="embeddings" + user_api_key_dict=user_api_key_dict, data=data, call_type="image_generation" ) - start_time = time.time() - ## ROUTE TO CORRECT ENDPOINT ## # skip router if user passed their key if "api_key" in data: @@ -4096,7 +4092,7 @@ async def moderations( user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), ): """ - The moderations endpoint is a tool you can use to check whether content complies with an LLM Providers policies. + The moderations endpoint is a tool you can use to check whether content complies with an LLM Providers policies. Quick Start ``` @@ -4268,7 +4264,7 @@ async def generate_key_fn( - permissions: Optional[dict] - key-specific permissions. Currently just used for turning off pii masking (if connected). Example - {"pii": false} - model_max_budget: Optional[dict] - key-specific model budget in USD. Example - {"text-davinci-002": 0.5, "gpt-3.5-turbo": 0.5}. IF null or {} then no model specific budget. - Examples: + Examples: 1. Allow users to turn on/off pii masking @@ -4573,7 +4569,7 @@ async def info_key_fn_v2( user_api_key_dict: UserAPIKeyAuth = Dependency representing the user's API key Returns: Dict containing the key and its associated information - + Example Curl: ``` curl -X GET "http://0.0.0.0:8000/key/info" \ @@ -4640,7 +4636,7 @@ async def info_key_fn( user_api_key_dict: UserAPIKeyAuth = Dependency representing the user's API key Returns: Dict containing the key and its associated information - + Example Curl: ``` curl -X GET "http://0.0.0.0:8000/key/info?key=sk-02Wr4IAlN3NvPXvL5JVvDA" \ @@ -4700,7 +4696,7 @@ async def spend_key_fn(): """ View all keys created, ordered by spend - Example Request: + Example Request: ``` curl -X GET "http://0.0.0.0:8000/spend/keys" \ -H "Authorization: Bearer sk-1234" @@ -4737,7 +4733,7 @@ async def spend_user_fn( """ View all users created, ordered by spend - Example Request: + Example Request: ``` curl -X GET "http://0.0.0.0:8000/spend/users" \ -H "Authorization: Bearer sk-1234" @@ -6094,21 +6090,21 @@ async def new_team( Returns: - team_id: (str) Unique team id - used for tracking spend across multiple keys for same team id. - _deprecated_params: - - admins: list - A list of user_id's for the admin role - - users: list - A list of user_id's for the user role + _deprecated_params: + - admins: list - A list of user_id's for the admin role + - users: list - A list of user_id's for the user role Example Request: ``` curl --location 'http://0.0.0.0:8000/team/new' \ - + --header 'Authorization: Bearer sk-1234' \ - + --header 'Content-Type: application/json' \ - + --data '{ "team_alias": "my-new-team_2", - "members_with_roles": [{"role": "admin", "user_id": "user-1234"}, + "members_with_roles": [{"role": "admin", "user_id": "user-1234"}, {"role": "user", "user_id": "user-2434"}] }' @@ -6236,7 +6232,7 @@ async def update_team( user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), ): """ - [RECOMMENDED] - use `/team/member_add` to add new team members instead + [RECOMMENDED] - use `/team/member_add` to add new team members instead You can now update team budget / rate limits via /team/update @@ -6249,16 +6245,16 @@ async def update_team( - max_budget: Optional[float] - The maximum budget allocated to the team - all keys for this team_id will have at max this max_budget - models: Optional[list] - A list of models associated with the team - all keys for this team_id will have at most, these models. If empty, assumes all models are allowed. - blocked: bool - Flag indicating if the team is blocked or not - will stop all calls from keys with this team_id. - + Example - update team TPM Limit ``` curl --location 'http://0.0.0.0:8000/team/update' \ - + --header 'Authorization: Bearer sk-1234' \ - + --header 'Content-Type: application/json' \ - + --data-raw '{ "team_id": "litellm-test-client-id-new", "tpm_limit": 100 @@ -6352,7 +6348,7 @@ async def team_member_add( data: TeamMemberAddRequest, user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), ): - """ + """ [BETA] Add new members (either via user_email or user_id) to a team @@ -6361,11 +6357,11 @@ async def team_member_add( ``` curl -X POST 'http://0.0.0.0:8000/team/update' \ - + -H 'Authorization: Bearer sk-1234' \ - + -H 'Content-Type: application/json' \ - + -D '{ "team_id": "45e3e396-ee08-4a61-a88e-16b3ce7e0849", "member": {"role": "user", "user_id": "krrish247652@berri.ai"} @@ -6445,7 +6441,7 @@ async def team_member_delete( data: TeamMemberDeleteRequest, user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), ): - """ + """ [BETA] delete members (either via user_email or user_id) from a team @@ -6453,11 +6449,11 @@ async def team_member_delete( If user doesn't exist, an exception will be raised ``` curl -X POST 'http://0.0.0.0:8000/team/update' \ - + -H 'Authorization: Bearer sk-1234' \ - + -H 'Content-Type: application/json' \ - + -D '{ "team_id": "45e3e396-ee08-4a61-a88e-16b3ce7e0849", "user_id": "krrish247652@berri.ai" @@ -6559,11 +6555,11 @@ async def delete_team( ``` curl --location 'http://0.0.0.0:8000/team/delete' \ - + --header 'Authorization: Bearer sk-1234' \ - + --header 'Content-Type: application/json' \ - + --data-raw '{ "team_ids": ["45e3e396-ee08-4a61-a88e-16b3ce7e0849"] }' @@ -6731,27 +6727,27 @@ async def new_organization( Only admins can create orgs. - # Parameters + # Parameters - `organization_alias`: *str* = The name of the organization. - `models`: *List* = The models the organization has access to. - - `budget_id`: *Optional[str]* = The id for a budget (tpm/rpm/max budget) for the organization. - ### IF NO BUDGET ID - CREATE ONE WITH THESE PARAMS ### + - `budget_id`: *Optional[str]* = The id for a budget (tpm/rpm/max budget) for the organization. + ### IF NO BUDGET ID - CREATE ONE WITH THESE PARAMS ### - `max_budget`: *Optional[float]* = Max budget for org - `tpm_limit`: *Optional[int]* = Max tpm limit for org - `rpm_limit`: *Optional[int]* = Max rpm limit for org - `model_max_budget`: *Optional[dict]* = Max budget for a specific model - `budget_duration`: *Optional[str]* = Frequency of reseting org budget - Case 1: Create new org **without** a budget_id + Case 1: Create new org **without** a budget_id ```bash curl --location 'http://0.0.0.0:4000/organization/new' \ - + --header 'Authorization: Bearer sk-1234' \ - + --header 'Content-Type: application/json' \ - + --data '{ "organization_alias": "my-secret-org", "models": ["model1", "model2"], @@ -6761,15 +6757,15 @@ async def new_organization( ``` - Case 2: Create new org **with** a budget_id + Case 2: Create new org **with** a budget_id ```bash curl --location 'http://0.0.0.0:4000/organization/new' \ - + --header 'Authorization: Bearer sk-1234' \ - + --header 'Content-Type: application/json' \ - + --data '{ "organization_alias": "my-secret-org", "models": ["model1", "model2"], @@ -7346,7 +7342,7 @@ async def async_queue_request( ): global general_settings, user_debug, proxy_logging_obj """ - v2 attempt at a background worker to handle queuing. + v2 attempt at a background worker to handle queuing. Just supports /chat/completion calls currently.