mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
(fix) proxy edit custom logger
This commit is contained in:
parent
8adbf35623
commit
b60dc20f4b
1 changed files with 7 additions and 40 deletions
|
@ -31,19 +31,21 @@ class MyCustomHandler(CustomLogger):
|
||||||
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("On Success!")
|
||||||
|
|
||||||
|
async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):
|
||||||
|
print(f"On Async Success!")
|
||||||
# log: key, user, model, prompt, response, tokens, cost
|
# log: key, user, model, prompt, response, tokens, cost
|
||||||
print("\nOn Success")
|
# Access kwargs passed to litellm.completion()
|
||||||
### Access kwargs passed to litellm.completion()
|
|
||||||
model = kwargs.get("model", None)
|
model = kwargs.get("model", None)
|
||||||
messages = kwargs.get("messages", None)
|
messages = kwargs.get("messages", None)
|
||||||
user = kwargs.get("user", None)
|
user = kwargs.get("user", None)
|
||||||
|
|
||||||
#### Access litellm_params passed to litellm.completion(), example access `metadata`
|
# Access litellm_params passed to litellm.completion(), example access `metadata`
|
||||||
litellm_params = kwargs.get("litellm_params", {})
|
litellm_params = kwargs.get("litellm_params", {})
|
||||||
metadata = litellm_params.get("metadata", {}) # headers passed to LiteLLM proxy, can be found here
|
metadata = litellm_params.get("metadata", {}) # headers passed to LiteLLM proxy, can be found here
|
||||||
#################################################
|
|
||||||
|
|
||||||
##### Calculate cost using litellm.completion_cost() #######################
|
# Calculate cost using litellm.completion_cost()
|
||||||
cost = litellm.completion_cost(completion_response=response_obj)
|
cost = litellm.completion_cost(completion_response=response_obj)
|
||||||
response = response_obj
|
response = response_obj
|
||||||
# tokens used in response
|
# tokens used in response
|
||||||
|
@ -99,41 +101,6 @@ class MyCustomHandler(CustomLogger):
|
||||||
print(f"Exception: {e}")
|
print(f"Exception: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):
|
|
||||||
print(f"On Async Success!")
|
|
||||||
# log: key, user, model, prompt, response, tokens, cost
|
|
||||||
print("\nOn Success")
|
|
||||||
# Access kwargs passed to litellm.completion()
|
|
||||||
model = kwargs.get("model", None)
|
|
||||||
messages = kwargs.get("messages", None)
|
|
||||||
user = kwargs.get("user", None)
|
|
||||||
|
|
||||||
# Access litellm_params passed to litellm.completion(), example access `metadata`
|
|
||||||
litellm_params = kwargs.get("litellm_params", {})
|
|
||||||
metadata = litellm_params.get("metadata", {}) # headers passed to LiteLLM proxy, can be found here
|
|
||||||
|
|
||||||
# Calculate cost using litellm.completion_cost()
|
|
||||||
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},
|
|
||||||
User: {user},
|
|
||||||
Usage: {usage},
|
|
||||||
Cost: {cost},
|
|
||||||
Response: {response}
|
|
||||||
Proxy Metadata: {metadata}
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
proxy_handler_instance = MyCustomHandler()
|
proxy_handler_instance = MyCustomHandler()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue