mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +00:00
try/except completion_cost + custom logger func
This commit is contained in:
parent
73c25de950
commit
7dc694c704
2 changed files with 80 additions and 30 deletions
36
litellm/integrations/custom_logger.py
Normal file
36
litellm/integrations/custom_logger.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
#### What this does ####
|
||||
# On success, logs events to Promptlayer
|
||||
import dotenv, os
|
||||
import requests
|
||||
import requests
|
||||
|
||||
dotenv.load_dotenv() # Loading env variables using dotenv
|
||||
import traceback
|
||||
|
||||
|
||||
class CustomLogger:
|
||||
# Class variables or attributes
|
||||
def __init__(self, callback_func):
|
||||
# Instance variables
|
||||
self.callback_func = callback_func
|
||||
|
||||
def log_event(self, kwargs, response_obj, start_time, end_time, print_verbose):
|
||||
# Method definition
|
||||
try:
|
||||
print_verbose(
|
||||
f"Custom Logger - Enters logging function for model {kwargs}"
|
||||
)
|
||||
self.callback_func(
|
||||
kwargs, # kwargs to func
|
||||
response_obj,
|
||||
start_time,
|
||||
end_time,
|
||||
print_verbose
|
||||
)
|
||||
print_verbose(
|
||||
f"Custom Logger - final response object: {response_obj}"
|
||||
)
|
||||
except:
|
||||
# traceback.print_exc()
|
||||
print_verbose(f"Custom Logger Error - {traceback.format_exc()}")
|
||||
pass
|
Loading…
Add table
Add a link
Reference in a new issue