diff --git a/litellm/integrations/langfuse.py b/litellm/integrations/langfuse.py index e6f48a5bd..8ef692b21 100644 --- a/litellm/integrations/langfuse.py +++ b/litellm/integrations/langfuse.py @@ -14,7 +14,7 @@ class LangFuseLogger: try: from langfuse import Langfuse except Exception as e: - raise Exception("\033[91mLangfuse not installed, try running 'pip install langfuse' to fix this error\033[0m", e) + raise Exception(f"\033[91mLangfuse not installed, try running 'pip install langfuse' to fix this error: {e}\033[0m") # Instance variables self.secret_key = os.getenv("LANGFUSE_SECRET_KEY") self.public_key = os.getenv("LANGFUSE_PUBLIC_KEY") diff --git a/litellm/tests/test_langfuse.py b/litellm/tests/test_langfuse.py index 60aaf006d..edab20a38 100644 --- a/litellm/tests/test_langfuse.py +++ b/litellm/tests/test_langfuse.py @@ -1,7 +1,8 @@ import sys import os -import io - +import io, asyncio +import logging +logging.basicConfig(level=logging.DEBUG) sys.path.insert(0, os.path.abspath('../..')) from litellm import completion @@ -11,7 +12,18 @@ litellm.success_callback = ["langfuse"] # litellm.set_verbose = True import time +def test_langfuse_logging_async(): + async def _test_langfuse(): + await litellm.acompletion( + model="gpt-3.5-turbo", + prompt="This is a test", + max_tokens=1000, + temperature=0.7, + ) + response = asyncio.run(_test_langfuse()) + print(f"response: {response}") +test_langfuse_logging_async() def test_langfuse_logging(): try: @@ -27,7 +39,7 @@ def test_langfuse_logging(): except Exception as e: print(e) -test_langfuse_logging() +# test_langfuse_logging() def test_langfuse_logging_custom_generation_name(): try: @@ -47,7 +59,7 @@ def test_langfuse_logging_custom_generation_name(): except Exception as e: print(e) -test_langfuse_logging_custom_generation_name() +# test_langfuse_logging_custom_generation_name() def test_langfuse_logging_function_calling(): function1 = [ @@ -80,7 +92,7 @@ def test_langfuse_logging_function_calling(): except Exception as e: print(e) -test_langfuse_logging_function_calling() +# test_langfuse_logging_function_calling() diff --git a/litellm/utils.py b/litellm/utils.py index c08517ae6..8b2d10207 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -835,8 +835,9 @@ def client(original_function): logging_obj = Logging(model=model, messages=messages, stream=stream, litellm_call_id=kwargs["litellm_call_id"], function_id=function_id, call_type=call_type, start_time=start_time) return logging_obj except Exception as e: # DO NOT BLOCK running the function because of this - print_verbose(f"[Non-Blocking] {traceback.format_exc()}; args - {args}; kwargs - {kwargs}") - pass + import logging + logging.debug(f"[Non-Blocking] {traceback.format_exc()}; args - {args}; kwargs - {kwargs}") + raise e def crash_reporting(*args, **kwargs): if litellm.telemetry: @@ -860,6 +861,7 @@ def client(original_function): def wrapper(*args, **kwargs): start_time = datetime.datetime.now() result = None + logging_obj = None # only set litellm_call_id if its not in kwargs if "litellm_call_id" not in kwargs: @@ -948,17 +950,18 @@ def client(original_function): crash_reporting(*args, **kwargs, exception=traceback_exception) end_time = datetime.datetime.now() # LOG FAILURE - handle streaming failure logging in the _next_ object, remove `handle_failure` once it's deprecated - threading.Thread(target=logging_obj.failure_handler, args=(e, traceback_exception, start_time, end_time)).start() - my_thread = threading.Thread( - target=handle_failure, - args=(e, traceback_exception, start_time, end_time, args, kwargs), - ) # don't interrupt execution of main thread - my_thread.start() - if hasattr(e, "message"): - if ( - liteDebuggerClient and liteDebuggerClient.dashboard_url != None - ): # make it easy to get to the debugger logs if you've initialized it - e.message += f"\n Check the log in your dashboard - {liteDebuggerClient.dashboard_url}" + if logging_obj: + threading.Thread(target=logging_obj.failure_handler, args=(e, traceback_exception, start_time, end_time)).start() + my_thread = threading.Thread( + target=handle_failure, + args=(e, traceback_exception, start_time, end_time, args, kwargs), + ) # don't interrupt execution of main thread + my_thread.start() + if hasattr(e, "message"): + if ( + liteDebuggerClient and liteDebuggerClient.dashboard_url != None + ): # make it easy to get to the debugger logs if you've initialized it + e.message += f"\n Check the log in your dashboard - {liteDebuggerClient.dashboard_url}" raise e return wrapper