|
6 | 6 | from pathlib import Path |
7 | 7 | from typing import Dict, Any, List, Annotated, Set, Optional |
8 | 8 |
|
| 9 | +import logfire |
9 | 10 | import typer |
10 | 11 | from loguru import logger |
11 | 12 | from rich.console import Console |
@@ -225,35 +226,38 @@ def import_chatgpt( |
225 | 226 | After importing, run 'basic-memory sync' to index the new files. |
226 | 227 | """ |
227 | 228 |
|
228 | | - try: |
229 | | - if conversations_json: |
230 | | - if not conversations_json.exists(): |
231 | | - typer.echo(f"Error: File not found: {conversations_json}", err=True) |
232 | | - raise typer.Exit(1) |
| 229 | + with logfire.span("import chatgpt"): # pyright: ignore [reportGeneralTypeIssues] |
| 230 | + try: |
| 231 | + if conversations_json: |
| 232 | + if not conversations_json.exists(): |
| 233 | + typer.echo(f"Error: File not found: {conversations_json}", err=True) |
| 234 | + raise typer.Exit(1) |
233 | 235 |
|
234 | | - # Get markdown processor |
235 | | - markdown_processor = asyncio.run(get_markdown_processor()) |
| 236 | + # Get markdown processor |
| 237 | + markdown_processor = asyncio.run(get_markdown_processor()) |
236 | 238 |
|
237 | | - # Process the file |
238 | | - base_path = config.home / folder |
239 | | - console.print(f"\nImporting chats from {conversations_json}...writing to {base_path}") |
240 | | - results = asyncio.run( |
241 | | - process_chatgpt_json(conversations_json, folder, markdown_processor) |
242 | | - ) |
| 239 | + # Process the file |
| 240 | + base_path = config.home / folder |
| 241 | + console.print( |
| 242 | + f"\nImporting chats from {conversations_json}...writing to {base_path}" |
| 243 | + ) |
| 244 | + results = asyncio.run( |
| 245 | + process_chatgpt_json(conversations_json, folder, markdown_processor) |
| 246 | + ) |
243 | 247 |
|
244 | | - # Show results |
245 | | - console.print( |
246 | | - Panel( |
247 | | - f"[green]Import complete![/green]\n\n" |
248 | | - f"Imported {results['conversations']} conversations\n" |
249 | | - f"Containing {results['messages']} messages", |
250 | | - expand=False, |
| 248 | + # Show results |
| 249 | + console.print( |
| 250 | + Panel( |
| 251 | + f"[green]Import complete![/green]\n\n" |
| 252 | + f"Imported {results['conversations']} conversations\n" |
| 253 | + f"Containing {results['messages']} messages", |
| 254 | + expand=False, |
| 255 | + ) |
251 | 256 | ) |
252 | | - ) |
253 | 257 |
|
254 | | - console.print("\nRun 'basic-memory sync' to index the new files.") |
| 258 | + console.print("\nRun 'basic-memory sync' to index the new files.") |
255 | 259 |
|
256 | | - except Exception as e: |
257 | | - logger.error("Import failed") |
258 | | - typer.echo(f"Error during import: {e}", err=True) |
259 | | - raise typer.Exit(1) |
| 260 | + except Exception as e: |
| 261 | + logger.error("Import failed") |
| 262 | + typer.echo(f"Error during import: {e}", err=True) |
| 263 | + raise typer.Exit(1) |
0 commit comments