Umar - Bootcamp
This commit is contained in:
66
week8/community_contributions/w8d5/tests/test_components.py
Normal file
66
week8/community_contributions/w8d5/tests/test_components.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import os
|
||||
import sys
|
||||
from dotenv import load_dotenv
|
||||
|
||||
project_root = os.path.join(os.path.dirname(__file__), '..')
|
||||
sys.path.insert(0, project_root)
|
||||
sys.path.insert(0, os.path.join(project_root, '..', '..'))
|
||||
|
||||
from helpers.travel_deals import ScrapedTravelDeal
|
||||
from agents.travel_scanner_agent import TravelScannerAgent
|
||||
from agents.travel_estimator_agent import TravelEstimatorAgent
|
||||
|
||||
load_dotenv()
|
||||
|
||||
print("\nTesting Travel Deal Hunter Components\n")
|
||||
|
||||
print("1. RSS Feed Scraping")
|
||||
deals = ScrapedTravelDeal.fetch(show_progress=False)
|
||||
print(f"Fetched {len(deals)} deals from RSS feeds")
|
||||
if deals:
|
||||
print(f"Sample: {deals[0].title[:60]}...")
|
||||
|
||||
|
||||
print("\n2. OpenAI Connection")
|
||||
if os.getenv("OPENAI_API_KEY"):
|
||||
print("OPENAI_API_KEY found")
|
||||
else:
|
||||
print("OPENAI_API_KEY not found - set in .env file")
|
||||
|
||||
print("\n3. Scanner Agent")
|
||||
scanner = TravelScannerAgent()
|
||||
print("Scanner agent initialized")
|
||||
|
||||
print("\n4. Deal Scanning")
|
||||
try:
|
||||
selection = scanner.scan(memory=[])
|
||||
if selection and selection.deals:
|
||||
print(f"Scanner found {len(selection.deals)} processed deals")
|
||||
print(f"Sample: {selection.deals[0].destination} - ${selection.deals[0].price}")
|
||||
else:
|
||||
print("No deals returned")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
print("\n5. ChromaDB Access")
|
||||
import chromadb
|
||||
try:
|
||||
db_path = "travel_vectorstore"
|
||||
client = chromadb.PersistentClient(path=db_path)
|
||||
collection = client.get_or_create_collection('travel_deals')
|
||||
count = collection.count()
|
||||
print(f"ChromaDB connected - {count} travel items in collection")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
print("\n6. Estimator Check using travel vectorstore")
|
||||
try:
|
||||
estimator = TravelEstimatorAgent(collection)
|
||||
sample = "Non-stop economy flight from New York to London, duration 7 hours"
|
||||
estimate = estimator.estimate(sample)
|
||||
print(f"Estimate: ${estimate:.2f}")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
print("\nComponent tests complete")
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import os
|
||||
import sys
|
||||
from dotenv import load_dotenv
|
||||
|
||||
project_root = os.path.join(os.path.dirname(__file__), '..')
|
||||
sys.path.insert(0, project_root)
|
||||
sys.path.insert(0, os.path.join(project_root, '..', '..'))
|
||||
|
||||
from agents.travel_estimator_agent import TravelEstimatorAgent
|
||||
from agents.travel_xgboost_agent import TravelXGBoostAgent
|
||||
import chromadb
|
||||
|
||||
load_dotenv()
|
||||
|
||||
print("\nTesting Dual Estimation (LLM vs XGBoost)\n")
|
||||
|
||||
client = chromadb.PersistentClient(path='travel_vectorstore')
|
||||
collection = client.get_collection('travel_deals')
|
||||
|
||||
print("Initializing agents...")
|
||||
llm_agent = TravelEstimatorAgent(collection)
|
||||
xgb_agent = TravelXGBoostAgent(collection)
|
||||
|
||||
test_cases = [
|
||||
"Round trip flight from New York to London, Economy class, non-stop",
|
||||
"5-star Marriott hotel in Paris, 3 nights, Suite with breakfast included",
|
||||
"7-night Caribbean cruise, Balcony cabin, all meals included",
|
||||
"Hertz SUV rental in Los Angeles for 5 days with unlimited mileage",
|
||||
"All-inclusive vacation package to Dubai for 7 nights with Business class flights"
|
||||
]
|
||||
|
||||
print("\n" + "="*80)
|
||||
print(f"{'Travel Deal Description':<60} {'LLM Est.':<12} {'XGB Est.':<12}")
|
||||
print("="*80)
|
||||
|
||||
for desc in test_cases:
|
||||
llm_est = llm_agent.estimate(desc)
|
||||
xgb_est = xgb_agent.estimate(desc)
|
||||
|
||||
short_desc = desc[:57] + "..." if len(desc) > 60 else desc
|
||||
print(f"{short_desc:<60} ${llm_est:>9.2f} ${xgb_est:>9.2f}")
|
||||
|
||||
print("="*80)
|
||||
print("\nDual estimation test complete!")
|
||||
print("\nKey Observations:")
|
||||
print("- LLM: Uses semantic understanding + RAG context")
|
||||
print("- XGBoost: Uses pattern recognition from embeddings")
|
||||
print("- Both trained on same 20K travel deals dataset")
|
||||
|
||||
38
week8/community_contributions/w8d5/tests/test_pipeline.py
Normal file
38
week8/community_contributions/w8d5/tests/test_pipeline.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import os
|
||||
import sys
|
||||
from dotenv import load_dotenv
|
||||
|
||||
project_root = os.path.join(os.path.dirname(__file__), '..')
|
||||
sys.path.insert(0, project_root)
|
||||
sys.path.insert(0, os.path.join(project_root, '..', '..'))
|
||||
|
||||
from helpers.travel_deal_framework import TravelDealFramework
|
||||
|
||||
load_dotenv()
|
||||
|
||||
print("\nTesting Full Travel Deal Pipeline\n")
|
||||
|
||||
print("Initializing framework...")
|
||||
framework = TravelDealFramework()
|
||||
framework.init_agents_as_needed()
|
||||
|
||||
print("\nRunning one iteration...")
|
||||
try:
|
||||
result = framework.run()
|
||||
print(f"\nPipeline completed")
|
||||
print(f"Memory now has {len(result)} opportunities")
|
||||
if result:
|
||||
latest = result[-1]
|
||||
print(f"\nLatest opportunity:")
|
||||
print(f" Destination: {latest.deal.destination}")
|
||||
print(f" Type: {latest.deal.deal_type}")
|
||||
print(f" Price: ${latest.deal.price:.2f}")
|
||||
print(f" Estimate: ${latest.estimate:.2f}")
|
||||
print(f" Discount: ${latest.discount:.2f}")
|
||||
except Exception as e:
|
||||
print(f"\nError during pipeline: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
print("\n")
|
||||
|
||||
Reference in New Issue
Block a user