7
7
8
8
from langfuse import Langfuse
9
9
from langfuse .api .core import ApiError
10
- from langfuse .client import ObservationsView , TraceWithDetails
11
10
from rich import print
12
11
from rich .console import Console
13
12
from rich .table import Table
@@ -106,14 +105,14 @@ def wrapper(*args, **kwargs):
106
105
107
106
@rate_limited
108
107
@retry_with_backoff
109
- def fetch_traces_safe (limit : Optional [int ] = None ) -> List [ TraceWithDetails ] :
108
+ def fetch_traces_safe (limit : Optional [int ] = None ) -> List :
110
109
"""Safely fetch traces with rate limiting and retry logic."""
111
110
return langfuse .fetch_traces (limit = limit ).data
112
111
113
112
114
113
@rate_limited
115
114
@retry_with_backoff
116
- def fetch_observations_safe (trace_id : str ) -> List [ ObservationsView ] :
115
+ def fetch_observations_safe (trace_id : str ) -> List :
117
116
"""Safely fetch observations with rate limiting and retry logic."""
118
117
return langfuse .fetch_observations (trace_id = trace_id ).data
119
118
@@ -193,7 +192,7 @@ def get_total_tokens_used(trace_id: str) -> Tuple[int, int]:
193
192
return 0 , 0
194
193
195
194
196
- def get_trace_stats (trace : TraceWithDetails ) -> Dict [str , Any ]:
195
+ def get_trace_stats (trace ) -> Dict [str , Any ]:
197
196
"""Get comprehensive statistics for a trace.
198
197
199
198
Args:
@@ -251,7 +250,7 @@ def get_trace_stats(trace: TraceWithDetails) -> Dict[str, Any]:
251
250
return {}
252
251
253
252
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 :
255
254
"""Get traces by name using Langfuse API.
256
255
257
256
Args:
@@ -270,7 +269,7 @@ def get_traces_by_name(name: str, limit: int = 1) -> List[TraceWithDetails]:
270
269
return []
271
270
272
271
273
- def get_observations_for_trace (trace_id : str ) -> List [ ObservationsView ] :
272
+ def get_observations_for_trace (trace_id : str ) -> List :
274
273
"""Get all observations for a specific trace.
275
274
276
275
Args:
@@ -289,7 +288,7 @@ def get_observations_for_trace(trace_id: str) -> List[ObservationsView]:
289
288
290
289
def filter_traces_by_date_range (
291
290
start_date : datetime , end_date : datetime , limit : Optional [int ] = None
292
- ) -> List [ TraceWithDetails ] :
291
+ ) -> List :
293
292
"""Filter traces within a specific date range.
294
293
295
294
Args:
@@ -330,9 +329,7 @@ def filter_traces_by_date_range(
330
329
return []
331
330
332
331
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 :
336
333
"""Get traces from the last N days.
337
334
338
335
Args:
@@ -349,7 +346,7 @@ def get_traces_last_n_days(
349
346
350
347
351
348
def get_trace_stats_batch (
352
- traces : List [ TraceWithDetails ] , show_progress : bool = True
349
+ traces : List , show_progress : bool = True
353
350
) -> List [Dict [str , Any ]]:
354
351
"""Get statistics for multiple traces efficiently with progress tracking.
355
352
@@ -375,7 +372,7 @@ def get_trace_stats_batch(
375
372
376
373
377
374
def get_aggregate_stats_for_traces (
378
- traces : List [ TraceWithDetails ] ,
375
+ traces : List ,
379
376
) -> Dict [str , Any ]:
380
377
"""Calculate aggregate statistics for a list of traces.
381
378
@@ -428,9 +425,7 @@ def get_aggregate_stats_for_traces(
428
425
}
429
426
430
427
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" ):
434
429
"""Display trace statistics in a formatted table.
435
430
436
431
Args:
@@ -459,7 +454,7 @@ def display_trace_stats_table(
459
454
console .print (table )
460
455
461
456
462
- def identify_prompt_type (observation : ObservationsView ) -> str :
457
+ def identify_prompt_type (observation ) -> str :
463
458
"""Identify the prompt type based on keywords in the observation's input.
464
459
465
460
Examines the system prompt in observation.input['messages'][0]['content']
0 commit comments