🔧 chore(base.py): improve error handling and error message when importing langfuse callback module
🚀 feat(base.py): add langfuse callback import type hint to ignore type checking for better compatibility with dynamic imports
This commit is contained in:
parent
6a974a4efd
commit
894dbdcd40
1 changed files with 7 additions and 2 deletions
|
|
@ -29,16 +29,21 @@ def get_langfuse_callback():
|
|||
if settings.LANGFUSE_PUBLIC_KEY and settings.LANGFUSE_SECRET_KEY:
|
||||
logger.debug("Langfuse credentials found")
|
||||
try:
|
||||
from langfuse.callback import CallbackHandler
|
||||
from langfuse.callback import CallbackHandler # type: ignore
|
||||
|
||||
return CallbackHandler(
|
||||
public_key=settings.LANGFUSE_PUBLIC_KEY,
|
||||
secret_key=settings.LANGFUSE_SECRET_KEY,
|
||||
host=settings.LANGFUSE_HOST,
|
||||
)
|
||||
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Error importing langfuse callback. "
|
||||
"Please install langfuse with `pip install langfuse`"
|
||||
) from exc
|
||||
except Exception as exc:
|
||||
logger.error(f"Error initializing langfuse callback: {exc}")
|
||||
|
||||
return None
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue