mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 03:34:10 +00:00
(fix) allow using more than 1 custom callback
This commit is contained in:
parent
5cf3c3dc86
commit
16f598aa3f
1 changed files with 6 additions and 7 deletions
|
@ -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,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue