| |
| """ |
| Test Desktop PDF Fix |
| |
| Test that the desktop app now properly suggests PDF reading instead of blocking it. |
| """ |
|
|
| import sys |
| from pathlib import Path |
|
|
| |
| project_root = Path(__file__).parent |
| sys.path.insert(0, str(project_root)) |
|
|
| def test_desktop_pdf_response(): |
| """Test that desktop app now suggests PDF reading for PDF URLs""" |
| |
| print("π§ͺ TESTING DESKTOP PDF RESPONSE") |
| print("=" * 40) |
| |
| try: |
| from atles_desktop_pyqt import ATLESCommunicationThread |
| |
| comm_thread = ATLESCommunicationThread() |
| |
| |
| user_message = "can you read this https://arxiv.org/pdf/2112.09332 and give me a summary" |
| fake_response = "I'll help you with that PDF." |
| |
| print(f"User message: {user_message}") |
| print(f"Testing architectural fixes...") |
| |
| |
| fixed_response = comm_thread._apply_architectural_fixes( |
| fake_response, |
| user_message, |
| {} |
| ) |
| |
| print(f"\nFixed response:") |
| print("-" * 40) |
| print(fixed_response) |
| print("-" * 40) |
| |
| |
| if "FUNCTION_CALL:read_pdf" in fixed_response: |
| print("β
Now suggests PDF reading function!") |
| else: |
| print("β Still not suggesting PDF reading") |
| |
| |
| if "Download and extract text from PDF files" in fixed_response: |
| print("β
Mentions PDF reading capabilities!") |
| else: |
| print("β Doesn't mention PDF capabilities") |
| |
| |
| if "I Cannot:" not in fixed_response or "Read PDF content directly from URLs" not in fixed_response: |
| print("β
No longer says 'I cannot read PDFs'!") |
| else: |
| print("β Still says 'I cannot read PDFs'") |
| |
| return "FUNCTION_CALL:read_pdf" in fixed_response |
| |
| except Exception as e: |
| print(f"β Test failed: {e}") |
| import traceback |
| traceback.print_exc() |
| return False |
|
|
| def test_non_pdf_url(): |
| """Test that non-PDF URLs still use accessibility check""" |
| |
| print(f"\nπ TESTING NON-PDF URL HANDLING") |
| print("=" * 40) |
| |
| try: |
| from atles_desktop_pyqt import ATLESCommunicationThread |
| |
| comm_thread = ATLESCommunicationThread() |
| |
| |
| user_message = "can you check this website https://example.com/article" |
| fake_response = "I'll help you with that URL." |
| |
| print(f"User message: {user_message}") |
| |
| |
| fixed_response = comm_thread._apply_architectural_fixes( |
| fake_response, |
| user_message, |
| {} |
| ) |
| |
| |
| if "FUNCTION_CALL:check_url_accessibility" in fixed_response: |
| print("β
Uses accessibility check for non-PDF URLs") |
| return True |
| else: |
| print("β Doesn't use accessibility check for non-PDF URLs") |
| return False |
| |
| except Exception as e: |
| print(f"β Test failed: {e}") |
| return False |
|
|
| def main(): |
| """Main test runner""" |
| |
| print("π§ DESKTOP PDF FIX TEST") |
| print("=" * 50) |
| |
| print(""" |
| TESTING THE FIX: |
| The desktop app should now suggest FUNCTION_CALL:read_pdf for PDF URLs |
| instead of saying "I cannot read PDF content directly from URLs" |
| """) |
| |
| results = [] |
| results.append(test_desktop_pdf_response()) |
| results.append(test_non_pdf_url()) |
| |
| |
| print(f"\nπ TEST RESULTS") |
| print("=" * 50) |
| |
| passed = sum(results) |
| total = len(results) |
| |
| print(f"Tests passed: {passed}/{total}") |
| |
| if passed == total: |
| print(f"\nπ DESKTOP PDF FIX SUCCESSFUL!") |
| print("β
PDF URLs now suggest read_pdf function") |
| print("β
Non-PDF URLs use accessibility check") |
| print("β
No more 'I cannot read PDFs' messages") |
| |
| print(f"\nπ‘ ATLES should now respond to PDF requests with:") |
| print("'π§ Let me read this PDF for you:'") |
| print("'FUNCTION_CALL:read_pdf:{\"url\": \"...\"}' ") |
| print("Instead of blocking PDF reading!") |
| |
| else: |
| print(f"\nβ οΈ Desktop fix still has issues") |
| if not results[0]: |
| print("β PDF URLs still not handled correctly") |
| if not results[1]: |
| print("β Non-PDF URLs not handled correctly") |
| |
| return passed == total |
|
|
| if __name__ == "__main__": |
| try: |
| success = main() |
| if success: |
| print(f"\n⨠Desktop PDF integration is now working!") |
| else: |
| print(f"\nβ οΈ Desktop PDF integration still needs work.") |
| except KeyboardInterrupt: |
| print(f"\nβΉοΈ Test interrupted") |
| except Exception as e: |
| print(f"\nπ₯ Test error: {e}") |
| import traceback |
| traceback.print_exc() |
|
|