Skip to content

Commit

Permalink
Merge pull request #128 from Meeeee6623/catch-langfuse-auth-error
Browse files Browse the repository at this point in the history
Fix: Add proper exception handling to langfuse filter pipeline
  • Loading branch information
tjbck committed Jun 27, 2024
2 parents 1b3bfe9 + 5e73b27 commit 3a48d80
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions examples/filters/langfuse_filter_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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__}")
Expand Down

0 comments on commit 3a48d80

Please sign in to comment.