refactor: fixing linting issues

This commit is contained in:
Krrish Dholakia 2023-11-11 18:52:28 -08:00
parent ae35c13015
commit 45b6f8b853
25 changed files with 223 additions and 133 deletions

View file

@ -39,12 +39,8 @@ from .integrations.weights_biases import WeightsBiasesLogger
from .integrations.custom_logger import CustomLogger
from .integrations.langfuse import LangFuseLogger
from .integrations.litedebugger import LiteDebugger
try:
from openai import OpenAIError as OriginalError
from openai._models import BaseModel as OpenAIObject
except:
from openai.error import OpenAIError as OriginalError
from openai.openai_object import OpenAIObject
from openai import OpenAIError as OriginalError
from openai._models import BaseModel as OpenAIObject
from .exceptions import (
AuthenticationError,
BadRequestError,
@ -353,6 +349,22 @@ class TextChoices(OpenAIObject):
self.logprobs = []
else:
self.logprobs = logprobs
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 __setitem__(self, key, value):
# Allow dictionary-style assignment of attributes
setattr(self, key, value)
class TextCompletionResponse(OpenAIObject):
"""
@ -398,6 +410,22 @@ class TextCompletionResponse(OpenAIObject):
self.usage = Usage()
self._hidden_params = {} # used in case users want to access the original model response
super(TextCompletionResponse, self).__init__(**params)
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 __setitem__(self, key, value):
# Allow dictionary-style assignment of attributes
setattr(self, key, value)
############################################################
def print_verbose(print_statement):