From 5e73b279d5c7838ac479d490c39b8d0469dd2d69 Mon Sep 17 00:00:00 2001 From: Benjamin Chauhan Date: Thu, 27 Jun 2024 11:08:15 -0700 Subject: [PATCH] Add proper exception handling to langfuse filter pipeline --- examples/filters/langfuse_filter_pipeline.py | 22 +++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/examples/filters/langfuse_filter_pipeline.py b/examples/filters/langfuse_filter_pipeline.py index f126a708..66dfcad7 100644 --- a/examples/filters/langfuse_filter_pipeline.py +++ b/examples/filters/langfuse_filter_pipeline.py @@ -15,6 +15,7 @@ from utils.pipelines.main import get_last_user_message, get_last_assistant_message from pydantic import BaseModel from langfuse import Langfuse +from langfuse.api.resources.commons.errors.unauthorized_error import UnauthorizedError class Pipeline: @@ -79,13 +80,20 @@ async def on_valves_updated(self): pass def set_langfuse(self): - self.langfuse = Langfuse( - secret_key=self.valves.secret_key, - public_key=self.valves.public_key, - host=self.valves.host, - debug=False, - ) - self.langfuse.auth_check() + try: + self.langfuse = Langfuse( + secret_key=self.valves.secret_key, + public_key=self.valves.public_key, + host=self.valves.host, + debug=False, + ) + self.langfuse.auth_check() + except UnauthorizedError: + print( + "Langfuse credentials incorrect. Please re-enter your Langfuse credentials in the pipeline settings." + ) + except Exception as e: + print(f"Langfuse error: {e} Please re-enter your Langfuse credentials in the pipeline settings.") async def inlet(self, body: dict, user: Optional[dict] = None) -> dict: print(f"inlet:{__name__}")