From b460025e18edae532c5d302e5af69c6f62d14f3e Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Fri, 11 Apr 2025 09:55:44 -0700 Subject: [PATCH] fix(openai.py): ensure openai file object shows up on logs --- litellm/proxy/db/db_spend_update_writer.py | 3 ++- litellm/types/llms/openai.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/db/db_spend_update_writer.py b/litellm/proxy/db/db_spend_update_writer.py index 12ae51822c..475049fd14 100644 --- a/litellm/proxy/db/db_spend_update_writer.py +++ b/litellm/proxy/db/db_spend_update_writer.py @@ -140,6 +140,7 @@ class DBSpendUpdateWriter: prisma_client=prisma_client, ) ) + if disable_spend_logs is False: await self._insert_spend_log_to_db( payload=payload, @@ -158,7 +159,7 @@ class DBSpendUpdateWriter: ) verbose_proxy_logger.debug("Runs spend update on all tables") - except Exception: + except Exception as e: verbose_proxy_logger.debug( f"Error updating Prisma database: {traceback.format_exc()}" ) diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.py index f36039cf44..0cb05a710f 100644 --- a/litellm/types/llms/openai.py +++ b/litellm/types/llms/openai.py @@ -290,6 +290,25 @@ class OpenAIFileObject(BaseModel): _hidden_params: dict = {"response_cost": 0.0} # no cost for writing a file + def __contains__(self, key): + # Define custom behavior for the 'in' operator + return hasattr(self, key) + + def get(self, key, default=None): + # Custom .get() method to access attributes with a default value if the attribute doesn't exist + return getattr(self, key, default) + + def __getitem__(self, key): + # Allow dictionary-style access to attributes + return getattr(self, key) + + def json(self, **kwargs): # type: ignore + try: + return self.model_dump() # noqa + except Exception: + # if using pydantic v1 + return self.dict() + CREATE_FILE_REQUESTS_PURPOSE = Literal["assistants", "batch", "fine-tune"]