Merge pull request #128 from Meeeee6623/catch-langfuse-auth-error

Fix: Add proper exception handling to langfuse filter pipeline
This commit is contained in:
Timothy Jaeryang Baek 2024-06-27 13:53:23 -07:00 committed by GitHub
commit 3a48d80123
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,6 +15,7 @@ import os
from utils.pipelines.main import get_last_user_message, get_last_assistant_message from utils.pipelines.main import get_last_user_message, get_last_assistant_message
from pydantic import BaseModel from pydantic import BaseModel
from langfuse import Langfuse from langfuse import Langfuse
from langfuse.api.resources.commons.errors.unauthorized_error import UnauthorizedError
class Pipeline: class Pipeline:
@ -79,13 +80,20 @@ class Pipeline:
pass pass
def set_langfuse(self): def set_langfuse(self):
self.langfuse = Langfuse( try:
secret_key=self.valves.secret_key, self.langfuse = Langfuse(
public_key=self.valves.public_key, secret_key=self.valves.secret_key,
host=self.valves.host, public_key=self.valves.public_key,
debug=False, host=self.valves.host,
) debug=False,
self.langfuse.auth_check() )
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: async def inlet(self, body: dict, user: Optional[dict] = None) -> dict:
print(f"inlet:{__name__}") print(f"inlet:{__name__}")