Spaces:
Running
Running
adityarajwaini
fix(learn-from-book): production readiness pass -- chapter drift, heading rendering, session persistence, full-width layout
c6cdc9f | import sys | |
| import os | |
| import uuid | |
| sys.stdout.reconfigure(encoding='utf-8') | |
| from app.services import rag_service, retrieval_service, pdf_processor | |
| from app.services.tutor_context import build_tutor_context | |
| timings = {} | |
| doc_name = 'SCHAND PHYSICS.pdf' | |
| q = "Let's start learning Chapter 1" | |
| print('=== 1. Testing DocumentIndex & Chapter 1 ===') | |
| doc_idx = pdf_processor.load_document_index('uploads', doc_name) | |
| if doc_idx: | |
| ch1 = doc_idx.get_chapter('1') | |
| if ch1: | |
| print(f"Chapter 1: title='{ch1.title}', pages={ch1.start_page}-{ch1.end_page}, status={ch1.status}") | |
| print(f"Key concepts ({len(ch1.key_concepts)}): {ch1.key_concepts[:6]}") | |
| else: | |
| print("Chapter 1 NOT found in docindex!") | |
| else: | |
| print("DocumentIndex NOT found!") | |
| print('\n=== 2. Testing parse_book_scope ===') | |
| scope = retrieval_service.parse_book_scope(q) | |
| print('Scope:', scope) | |
| print('\n=== 3. Testing vector_store_service / retrieval_service ===') | |
| results = retrieval_service.retrieve( | |
| query=q, | |
| document_name=doc_name, | |
| scope=scope, | |
| timings=timings, | |
| upload_dir='uploads', | |
| ) | |
| print(f'Retrieved {len(results)} chunks:') | |
| for i, r in enumerate(results[:8]): | |
| print(f' Chunk {i+1}: page={r.page_number}, score={r.score:.3f}, source={r.source}') | |
| print(f' Snippet: {r.text[:120]}...') | |
| print('\n=== 4. Testing rag_service.ask ===') | |
| res = rag_service.ask( | |
| question=q, | |
| document_name=doc_name, | |
| session_id=str(uuid.uuid4()), | |
| timings=timings, | |
| upload_dir='uploads', | |
| ) | |
| print(f'Sources count: {len(res.sources)}') | |
| for s in res.sources: | |
| print(f' Source: page={s.page}, score={s.score:.3f}') | |
| print(f'Answer ({len(res.answer)} chars):') | |
| print(res.answer) | |