diff --git a/docs/my-website/docs/proxy/virtual_keys.md b/docs/my-website/docs/proxy/virtual_keys.md index 589e3fec5..525843cfd 100644 --- a/docs/my-website/docs/proxy/virtual_keys.md +++ b/docs/my-website/docs/proxy/virtual_keys.md @@ -19,9 +19,9 @@ Requirements: - Need a postgres database (e.g. [Supabase](https://supabase.com/), [Neon](https://neon.tech/), etc) - Set `DATABASE_URL=postgresql://:@:/` in your env -- Set a `master key`, this is your Proxy Admin key - you can use this to create other keys +- Set a `master key`, this is your Proxy Admin key - you can use this to create other keys (🚨 must start with `sk-`). - ** Set on config.yaml** set your master key under `general_settings:master_key`, example below - - ** Set env variable** set `LITELLM_MASTER_KEY` (**Note: either set this on the config.yaml or in your env** whatever is more convenient for you) + - ** Set env variable** set `LITELLM_MASTER_KEY` (the proxy Dockerfile checks if the `DATABASE_URL` is set and then intializes the DB connection) diff --git a/litellm/llms/prompt_templates/factory.py b/litellm/llms/prompt_templates/factory.py index 0347e5fd6..990bd863d 100644 --- a/litellm/llms/prompt_templates/factory.py +++ b/litellm/llms/prompt_templates/factory.py @@ -700,12 +700,11 @@ def anthropic_messages_pt(messages: list): if new_messages[-1]["role"] == "assistant": for content in new_messages[-1]["content"]: - if content["type"] == "text": + if isinstance(content, dict) and content["type"] == "text": content["text"] = content[ "text" ].rstrip() # no trailing whitespace for final assistant message - return new_messages diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index bb0762b7a..a6510c7f2 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -1090,6 +1090,8 @@ async def update_database( key=hashed_token ) existing_user_obj = await user_api_key_cache.async_get_cache(key=user_id) + if existing_user_obj is not None and isinstance(existing_user_obj, dict): + existing_user_obj = LiteLLM_UserTable(**existing_user_obj) if existing_token_obj.user_id != user_id: # an end-user id was passed in end_user_id = user_id user_ids = [existing_token_obj.user_id, litellm_proxy_budget_name] @@ -1201,7 +1203,8 @@ async def update_database( ) except Exception as e: verbose_proxy_logger.info( - f"Update User DB call failed to execute {str(e)}" + "\033[91m" + + f"Update User DB call failed to execute {str(e)}\n{traceback.format_exc()}" ) ### UPDATE KEY SPEND ### @@ -1241,9 +1244,8 @@ async def update_database( valid_token.spend = new_spend user_api_key_cache.set_cache(key=token, value=valid_token) except Exception as e: - traceback.print_exc() verbose_proxy_logger.info( - f"Update Key DB Call failed to execute - {str(e)}" + f"Update Key DB Call failed to execute - {str(e)}\n{traceback.format_exc()}" ) raise e @@ -1267,7 +1269,7 @@ async def update_database( except Exception as e: verbose_proxy_logger.info( - f"Update Spend Logs DB failed to execute - {str(e)}" + f"Update Spend Logs DB failed to execute - {str(e)}\n{traceback.format_exc()}" ) raise e @@ -1314,7 +1316,7 @@ async def update_database( user_api_key_cache.set_cache(key=token, value=valid_token) except Exception as e: verbose_proxy_logger.info( - f"Update Team DB failed to execute - {str(e)}" + f"Update Team DB failed to execute - {str(e)}\n{traceback.format_exc()}" ) raise e @@ -1323,7 +1325,7 @@ async def update_database( asyncio.create_task(_update_team_db()) asyncio.create_task(_insert_spend_log_to_db()) - verbose_proxy_logger.info("Successfully updated spend in all 3 tables") + verbose_proxy_logger.debug("Runs spend update on all tables") except Exception as e: verbose_proxy_logger.debug( f"Error updating Prisma database: {traceback.format_exc()}" @@ -1439,7 +1441,7 @@ async def update_cache( user_email=None, ) verbose_proxy_logger.debug( - f"_update_user_db: existing spend: {existing_spend_obj}" + f"_update_user_db: existing spend: {existing_spend_obj}; response_cost: {response_cost}" ) if existing_spend_obj is None: existing_spend = 0