fix(openai.py): ensure openai file object shows up on logs

This commit is contained in:
Krrish Dholakia 2025-04-11 09:55:44 -07:00
parent 0415f1205e
commit b460025e18
2 changed files with 21 additions and 1 deletions

View file

@ -140,6 +140,7 @@ class DBSpendUpdateWriter:
prisma_client=prisma_client, prisma_client=prisma_client,
) )
) )
if disable_spend_logs is False: if disable_spend_logs is False:
await self._insert_spend_log_to_db( await self._insert_spend_log_to_db(
payload=payload, payload=payload,
@ -158,7 +159,7 @@ class DBSpendUpdateWriter:
) )
verbose_proxy_logger.debug("Runs spend update on all tables") verbose_proxy_logger.debug("Runs spend update on all tables")
except Exception: except Exception as e:
verbose_proxy_logger.debug( verbose_proxy_logger.debug(
f"Error updating Prisma database: {traceback.format_exc()}" f"Error updating Prisma database: {traceback.format_exc()}"
) )

View file

@ -290,6 +290,25 @@ class OpenAIFileObject(BaseModel):
_hidden_params: dict = {"response_cost": 0.0} # no cost for writing a file _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"] CREATE_FILE_REQUESTS_PURPOSE = Literal["assistants", "batch", "fine-tune"]