Skip to content

A Python-based travel AI assistant using IBM Watson AI with real-time streaming responses. Features OAuth 2.0 authentication, comprehensive error handling, and intelligent travel recommendations including destinations, budgets, and visa requirements through an interactive Jupyter notebook interface.

Notifications You must be signed in to change notification settings

arshdeepyadavofficial/Travel_Agent_Ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

IBM Watson AI Travel Assistant

A comprehensive travel recommendation system built with IBM Watson AI that provides real-time streaming responses for travel planning queries.

🌟 Overview

This project demonstrates how to integrate with IBM Watson AI to create an intelligent travel assistant that can help with:

  • Destination recommendations
  • Itinerary planning
  • Travel tips and advice
  • Local recommendations
  • Budget-friendly suggestions

πŸ—οΈ Architecture

Core Components

  • Authentication Layer: IBM Cloud IAM OAuth 2.0 integration
  • Streaming API Handler: Real-time response processing using Server-Sent Events (SSE)
  • Error Management: Comprehensive error handling for production use
  • Modular Design: Reusable functions for easy integration

Watson AI Integration

  • Deployment: Uses IBM Watson AI streaming endpoint
  • Region: US-South (us-south.ml.cloud.ibm.com)
  • Protocol: HTTPS with Bearer token authentication
  • Response Format: Server-Sent Events (SSE) with JSON chunks

πŸ“ Project Structure

Travel_Agent_Ai/
β”œβ”€β”€ travel_ai_notebook.ipynb    # Complete Jupyter notebook implementation
β”œβ”€β”€ arsh.env                  # Your API key file (create this)
└── README.md                 # This file

File Descriptions:

  • travel_ai_notebook.ipynb: Interactive notebook with step-by-step implementation and detailed explanations
  • arsh.env: Your API key configuration file (you need to create this)

πŸš€ Quick Start

Prerequisites

  • Python 3.7+
  • IBM Cloud account with Watson AI service
  • Required Python packages: requests, re, json

Installation

  1. Clone or download the project files

    git clone https://github.com/arshdeepyadavofficial/Travel_Agent_Ai
    cd Travel_Agent_Ai
  2. Install dependencies

    pip install requests python-dotenv
  3. Set up your IBM Cloud API key

    Create a .env file in the project root directory and add your IBM Cloud API key:

    API_KEY=your_actual_ibm_cloud_api_key_here

    How to get your IBM Cloud API key:

    1. Go to IBM Cloud Console
    2. Navigate to Manage β†’ Access (IAM) β†’ API Keys
    3. Click Create to generate a new API key
    4. Copy the key and paste it in your .env file

    Important Notes:

    • Never share your API key publicly
    • Add .env to your .gitignore file
    • The key should be without quotes or extra spaces

Usage

Option 1: Run the Jupyter Notebook (Recommended)

  1. Set up your API key (see Configuration section above)
  2. Start Jupyter Notebook
    jupyter notebook travel_ai_notebook.ipynb
  3. Run the cells in order - the notebook includes detailed explanations for each step

Option 2: Run as Python Script (if available)

# Make sure your .env file is set up first
python travel_ai_notebook.py  # If you convert the notebook to .py

πŸ”§ Configuration

Getting Your IBM Cloud API Key

  1. Sign up/Login to IBM Cloud

  2. Create Watson AI Service

    • Go to Catalog β†’ AI/Machine Learning β†’ Watson Studio
    • Create a service instance
  3. Generate API Key

    • Navigate to Manage β†’ Access (IAM) β†’ API Keys
    • Click Create button
    • Give it a name (e.g., "Travel AI Assistant")
    • Copy the generated API key
  4. Create Environment File

    • Create a .env file in your project directory
    • Add your API key:
    API_KEY=your_actual_ibm_cloud_api_key_here

Alternative Configuration Methods

Method 1: Custom Environment File (arsh.env)

API_KEY=your_ibm_cloud_api_key_here

Method 2: System Environment Variables

export API_KEY="your_ibm_cloud_api_key_here"

API Configuration Example

# The code automatically loads from .env or arsh.env files
# Your .env file should contain:
API_KEY=abcd1234-efgh-5678-ijkl-9012mnopqrst

# The deployment URL is already configured in the code

πŸ’‘ Features

βœ… Core Functionality

  • Real-time Streaming: See AI responses as they're generated
  • Authentication: Secure IBM Cloud IAM integration
  • Error Handling: Comprehensive error management
  • Modular Design: Easy to integrate and extend

βœ… Travel Assistant Capabilities

  • Destination planning and recommendations
  • Itinerary creation (multi-day trips)
  • Travel tips and packing advice
  • Local recommendations (restaurants, attractions)
  • Budget-friendly travel options

βœ… Technical Features

  • Server-Sent Events (SSE) parsing
  • JSON response chunk assembly
  • Token-based authentication
  • Production-ready error handling

πŸ“š Usage Examples

Once your API key is configured, you can use the travel assistant for various queries:

Basic Travel Query

# Ask about destinations
travel_ai_assistant("I'm planning a trip to Paris. Can you suggest popular tourist attractions?")

Itinerary Planning

# Multi-day trip planning
travel_ai_assistant("Create a 3-day itinerary for Rome including must-see attractions")

Travel Tips

# Packing and preparation advice
travel_ai_assistant("What should I pack for a winter trip to Iceland?")

Local Recommendations

# Local experiences and food
travel_ai_assistant("Best authentic street food in Bangkok?")

πŸ” Authentication Flow

  1. API Key: Your IBM Cloud API key
  2. Token Request: POST to IBM IAM endpoint
  3. Access Token: Temporary token (expires in 3600 seconds)
  4. Bearer Auth: Token used in Watson AI requests
# Authentication process
token_response = requests.post(IAM_URL, data={
    "apikey": API_KEY,
    "grant_type": 'urn:ibm:params:oauth:grant-type:apikey'
})
access_token = token_response.json()["access_token"]

πŸ“‘ API Response Format

Watson AI returns streaming responses in SSE format:

id: 1
event: message
data: {"choices": [{"index": 0, "delta": {"role": "assistant", "content": "Hello"}}]}

id: 2
event: message  
data: {"choices": [{"index": 0, "delta": {"role": "assistant", "content": " there"}}]}

The code parses these chunks and assembles the complete response.

πŸ› οΈ Technical Details

Streaming Response Parsing

# Extract data lines from SSE format
data_lines = re.findall(r'data: (.+)', response_text)

# Parse each JSON chunk
for line in data_lines:
    data = json.loads(line)
    content = data['choices'][0]['delta'].get('content', '')
    full_response += content

Error Handling

error_messages = {
    400: "Bad Request - Check your message format",
    401: "Unauthorized - Verify your API key", 
    403: "Forbidden - Check your permissions",
    404: "Not Found - Verify deployment URL",
    429: "Rate Limited - Wait before making more requests",
    500: "Internal Server Error - Try again later",
    503: "Service Unavailable - Watson AI may be down"
}

πŸ§ͺ Testing

Test Categories Covered

  1. Destination Planning

    • Family vacation recommendations
    • Beach and food destinations
    • Seasonal travel timing
  2. Itinerary Creation

    • Multi-day trip planning
    • Budget-friendly options
    • City-specific itineraries
  3. Travel Tips

    • Packing recommendations
    • Family travel advice
    • Solo travel safety
  4. Local Recommendations

    • Authentic dining experiences
    • Hidden gems and local culture
    • Cultural experiences

Running Tests

Execute the notebook cells in order, or run:

# Test basic functionality
response = travel_ai_assistant("Plan a trip to Tokyo")

# Test multiple query types
test_multiple_queries()

🚨 Error Codes & Troubleshooting

Code Issue Solution
401 Authentication failed Check API key validity
404 Deployment not found Verify deployment URL
429 Rate limited Wait and retry
500 Server error Retry after delay

Common Issues

  1. "❌ API key is missing" Error

    • Ensure your .env or arsh.env file exists in the project directory
    • Check that the file contains: API_KEY=your_actual_key_here
    • Make sure there are no extra spaces around the equals sign
    • Verify the API key is valid and not expired
  2. Authentication Failures

    • Double-check your API key from IBM Cloud console
    • Ensure the API key has proper permissions for Watson AI
    • Try regenerating the API key if it's old
  3. File Not Found Issues

    • Make sure you're running the notebook from the correct directory
    • Check that .env or arsh.env file is in the same folder as the notebook
    • Use absolute paths if needed
  4. Network Issues

    • Check internet connectivity
    • Verify firewall settings allow HTTPS requests
    • Try different network if corporate firewall blocks requests
  5. Response Parsing Issues

    • Check if your Watson deployment supports streaming
    • Verify API version compatibility
    • Ensure deployment URL is correct

πŸ”„ Production Considerations

Security

  • Store API keys in environment variables
  • Use secrets management systems
  • Implement request rate limiting
  • Add input validation and sanitization

Performance

  • Implement response caching
  • Add connection pooling
  • Use async requests for multiple queries
  • Monitor token expiration

Monitoring

  • Log API usage and errors
  • Track response times
  • Monitor token refresh cycles
  • Set up alerting for failures

πŸš€ Enhancement Ideas

Immediate Improvements

  • Add conversation history support
  • Implement token refresh mechanism
  • Add response caching
  • Create web interface (Flask/FastAPI)

Advanced Features

  • Multi-language support
  • Image integration for destinations
  • Travel booking integration
  • Real-time pricing data
  • Weather integration
  • Map visualization

Integration Options

  • Slack/Discord bot
  • WhatsApp integration
  • Voice assistant compatibility
  • Mobile app backend
  • Chrome extension

πŸ“„ License

This project is open source. Feel free to use, modify, and distribute.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“ž Support

For issues and questions:

  • Check the troubleshooting section
  • Review IBM Watson AI documentation
  • Create an issue in the repository

οΏ½β€πŸ’» Author

Arshdeep Yadav
BTech Computer Science Engineering

GitHub LinkedIn

οΏ½πŸ™ Acknowledgments

  • IBM Watson AI team for the excellent API
  • IBM Cloud documentation and examples
  • Open source community for inspiration

Made with ❀️ for travelers worldwide 🌍✈️

About

A Python-based travel AI assistant using IBM Watson AI with real-time streaming responses. Features OAuth 2.0 authentication, comprehensive error handling, and intelligent travel recommendations including destinations, budgets, and visa requirements through an interactive Jupyter notebook interface.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published