🐛 fix(langfuse.py): handle ImportError when importing Langfuse to prevent crashes when Langfuse is not installed

✨ feat(langfuse.py): set cls._instance to None when no Langfuse credentials are found to improve error handling and prevent crashes
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-09-27 16:21:41 -03:00
commit 5590dfe8f3

View file

@ -17,6 +17,7 @@ class LangfuseInstance:
@classmethod @classmethod
def create(cls): def create(cls):
try:
logger.debug("Creating Langfuse instance") logger.debug("Creating Langfuse instance")
from langfuse import Langfuse # type: ignore from langfuse import Langfuse # type: ignore
@ -35,6 +36,9 @@ class LangfuseInstance:
else: else:
logger.debug("No Langfuse credentials found") logger.debug("No Langfuse credentials found")
cls._instance = None cls._instance = None
except ImportError:
logger.debug("Langfuse not installed")
cls._instance = None
@classmethod @classmethod
def update(cls): def update(cls):