Add proper exception handling to langfuse filter pipeline

This commit is contained in:
Benjamin Chauhan 2024-06-27 11:08:15 -07:00
parent 1b3bfe902a
commit 5e73b279d5

View File

@ -15,6 +15,7 @@ import os
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,6 +80,7 @@ class Pipeline:
pass
def set_langfuse(self):
try:
self.langfuse = Langfuse(
secret_key=self.valves.secret_key,
public_key=self.valves.public_key,
@ -86,6 +88,12 @@ class Pipeline:
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__}")