(fix) allow using more than 1 custom callback

This commit is contained in:
ishaan-jaff 2023-10-19 08:57:28 -07:00
parent 5cf3c3dc86
commit 16f598aa3f

View file

@ -10,11 +10,10 @@ import traceback
class CustomLogger: class CustomLogger:
# Class variables or attributes # Class variables or attributes
def __init__(self, callback_func): def __init__(self):
# Instance variables pass
self.callback_func = callback_func
def log_input_event(self, model, messages, kwargs, print_verbose): def log_input_event(self, model, messages, kwargs, print_verbose, callback_func):
try: try:
print_verbose( print_verbose(
f"Custom Logger - Enters logging function for model {kwargs}" f"Custom Logger - Enters logging function for model {kwargs}"
@ -22,7 +21,7 @@ class CustomLogger:
kwargs["model"] = model kwargs["model"] = model
kwargs["messages"] = messages kwargs["messages"] = messages
kwargs["log_event_type"] = "pre_api_call" kwargs["log_event_type"] = "pre_api_call"
self.callback_func( callback_func(
kwargs, kwargs,
) )
print_verbose( print_verbose(
@ -32,14 +31,14 @@ class CustomLogger:
traceback.print_exc() traceback.print_exc()
print_verbose(f"Custom Logger Error - {traceback.format_exc()}") print_verbose(f"Custom Logger Error - {traceback.format_exc()}")
def log_event(self, kwargs, response_obj, start_time, end_time, print_verbose): def log_event(self, kwargs, response_obj, start_time, end_time, print_verbose, callback_func):
# Method definition # Method definition
try: try:
print_verbose( print_verbose(
f"Custom Logger - Enters logging function for model {kwargs}" f"Custom Logger - Enters logging function for model {kwargs}"
) )
kwargs["log_event_type"] = "post_api_call" kwargs["log_event_type"] = "post_api_call"
self.callback_func( callback_func(
kwargs, # kwargs to func kwargs, # kwargs to func
response_obj, response_obj,
start_time, start_time,