Spaces:
Sleeping
Sleeping
File size: 3,835 Bytes
a4538e5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | #!/usr/bin/env python3
"""
Test script to verify the updated Langchain RAG system works correctly.
"""
import sys
import os
import traceback
def test_imports():
"""Test that all required imports work."""
print("Testing imports...")
try:
# Core imports
from src.search import RAGSearch, RetrievalResult
from src.embedding import EmbeddingPipeline
from src.vectorstore import FaissVectorStore
from src.data_loader import load_all_documents
# External dependencies
import langchain
import langchain_core
import langchain_community
import langchain_text_splitters
import sentence_transformers
import faiss
import pydantic
import fastapi
import uvicorn
print("β
All imports successful!")
# Print versions
print(f"\nPackage versions:")
print(f"- LangChain: {langchain.__version__}")
print(f"- LangChain Core: {langchain_core.__version__}")
print(f"- Sentence Transformers: {sentence_transformers.__version__}")
print(f"- Pydantic: {pydantic.__version__}")
print(f"- FastAPI: {fastapi.__version__}")
return True
except Exception as e:
print(f"β Import failed: {e}")
traceback.print_exc()
return False
def test_basic_functionality():
"""Test basic functionality without requiring API keys."""
print("\nTesting basic functionality...")
try:
from src.embedding import EmbeddingPipeline
from src.vectorstore import FaissVectorStore
# Test embedding pipeline initialization
embedding_pipeline = EmbeddingPipeline()
print("β
Embedding pipeline initialized")
# Test vector store initialization
vector_store = FaissVectorStore(persist_dir="test_store", embedding_model="all-MiniLM-L6-v2")
print("β
Vector store initialized")
return True
except Exception as e:
print(f"β Basic functionality test failed: {e}")
traceback.print_exc()
return False
def test_config_loading():
"""Test configuration file loading."""
print("\nTesting configuration loading...")
try:
import yaml
# Test params.yaml
if os.path.exists("params.yaml"):
with open("params.yaml", "r") as f:
params = yaml.safe_load(f)
print("β
params.yaml loaded successfully")
# Test config.yaml
if os.path.exists("config/config.yaml"):
with open("config/config.yaml", "r") as f:
config = yaml.safe_load(f)
print("β
config/config.yaml loaded successfully")
return True
except Exception as e:
print(f"β Config loading failed: {e}")
return False
def main():
"""Run all tests."""
print("=== Updated Langchain RAG System Test ===\n")
all_passed = True
# Test imports
if not test_imports():
all_passed = False
# Test basic functionality
if not test_basic_functionality():
all_passed = False
# Test config loading
if not test_config_loading():
all_passed = False
print(f"\n{'='*50}")
if all_passed:
print("π All tests passed! Your project is successfully updated!")
print("\nNext steps:")
print("1. Set your GROQ_API_KEY in a .env file")
print("2. Place your documents in the 'data' directory")
print("3. Run: python main.py")
print("4. Or start the API: python app.py")
else:
print("β Some tests failed. Please check the errors above.")
return 1
return 0
if __name__ == "__main__":
sys.exit(main()) |