Skip to content

jtooley307/alexaWine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alexa Wine Skill - Complete Migration & Modernization

🍷 A sophisticated Alexa skill for wine enthusiasts - completely migrated from Node.js to Python with modern architecture and production deployment.

🎉 Migration Complete: Node.js → Python

This project showcases a complete migration from the original Node.js implementation to a modern, production-ready Python version with enhanced features and reliability.

🏗️ Architecture Overview

Wine Data Source

  • Primary: Curated local wine database (wineDatabase.json) with detailed wine information

🐍 Python Implementation (Current/Production)

  • Status: ✅ Production Ready & Deployed
  • Runtime: Python 3.11 on AWS Lambda
  • Framework: ASK SDK for Python v3
  • Features: Local curated data source, Bedrock NLG summaries, optional vector/OpenSearch search, enhanced error handling, comprehensive testing

🚀 Production Deployment Status

AWS Lambda Function

  • Function Name: alexa-wine-skill-python
  • Runtime: Python 3.11
  • Region: us-west-2
  • Status: ✅ Active and Fully Functional
  • Last Deployed: See CloudWatch logs for $LATEST version updates

📁 Project Structure

Python Implementation Files

├── lambda_function.py          # Main Alexa skill handlers
├── wine_service.py            # Wine search and data management
├── wine_api_service.py        # Hybrid data source integration
├── config.py                  # Environment configuration
├── utils.py                   # Validation, logging, session utilities
├── requirements.txt           # Python dependencies
├── serverless-python.yml      # Serverless deployment config (optional)
├── deploy.py                  # One-shot zip + Lambda update script (recommended)
├── test_wine_skill.py         # Comprehensive test suite (25 tests)
└── README.md                  # This document (Python-only)

Shared Resources

├── wineDatabase.json         # Curated wine database
├── .env                      # Environment variables
└── test_*.json              # Test payloads for both implementations

🛠️ Setup & Installation

Prerequisites

  • AWS Account with Lambda and Alexa Skills Kit permissions
  • Alexa Developer Console account
  • Python 3.11+
  • AWS CLI configured
  • Serverless Framework CLI (optional; deploy.py is preferred)

Python Version Setup (Recommended)

  1. Install Dependencies

    pip install -r requirements.txt
  2. Configure Environment

    cp .env.example .env
    # Edit .env with your values (see Environment Variables below)
  3. Deploy to AWS Lambda

    # Preferred: simple deploy script that zips and updates the Lambda code
    python3 deploy.py
    
    # Optional: using Serverless Framework instead of deploy.py
    # serverless deploy --config serverless-python.yml
  4. Run Tests

    python -m pytest test_wine_skill.py -v

🧪 Testing

Python Implementation

  • Test Suite: 25 comprehensive tests using pytest
  • Coverage: All handlers, wine service, API integration, error scenarios
  • Run Tests: python -m pytest test_wine_skill.py -v

Lambda Function Testing

# Test LaunchRequest
aws lambda invoke --function-name alexa-wine-skill-python --payload file://test_launch.json response.json

# Test Wine Search
aws lambda invoke --function-name alexa-wine-skill-python --payload file://test_wine_search.json response.json

🔒 Security & Best Practices

✅ Security Improvements

  • Environment Variables: All sensitive data externalized
  • No Hardcoded Secrets: API keys and IDs properly managed
  • Input Validation: Comprehensive sanitization of user input
  • HTTPS Only: All external API calls use secure connections
  • Session Security: Proper session attribute management

✅ Code Quality

  • Modular Architecture: Clean separation of concerns
  • Error Handling: Comprehensive error handling with user-friendly messages
  • Logging: Structured logging throughout the application
  • Type Hints: Python implementation uses type annotations
  • Documentation: Comprehensive inline documentation

🍷 Wine Data Source

Local Curated Database

  • File: wineDatabase.json
  • Content: High-quality wine data with ratings, descriptions, pairings
  • Benefits: Reliable, fast, no external API dependencies

📚 References

This project utilizes the X-Wines dataset for wine recommendations. When using this dataset in production, please cite the following paper:

RecSys-DAN: A Comprehensive Dataset for Research on Recommendation Systems with Deep Learning
Authors: [Authors]
Journal: AI, 2023, 7(1), 20
DOI: https://doi.org/10.3390/ai7010020

Read the full paper here

📊 Features

Wine Search Capabilities

  • Search by wine name, winery, type, region
  • Detailed wine information (price, rating, description)
  • Food pairing recommendations
  • Occasion-based suggestions
  • Session-based follow-up questions

Alexa Integration

  • LaunchRequest handling
  • Intent-based wine searches
  • Session management for multi-turn conversations
  • Error handling with helpful user messages
  • Card displays for visual devices

🔄 Migration History

Phase 1: Node.js Modernization

  • ✅ Upgraded from alexa-sdk v1 to ask-sdk-core v2
  • ✅ Updated Node.js runtime from 4.3 to 18.x
  • ✅ Removed hardcoded Wine.com API key
  • ✅ Added environment variable management
  • ✅ Implemented proper error handling
  • ✅ Added structured logging

Phase 2: Python Migration

  • ✅ Complete rewrite in Python using ASK SDK v3
  • ✅ Local curated data source implementation
  • ✅ Comprehensive test suite with pytest
  • ✅ Production deployment to AWS Lambda
  • ✅ Full feature parity verification
  • ✅ Performance and reliability testing

🚀 Production Status

  • Environment: AWS Lambda (us-west-2)
  • Status: ✅ Live and Operational
  • Last Deployment: Successfully tested and verified
  • Monitoring: CloudWatch logs available
  • Performance: Sub-second response times

📝 Version History

  • v2.0.0 - Complete Python migration with hybrid data sources
  • v1.1.0 - Node.js modernization and security fixes
  • v1.0.1 - Improved logging
  • v1.0.0 - Initial Node.js implementation

⚙️ Environment Variables

Add these to .env as needed:

# Alexa Skill / AWS
ALEXA_SKILL_ID=your_skill_id
AWS_REGION=us-west-2
LOG_LEVEL=info

# Optional: OpenSearch + Vector Search
USE_OPENSEARCH=false
OPENSEARCH_ENDPOINT=https://your-domain
OPENSEARCH_INDEX=xwines-vec-768-1k
OPENSEARCH_USE_IAM=true
USE_VECTOR_SEARCH=false
USE_HYBRID_SEARCH=false

# Optional: Local embeddings via Ollama (for query-time vectors)
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_EMBED_MODEL=nomic-embed-text

OpenSearch Integration (BM25, Vector, Hybrid)

  • Prereqs:
    • OpenSearch index with knn_vector field embedding (dim 768)
    • Optional local Ollama for query embeddings
  • Notes:
    • Enable IAM with OPENSEARCH_USE_IAM=true and ensure credentials are available
    • Hybrid search merges BM25 + kNN; set USE_VECTOR_SEARCH=false to use BM25 only

Data Ingestion with Embeddings

Use ingest_xwines_vectors.py to create the index and ingest wines with embeddings:

python ingest_xwines_vectors.py --csv /path/to/XWines_Slim_1K_wines.csv --index xwines-vec-768-1k --chunk-size 200

Usage Examples (Voice)

  • "Alexa, open Wine Assistant"
  • "Find a Pinot Noir"
  • "What's the price of this wine?"
  • "Tell me about the rating"
  • "Where is this wine from?"
  • "Next wine"
  • "Previous wine"
  • "Start over"

📄 License

MIT


🎯 Ready for Production: The Python implementation is fully deployed and operational on AWS Lambda with comprehensive testing and monitoring in place. 1.0 Jan-06-2017 first certified Alexa release

About

wine app

Resources

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors