diff --git a/litellm/integrations/langfuse.py b/litellm/integrations/langfuse.py index 8ef692b21b..b5fd5e584b 100644 --- a/litellm/integrations/langfuse.py +++ b/litellm/integrations/langfuse.py @@ -37,7 +37,7 @@ class LangFuseLogger: f"Langfuse Logging - Enters logging function for model {kwargs}" ) metadata = kwargs.get("metadata", {}) - prompt = [kwargs['messages']] + prompt = [kwargs.get('messages')] # langfuse does not accept jsons for logging metadata # kwargs.pop("litellm_logging_obj", None) @@ -52,7 +52,7 @@ class LangFuseLogger: startTime=start_time, endTime=end_time, model=kwargs['model'], - modelParameters= kwargs, + modelParameters= kwargs["optional_params"], prompt=prompt, completion=response_obj['choices'][0]['message'], usage=Usage( diff --git a/litellm/tests/test_async_fn.py b/litellm/tests/test_async_fn.py index 7e435d4d0d..79fcdb4a73 100644 --- a/litellm/tests/test_async_fn.py +++ b/litellm/tests/test_async_fn.py @@ -11,6 +11,7 @@ sys.path.insert( ) # Adds the parent directory to the system path import litellm from litellm import completion, acompletion, acreate +litellm.num_retries = 3 def test_sync_response(): litellm.set_verbose = True diff --git a/litellm/tests/test_batch_completions.py b/litellm/tests/test_batch_completions.py index 4521f655a4..a49b500a9a 100644 --- a/litellm/tests/test_batch_completions.py +++ b/litellm/tests/test_batch_completions.py @@ -9,6 +9,7 @@ sys.path.insert( ) # Adds the parent directory to the system path from openai import APITimeoutError as Timeout import litellm +litellm.num_retries = 3 from litellm import batch_completion, batch_completion_models, completion, batch_completion_models_all_responses # litellm.set_verbose=True diff --git a/litellm/tests/test_langfuse.py b/litellm/tests/test_langfuse.py index 1b5a164eb0..67bd28a0f8 100644 --- a/litellm/tests/test_langfuse.py +++ b/litellm/tests/test_langfuse.py @@ -1,8 +1,8 @@ import sys import os import io, asyncio -import logging -logging.basicConfig(level=logging.DEBUG) +# import logging +# logging.basicConfig(level=logging.DEBUG) sys.path.insert(0, os.path.abspath('../..')) from litellm import completion @@ -13,6 +13,7 @@ litellm.success_callback = ["langfuse"] import time def test_langfuse_logging_async(): + litellm.set_verbose = True async def _test_langfuse(): return await litellm.acompletion( model="gpt-3.5-turbo", diff --git a/litellm/utils.py b/litellm/utils.py index eb1788e81b..4373ebe1c7 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -816,6 +816,43 @@ class Logging: run_id=self.litellm_call_id, print_verbose=print_verbose, ) + if callback == "helicone": + print_verbose("reaches helicone for logging!") + model = self.model + messages = kwargs["messages"] + heliconeLogger.log_success( + model=model, + messages=messages, + response_obj=result, + start_time=start_time, + end_time=end_time, + print_verbose=print_verbose, + ) + if callback == "langfuse": + print_verbose("reaches langfuse for logging!") + deep_copy = {} + for k, v in self.model_call_details.items(): + if k != "original_response": # copy.deepcopy raises errors as this could be a coroutine + deep_copy[k] = v + langFuseLogger.log_event( + kwargs=deep_copy, + response_obj=result, + start_time=start_time, + end_time=end_time, + print_verbose=print_verbose, + ) + if callback == "traceloop": + deep_copy = {} + for k, v in self.model_call_details.items(): + if k != "original_response": + deep_copy[k] = v + traceloopLogger.log_event( + kwargs=deep_copy, + response_obj=result, + start_time=start_time, + end_time=end_time, + print_verbose=print_verbose, + ) if isinstance(callback, CustomLogger): # custom logger class if self.stream and complete_streaming_response is None: callback.log_stream_event( @@ -2955,37 +2992,6 @@ def handle_success(args, kwargs, result, start_time, end_time): slack_app.client.chat_postMessage( channel=alerts_channel, text=slack_msg ) - elif callback == "helicone": - print_verbose("reaches helicone for logging!") - model = args[0] if len(args) > 0 else kwargs["model"] - messages = args[1] if len(args) > 1 else kwargs["messages"] - heliconeLogger.log_success( - model=model, - messages=messages, - response_obj=result, - start_time=start_time, - end_time=end_time, - print_verbose=print_verbose, - ) - elif callback == "langfuse": - print_verbose("reaches langfuse for logging!") - langFuseLogger.log_event( - kwargs=kwargs, - response_obj=result, - start_time=start_time, - end_time=end_time, - print_verbose=print_verbose, - ) - - elif callback == "traceloop": - traceloopLogger.log_event( - kwargs=kwargs, - response_obj=result, - start_time=start_time, - end_time=end_time, - print_verbose=print_verbose, - ) - elif callback == "aispend": print_verbose("reaches aispend for logging!") model = args[0] if len(args) > 0 else kwargs["model"]