run_auth_workflow.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from r2r import R2RClient
  2. if __name__ == "__main__":
  3. client = R2RClient(
  4. "http://localhost:7272"
  5. ) # Replace with your R2R deployment URL
  6. # Register a new user
  7. user_result = client.register("owen@sciphi.ai", "password123")
  8. print(user_result)
  9. # # Uncomment when running with authentication
  10. # # Verify email (replace with actual verification code sent to the user's email)
  11. # verify_result = client.verify_email("verification_code_here")
  12. # print(verify_result)
  13. # Login immediately (assuming email verification is disabled)
  14. login_result = client.login("user11123@test.com", "password123")
  15. print(login_result)
  16. # Refresh access token
  17. refresh_result = client.refresh_access_token()
  18. print(refresh_result)
  19. import os
  20. # Ingest a sample file for the logged-in user
  21. script_path = os.path.dirname(__file__)
  22. sample_file = os.path.join(script_path, "..", "data", "aristotle.txt")
  23. ingestion_result = client.ingest_files([sample_file])
  24. print(ingestion_result)
  25. # Check the user's documents
  26. documents_overview = client.documents_overview()
  27. print(documents_overview)
  28. # Check that we can search and run RAG over the user documents
  29. search_result = client.search(query="Sample search query")
  30. print(search_result)
  31. rag_result = client.rag(query="Sample search query")
  32. print(rag_result)
  33. # # Uncomment to delete the user account
  34. # # Delete account (requires password confirmation)
  35. # delete_result = client.delete_user(login_result["id"], "password123")
  36. # print(delete_result)
  37. logout_result = client.logout()
  38. print(logout_result)
  39. # {'results': {'message': 'Logged out successfully'}}
  40. # # Login as admin
  41. login_result = client.login("admin@example.com", "change_me_immediately")
  42. # Now you can access superuser features, for example:
  43. users_overview = client.users_overview()
  44. print(users_overview)
  45. # Access system-wide logs
  46. logs = client.logs()
  47. print(logs)
  48. # Perform analytics
  49. analytics_result = client.analytics(
  50. {"search_latencies": "search_latency"},
  51. {"search_latencies": ["basic_statistics", "search_latency"]},
  52. )
  53. print(analytics_result)