test_llm_functionality.pyā¢2.84 kB
#!/usr/bin/env python3
"""Test LLM functionality with user's credentials"""
import os
from pathlib import Path
def test_llm_functionality():
print("š Testing LLM Functionality with Your Credentials")
print("=" * 50)
try:
from data.multimodal.pdf_reader import EnhancedPDFReader
# Initialize reader with your credentials
reader = EnhancedPDFReader()
print(f"ā
LLM Available: {reader.llm is not None}")
print(f"ā
Embeddings Available: {reader.embeddings is not None}")
print(f"ā
API Key Set: {bool(reader.api_key)}")
print(f"ā
Model: {reader.model_name}")
if reader.llm and reader.embeddings:
# Find a PDF to test with
pdf_dir = Path("data/multimodal/uploaded_pdfs")
pdf_files = list(pdf_dir.glob("*.pdf"))
if pdf_files:
test_pdf = pdf_files[0]
print(f"\nš Testing with PDF: {test_pdf.name}")
# Load and process PDF
success = reader.load_and_process_pdf(str(test_pdf), verbose=True)
if success:
print("ā
PDF loaded successfully for Q&A")
# Test asking a question
question = "What is this document about?"
print(f"\nš¤ Asking: {question}")
answer = reader.ask_question(question, verbose=True)
if answer and not answer.startswith("ā"):
print(f"ā
LLM Answer received:")
print(f"š {answer[:200]}...")
# Test document summary
print(f"\nš Getting document summary...")
summary = reader.get_document_summary(max_length=150)
print(f"ā
Summary: {summary[:150]}...")
print("\nš LLM Functionality: FULLY WORKING!")
return True
else:
print(f"ā LLM Answer failed: {answer}")
return False
else:
print("ā PDF processing failed")
return False
else:
print("ā ļø No PDF files found for testing")
print("ā
LLM components are working (no test files)")
return True
else:
print("ā LLM components not properly initialized")
return False
except Exception as e:
print(f"ā LLM Test failed: {e}")
return False
if __name__ == "__main__":
test_llm_functionality()