Skip to content

bhavya94/chatbot

Repository files navigation

Hotel Booking Chatbot

A sophisticated AI-powered hotel booking assistant built with Gradio, Claude API, and sentence transformers. This chatbot specializes in helping users find, compare, and book hotels based on their specific requirements using the MultiWOZ dataset.

Project Overview

This project implements a comprehensive hotel booking chatbot that:

  • Uses the Claude API for natural language understanding and generation
  • Leverages sentence transformers for semantic search and embeddings
  • Implements a mock OpenSearch-like client for hotel information retrieval
  • Provides a user-friendly Gradio interface with conversation history
  • Includes comprehensive tools for different hotel-related intents
  • Uses MultiWOZ dataset (focused on hotels) for training and testing

Features

Core Functionality

  • Hotel Search: Find hotels based on location, price, amenities, and other criteria
  • Booking Management: Create, modify, and cancel hotel reservations
  • Information Retrieval: Get detailed information about hotels and their services
  • Recommendations: Receive personalized hotel suggestions based on preferences
  • Comparison: Compare multiple hotels side-by-side
  • Availability Checking: Real-time availability and pricing information

Technical Features

  • Streaming Responses: Real-time chat with Claude API streaming support
  • Semantic Search: Vector-based search using sentence transformers
  • Context Management: Intelligent conversation context and history handling
  • Intent Detection: Automatic detection of user intents (search, booking, info, etc.)
  • Multi-modal Search: Hybrid text and vector search capabilities
  • Session Management: Persistent user sessions with preferences

Architecture

The project follows a modular architecture with clear separation of concerns:

chatbot/
├── clients/                    # External service clients
│   ├── llm_client.py          # Claude API client with streaming
│   ├── embedding_client.py     # Sentence transformers client
│   └── search_client.py        # Mock OpenSearch client
├── context/                    # Context management
│   └── context_manager.py      # Search and load context information
├── prompts/                    # System prompts
│   └── hotel_prompts.py        # Hotel-specific prompt templates
├── tool_collection/            # Intent-specific tools
│   └── hotel_tools.py          # Tools for hotel operations
├── tests/                      # Comprehensive test suite
│   ├── test_clients.py
│   ├── test_context_manager.py
│   ├── test_hotel_tools.py
│   └── test_prompts.py
├── notebooks/                  # Data analysis and experimentation
│   ├── analyze_multiwoz.ipynb  # MultiWOZ dataset analysis
│   └── multiwoz-master/        # Downloaded MultiWOZ dataset
├── app.py                      # Main Gradio application
└── requirements.txt            # Dependencies

Installation

Prerequisites

  • Python 3.8+
  • pip package manager
  • Anthropic API key for Claude

Setup Instructions

  1. Clone the repository:

    git clone <repository-url>
    cd chatbot
  2. Install dependencies:

    pip install -r requirements.txt
  3. Set up environment variables:

    export ANTHROPIC_API_KEY="your-claude-api-key-here"
  4. Download and prepare MultiWOZ dataset (optional - sample data is included): The dataset is automatically downloaded when you run the application for the first time.

Usage

Running the Chatbot

  1. Start the Gradio application:

    python app.py
  2. Open your browser and navigate to:

    http://localhost:7860
    
  3. Start chatting with the hotel booking assistant!

Example Conversations

Hotel Search:

User: "Find me a 4-star hotel in Cambridge with parking and free wifi under £200 per night"
Assistant: "I found several hotels matching your criteria..."

Booking Request:

User: "I want to book the Grand Cambridge Hotel for 2 nights"
Assistant: "I'd be happy to help you book the Grand Cambridge Hotel..."

Information Query:

User: "What amenities does the Luxury Cambridge Resort have?"
Assistant: "The Luxury Cambridge Resort offers excellent amenities including..."

Using the Interface

  • Main Chat: Primary conversation area with the AI assistant
  • Quick Search: Side panel for rapid hotel searches with filters
  • Amenities Filter: Select preferred hotel amenities
  • Session Management: Clear chat or start new sessions
  • Example Prompts: Pre-configured examples to get started

Development

Code Quality Tools

The project includes comprehensive code quality tools:

# Format code with Black
black .

# Lint with flake8
flake8 .

# Sort imports with isort
isort .

# Run tests
pytest

# Run tests with coverage
pytest --cov

Running Tests

# Run all tests
pytest

# Run specific test modules
pytest tests/test_clients.py
pytest tests/test_hotel_tools.py

# Run with verbose output
pytest -v

# Run with coverage report
pytest --cov --cov-report=html

Adding New Features

  1. Implement the core logic in the appropriate module (clients/, context/, tool_collection/)
  2. Add comprehensive tests in the tests/ directory
  3. Update prompts if needed in prompts/hotel_prompts.py
  4. Extend the Gradio interface in app.py if UI changes are needed
  5. Update documentation and this README

Configuration

Environment Variables

  • ANTHROPIC_API_KEY: Your Claude API key (required)
  • SENTENCE_TRANSFORMERS_HOME: Custom cache directory for models (optional)

Customization

  • Model Selection: Change the sentence transformer model in embedding_client.py
  • Search Parameters: Adjust similarity thresholds and result limits in context_manager.py
  • UI Styling: Modify the Gradio interface styling in app.py
  • Hotel Database: Add more hotels to the mock database in hotel_tools.py

Key Dependencies

Core Libraries

  • anthropic: Claude API client for LLM interactions
  • sentence-transformers: Embedding generation and semantic search
  • gradio: Web-based user interface
  • numpy: Numerical computations
  • pandas: Data manipulation and analysis

Development Tools

  • pytest: Testing framework
  • black: Code formatting
  • flake8: Code linting
  • isort: Import sorting

Data Science Stack

  • jupyter: Notebook environment for data analysis
  • matplotlib: Data visualization
  • scipy: Scientific computing

MultiWOZ Dataset Integration

The project uses the MultiWOZ dataset (Multi-Domain Wizard-of-Oz) focused on hotel bookings:

  • Dataset Location: notebooks/multiwoz-master/data/MultiWOZ_2.2/
  • Analysis Notebook: notebooks/analyze_multiwoz.ipynb
  • Focus: Hotel domain dialogues and intent patterns
  • Usage: Training data for intent detection and response patterns

Testing Strategy

The project includes comprehensive tests covering:

Unit Tests

  • Client modules: LLM, embedding, and search client functionality
  • Context management: Session handling and context building
  • Hotel tools: Intent detection, search, and booking operations
  • Prompts: System prompt generation and formatting

Test Coverage

  • Functionality testing: All core features and edge cases
  • Error handling: Invalid inputs and error scenarios
  • Integration testing: Component interaction verification
  • Mock testing: External API calls and dependencies

Performance Considerations

  • Embedding Caching: Sentence transformer models are cached locally
  • Session Management: Efficient in-memory session storage
  • Search Optimization: Vector similarity search with configurable thresholds
  • Response Streaming: Real-time response generation with Claude API

Security Features

  • API Key Protection: Environment variable-based API key management
  • Input Validation: Comprehensive input sanitization
  • Error Handling: Graceful error handling without exposing internals
  • Session Isolation: User sessions are isolated and secure

Future Enhancements

  • Real Hotel Integration: Connect to actual hotel booking APIs
  • Payment Processing: Add secure payment handling
  • Multi-language Support: Extend to support multiple languages
  • Advanced Analytics: User behavior and booking pattern analysis
  • Mobile Interface: React Native or Flutter mobile app
  • Voice Interface: Speech-to-text and text-to-speech capabilities

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes and add tests
  4. Run the test suite (pytest)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Troubleshooting

Common Issues

  1. API Key Error: Ensure ANTHROPIC_API_KEY is set correctly
  2. Model Download: First run may take time to download sentence transformer models
  3. Port Conflicts: Change the port in app.py if 7860 is occupied
  4. Memory Issues: Reduce batch sizes in embedding client for lower memory usage

Getting Help

  • Check the test suite for usage examples
  • Review the notebooks for data analysis examples
  • Examine the Gradio interface code for UI customization
  • Read the comprehensive docstrings in each module

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • MultiWOZ Dataset: University of Cambridge for the dialogue dataset
  • Anthropic: Claude API for advanced language understanding
  • Hugging Face: Sentence transformers and model hosting
  • Gradio: Excellent framework for ML interfaces

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors