|
8 | 8 | from pathlib import Path |
9 | 9 | from rich.console import Console |
10 | 10 | from rich.progress import Progress, SpinnerColumn, TimeElapsedColumn, TextColumn, BarColumn |
| 11 | +import json |
11 | 12 |
|
12 | 13 | import mle |
13 | 14 | from mle.server import app |
|
21 | 22 | ) |
22 | 23 | from mle.utils import CodeChunker |
23 | 24 | from mle.utils import LanceDBMemory, list_files, read_file |
| 25 | +from mle.utils.component_memory import ComponentMemory |
24 | 26 |
|
25 | 27 | console = Console() |
26 | 28 |
|
@@ -303,7 +305,7 @@ def new(name): |
303 | 305 | base_url = questionary.text( |
304 | 306 | "What is your vLLM server URL? (default: http://localhost:8000/v1)" |
305 | 307 | ).ask() or "http://localhost:8000/v1" |
306 | | - |
| 308 | + |
307 | 309 | model_name = questionary.text( |
308 | 310 | "What is the model name loaded in your vLLM server? (default: mistralai/Mistral-7B-Instruct-v0.3B)" |
309 | 311 | ).ask() or "mistralai/Mistral-7B-Instruct-v0.3" |
@@ -433,3 +435,79 @@ def memory(add, rm, update): |
433 | 435 | table_name=table_name, |
434 | 436 | metadata=[{'file': file_path, 'chunk_key': k} for k, _ in chunks.items()] |
435 | 437 | ) |
| 438 | + |
| 439 | + |
| 440 | +@cli.command() |
| 441 | +@click.option('--component', type=click.Choice([ |
| 442 | + 'advisor', 'planner', 'coder', 'debugger', 'reporter', 'chat', |
| 443 | + 'github_summarizer', 'git_summarizer' |
| 444 | +]), help='Component to view traces for') |
| 445 | +@click.option('--limit', default=5, help='Maximum number of traces to show') |
| 446 | +@click.option('--full-output', is_flag=True, help='Show complete output (not truncated)') |
| 447 | +def traces(component, limit, full_output): |
| 448 | + """View execution traces for components.""" |
| 449 | + if not component: |
| 450 | + console.print("[yellow]Please specify a component to view traces for.[/yellow]") |
| 451 | + return |
| 452 | + |
| 453 | + memory = ComponentMemory(os.getcwd()) |
| 454 | + traces = memory.get_recent_traces(component, limit) |
| 455 | + |
| 456 | + if not traces: |
| 457 | + console.print(f"[yellow]No traces found for component: {component}[/yellow]") |
| 458 | + return |
| 459 | + |
| 460 | + console.print(f"[green]Recent {component} traces:[/green]") |
| 461 | + |
| 462 | + for i, trace in enumerate(traces): |
| 463 | + console.print(f"\n[bold cyan]Trace #{i+1}[/bold cyan] ({trace['timestamp']})") |
| 464 | + console.print(f"Status: {trace['status']}") |
| 465 | + |
| 466 | + if trace['execution_time']: |
| 467 | + console.print(f"Execution Time: {trace['execution_time']:.2f} seconds") |
| 468 | + |
| 469 | + # Show context information |
| 470 | + if trace['context']: |
| 471 | + context = trace['context'] |
| 472 | + if isinstance(context, dict) and context: |
| 473 | + console.print("\n[bold]Context:[/bold]") |
| 474 | + for key, value in context.items(): |
| 475 | + console.print(f" {key}: {value}") |
| 476 | + |
| 477 | + # Show full input |
| 478 | + console.print("\n[bold]Input:[/bold]") |
| 479 | + if isinstance(trace['input_data'], str): |
| 480 | + if full_output: |
| 481 | + console.print(trace['input_data']) |
| 482 | + else: |
| 483 | + console.print(trace['input_data'][:500] + ("..." if len(trace['input_data']) > 500 else "")) |
| 484 | + else: |
| 485 | + # Handle dictionary or other structured data |
| 486 | + input_str = json.dumps(trace['input_data'], indent=2) if isinstance(trace['input_data'], (dict, list)) else str(trace['input_data']) |
| 487 | + if full_output: |
| 488 | + console.print(input_str) |
| 489 | + else: |
| 490 | + console.print(input_str[:500] + ("..." if len(input_str) > 500 else "")) |
| 491 | + |
| 492 | + # Show full output |
| 493 | + console.print("\n[bold]Output:[/bold]") |
| 494 | + if isinstance(trace['output_data'], str): |
| 495 | + if full_output: |
| 496 | + console.print(trace['output_data']) |
| 497 | + else: |
| 498 | + console.print(trace['output_data'][:500] + ("..." if len(trace['output_data']) > 500 else "")) |
| 499 | + else: |
| 500 | + # Handle dictionary or other structured data |
| 501 | + output_str = json.dumps(trace['output_data'], indent=2) if isinstance(trace['output_data'], (dict, list)) else str(trace['output_data']) |
| 502 | + if full_output: |
| 503 | + console.print(output_str) |
| 504 | + else: |
| 505 | + console.print(output_str[:500] + ("..." if len(output_str) > 500 else "")) |
| 506 | + |
| 507 | + console.print("-" * 50) |
| 508 | + |
| 509 | + # Show command for seeing full output |
| 510 | + if not full_output and traces: |
| 511 | + console.print("[yellow]Tip: Use --full-output flag to see complete trace data[/yellow]") |
| 512 | + |
| 513 | + memory.close() |
0 commit comments