(feat) proxy:custom_logger

This commit is contained in:
ishaan-jaff 2023-12-04 09:23:55 -08:00
parent 6599263a85
commit 0d44f5e441

View file

@ -5,24 +5,35 @@ class MyCustomHandler(CustomLogger):
print(f"Pre-API Call") print(f"Pre-API Call")
def log_post_api_call(self, kwargs, response_obj, start_time, end_time): def log_post_api_call(self, kwargs, response_obj, start_time, end_time):
# log: key, user, model, prompt, response, tokens, cost
print(f"Post-API Call") print(f"Post-API Call")
print("\n kwargs\n")
print(kwargs)
model = kwargs["model"]
messages = kwargs["messages"]
cost = litellm.completion_cost(completion_response=response_obj)
# tokens used in response
usage = response_obj.usage
print(usage)
def log_stream_event(self, kwargs, response_obj, start_time, end_time): def log_stream_event(self, kwargs, response_obj, start_time, end_time):
print(f"On Stream") print(f"On Stream")
def log_success_event(self, kwargs, response_obj, start_time, end_time): def log_success_event(self, kwargs, response_obj, start_time, end_time):
print(f"On Success") print(f"On Success")
# log: key, user, model, prompt, response, tokens, cost
print("\n kwargs\n")
print(kwargs)
model = kwargs["model"]
messages = kwargs["messages"]
cost = litellm.completion_cost(completion_response=response_obj)
response = response_obj
# tokens used in response
usage = response_obj["usage"]
print(
f"""
Model: {model},
Messages: {messages},
Usage: {usage},
Cost: {cost},
Response: {response}
"""
)
print(usage)
def log_failure_event(self, kwargs, response_obj, start_time, end_time): def log_failure_event(self, kwargs, response_obj, start_time, end_time):
print(f"On Failure") print(f"On Failure")