diff --git a/litellm/tests/test_lunary.py b/litellm/tests/test_lunary.py index ab62adee06..be98fb102e 100644 --- a/litellm/tests/test_lunary.py +++ b/litellm/tests/test_lunary.py @@ -7,6 +7,7 @@ sys.path.insert(0, os.path.abspath("../..")) from litellm import completion import litellm +litellm.failure_callback = ["lunary"] litellm.success_callback = ["lunary"] litellm.set_verbose = True diff --git a/litellm/utils.py b/litellm/utils.py index af480edd4f..e2a416740a 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -1336,9 +1336,10 @@ class Logging: if callback == "lunary": print_verbose("reaches lunary for logging!") model = self.model + kwargs = self.model_call_details - input = self.model_call_details.get( - "messages", self.model_call_details.get("input", None) + input = kwargs.get( + "messages", kwargs.get("input", None) ) type = ( @@ -1347,15 +1348,27 @@ class Logging: else "llm" ) + # this only logs streaming once, complete_streaming_response exists i.e when stream ends + if self.stream: + print_verbose("reaches lunary for streaming logging!") + print(kwargs) + if "complete_streaming_response" not in kwargs: + break + else: + print_verbose( + "reaches lunary for streaming logging!" + ) + result = kwargs["complete_streaming_response"] + lunaryLogger.log_event( type=type, - kwargs=self.model_call_details, + kwargs=kwargs, event="end", model=model, input=input, - user_id=self.model_call_details.get("user_id", self.model_call_details.get("user", None)), + user_id=kwargs.get("user", None), #user_props=self.model_call_details.get("user_props", None), - extra=self.model_call_details.get("optional_params", {}), + extra=kwargs.get("optional_params", {}), response_obj=result, start_time=start_time, end_time=end_time, @@ -1873,6 +1886,8 @@ class Logging: else "llm" ) + + lunaryLogger.log_event( type=_type, event="error",