77
88from langfuse import Langfuse
99from langfuse .api .core import ApiError
10- from langfuse .client import ObservationsView , TraceWithDetails
1110from rich import print
1211from rich .console import Console
1312from rich .table import Table
@@ -106,14 +105,14 @@ def wrapper(*args, **kwargs):
106105
107106@rate_limited
108107@retry_with_backoff
109- def fetch_traces_safe (limit : Optional [int ] = None ) -> List [ TraceWithDetails ] :
108+ def fetch_traces_safe (limit : Optional [int ] = None ) -> List :
110109 """Safely fetch traces with rate limiting and retry logic."""
111110 return langfuse .fetch_traces (limit = limit ).data
112111
113112
114113@rate_limited
115114@retry_with_backoff
116- def fetch_observations_safe (trace_id : str ) -> List [ ObservationsView ] :
115+ def fetch_observations_safe (trace_id : str ) -> List :
117116 """Safely fetch observations with rate limiting and retry logic."""
118117 return langfuse .fetch_observations (trace_id = trace_id ).data
119118
@@ -193,7 +192,7 @@ def get_total_tokens_used(trace_id: str) -> Tuple[int, int]:
193192 return 0 , 0
194193
195194
196- def get_trace_stats (trace : TraceWithDetails ) -> Dict [str , Any ]:
195+ def get_trace_stats (trace ) -> Dict [str , Any ]:
197196 """Get comprehensive statistics for a trace.
198197
199198 Args:
@@ -251,7 +250,7 @@ def get_trace_stats(trace: TraceWithDetails) -> Dict[str, Any]:
251250 return {}
252251
253252
254- def get_traces_by_name (name : str , limit : int = 1 ) -> List [ TraceWithDetails ] :
253+ def get_traces_by_name (name : str , limit : int = 1 ) -> List :
255254 """Get traces by name using Langfuse API.
256255
257256 Args:
@@ -270,7 +269,7 @@ def get_traces_by_name(name: str, limit: int = 1) -> List[TraceWithDetails]:
270269 return []
271270
272271
273- def get_observations_for_trace (trace_id : str ) -> List [ ObservationsView ] :
272+ def get_observations_for_trace (trace_id : str ) -> List :
274273 """Get all observations for a specific trace.
275274
276275 Args:
@@ -289,7 +288,7 @@ def get_observations_for_trace(trace_id: str) -> List[ObservationsView]:
289288
290289def filter_traces_by_date_range (
291290 start_date : datetime , end_date : datetime , limit : Optional [int ] = None
292- ) -> List [ TraceWithDetails ] :
291+ ) -> List :
293292 """Filter traces within a specific date range.
294293
295294 Args:
@@ -330,9 +329,7 @@ def filter_traces_by_date_range(
330329 return []
331330
332331
333- def get_traces_last_n_days (
334- days : int , limit : Optional [int ] = None
335- ) -> List [TraceWithDetails ]:
332+ def get_traces_last_n_days (days : int , limit : Optional [int ] = None ) -> List :
336333 """Get traces from the last N days.
337334
338335 Args:
@@ -349,7 +346,7 @@ def get_traces_last_n_days(
349346
350347
351348def get_trace_stats_batch (
352- traces : List [ TraceWithDetails ] , show_progress : bool = True
349+ traces : List , show_progress : bool = True
353350) -> List [Dict [str , Any ]]:
354351 """Get statistics for multiple traces efficiently with progress tracking.
355352
@@ -375,7 +372,7 @@ def get_trace_stats_batch(
375372
376373
377374def get_aggregate_stats_for_traces (
378- traces : List [ TraceWithDetails ] ,
375+ traces : List ,
379376) -> Dict [str , Any ]:
380377 """Calculate aggregate statistics for a list of traces.
381378
@@ -428,9 +425,7 @@ def get_aggregate_stats_for_traces(
428425 }
429426
430427
431- def display_trace_stats_table (
432- traces : List [TraceWithDetails ], title : str = "Trace Statistics"
433- ):
428+ def display_trace_stats_table (traces : List , title : str = "Trace Statistics" ):
434429 """Display trace statistics in a formatted table.
435430
436431 Args:
@@ -459,7 +454,7 @@ def display_trace_stats_table(
459454 console .print (table )
460455
461456
462- def identify_prompt_type (observation : ObservationsView ) -> str :
457+ def identify_prompt_type (observation ) -> str :
463458 """Identify the prompt type based on keywords in the observation's input.
464459
465460 Examines the system prompt in observation.input['messages'][0]['content']
0 commit comments