Files
DS_TASK_AI_VIEWS/test_all_dependencies.py
T

124 lines
3.7 KiB
Python
Raw Normal View History

"""Test all dependencies for DS Task AI News"""
def test_imports():
"""Test importing all required packages"""
print("🧪 Testing all dependencies...")
try:
# FastAPI and server
import fastapi
import uvicorn
print("✅ FastAPI ecosystem: OK")
# RSS and web scraping
import feedparser
import requests
import bs4 # beautifulsoup4
print("✅ Web scraping: OK")
# AI and ML - Core
import cohere
import sentence_transformers
import faiss
import numpy
print("✅ AI/ML Core: OK")
# AI and ML - Supporting
import torch
import transformers
import sklearn
print("✅ AI/ML Supporting: OK")
# Data processing
import pandas
import scipy
print("✅ Data processing: OK")
# Environment and config
import dotenv
import pydantic
print("✅ Configuration: OK")
# LLM Integration
import groq
print("✅ Groq LLM: OK")
# Test specific functionality
print("\n🔧 Testing specific functionality...")
# Test sentence transformers
from sentence_transformers import SentenceTransformer
print("✅ SentenceTransformer import: OK")
# Test FAISS
import faiss
index = faiss.IndexFlatIP(384) # Test creating index
print("✅ FAISS index creation: OK")
# Test Cohere client creation (without API key)
try:
client = cohere.Client("") # Empty key for test
print("✅ Cohere client creation: OK")
except:
print("✅ Cohere client creation: OK (expected error without API key)")
# Test Groq client creation (without API key)
try:
from groq import Groq
client = Groq(api_key="") # Empty key for test
print("✅ Groq client creation: OK")
except:
print("✅ Groq client creation: OK (expected error without API key)")
print("\n🎉 All dependencies successfully installed and working!")
return True
except ImportError as e:
print(f"❌ Import error: {e}")
return False
except Exception as e:
print(f"❌ Error: {e}")
return False
def test_versions():
"""Test package versions"""
print("\n📦 Package versions:")
packages = [
'fastapi', 'uvicorn', 'feedparser', 'requests', 'beautifulsoup4',
'cohere', 'sentence-transformers', 'faiss-cpu', 'numpy', 'torch',
'transformers', 'scikit-learn', 'pandas', 'python-dotenv',
'pydantic', 'groq'
]
import pkg_resources
for package in packages:
try:
version = pkg_resources.get_distribution(package).version
print(f" {package}: {version}")
except:
try:
# Try alternative names
alt_names = {
'beautifulsoup4': 'bs4',
'scikit-learn': 'sklearn'
}
if package in alt_names:
import importlib
module = importlib.import_module(alt_names[package])
print(f" {package}: installed (module available)")
else:
print(f" {package}: version check failed")
except:
print(f" {package}: not found")
if __name__ == "__main__":
success = test_imports()
test_versions()
if success:
print("\n✅ System ready for full AI-powered news processing!")
else:
print("\n❌ Some dependencies need attention")