An AI-powered travel planning backend with chatbot capabilities for finding flights, hotels, restaurants, and activities. Built with FastAPI, LangChain, and Groq AI.
- AI Travel Assistant: Chat with an intelligent bot that helps plan your trips
- Flight Search: Find and compare flights between destinations
- Hotel Booking: Search hotels with filters for dates, price range, and amenities
- Restaurant Recommendations: Discover restaurants by cuisine, price, and dietary needs
- Activity & Attraction Search: Find tours, activities, and tourist attractions
- User Authentication: Secure user registration and login system
- Conversation History: Save and retrieve past travel planning conversations
- Backend: FastAPI
- AI/LLM: Groq AI with LangChain
- Database: PostgreSQL with SQLAlchemy
- Authentication: JWT tokens
- Web Scraping: Selenium (for flight data)
- Search: Serper API for web search
POST /auth/register- Register new userPOST /auth/login- User loginPOST /auth/refresh- Refresh access token
POST /chat/- Chat with AI travel assistantGET /chat/conversations- Get user's conversationsGET /chat/conversation/{id}- Get specific conversation
GET /users/me- Get current user profilePUT /users/me- Update user profile
Create a .env file with the following variables:
# Database
DATABASE_URL=postgresql://username:password@localhost:5432/travel_planner
# JWT Authentication
SECRET_KEY=your-secret-key-here
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
# AI/LLM Configuration
GROQ_API_KEY=your-groq-api-key
GROQ_DEFAULT_MODEL=meta-llama/llama-4-maverick-17b-128e-instruct
LLM_TEMPERATURE=0.7
# Search API
SERPER_API_KEY=your-serper-api-key
# Chat Configuration
CHAT_CONTEXT_MESSAGES=20- Clone the repository
git clone <repository-url>
cd travel-ai-planner- Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate-
Install dependencies
pip install -r requirements.txt
-
Set up database
# Create PostgreSQL database
# Update DATABASE_URL in .env file- Run the application
uvicorn src.app:app --reload
The API will be available at http://localhost:8000
import requests
# Start a conversation
response = requests.post("http://localhost:8000/chat/", json={
"messages": [
{"role": "user", "content": "I want to plan a trip to Paris for 3 days"}
]
}, headers={"Authorization": "Bearer YOUR_TOKEN"})
print(response.json())The AI assistant can search for hotels when you ask:
- "Find hotels in Paris for March 15-18"
- "Show me budget hotels in Tokyo"
- "I need a luxury hotel in New York with a spa"
Ask the assistant about dining:
- "Recommend Italian restaurants in Rome"
- "Find vegan restaurants in Berlin"
- "What are the best local restaurants in Barcelona?"
Get activity suggestions:
- "What activities can I do in London?"
- "Find cultural tours in Paris"
- "Show me outdoor activities in Colorado"
src/
├── ai/
│ ├── tools/ # Travel search tools
│ ├── agent.py # AI agent configuration
│ └── conversation.py # Conversation management
├── routes/ # API endpoints
├── schemas/ # Database models
├── app.py # FastAPI application
├── config.py # Database configuration
└── auth_utils.py # Authentication utilities
- Create a new tool in
src/ai/tools/ - Import and add to tools list in
src/ai/agent.py - Update the system prompt to describe the new tool
Once running, visit:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
A Python tool to extract restaurant data from TripAdvisor using both GraphQL API and HTML parsing.
- 🔍 Location Search: Find restaurant listing URLs using TripAdvisor's GraphQL API
- 🍽️ Restaurant Parsing: Extract detailed restaurant data from HTML listings
- 📊 Rich Data Extraction: Get ratings, reviews, cuisine types, prices, and more
- 💾 Data Export: Save results to JSON files
- 🏆 Special Badges: Detect Travelers' Choice awards and sponsored listings
pip install requests beautifulsoup4 lxmlfrom test import TripAdvisorRestaurantAPI
api = TripAdvisorRestaurantAPI()
# Get restaurant URL for a city
search_results = api.search_locations("London")
restaurants_url = api.extract_restaurant_url(search_results)
# Parse restaurants from the URL
restaurants = api.get_restaurants_from_url(restaurants_url)
print(f"Found {len(restaurants)} restaurants")
for restaurant in restaurants:
print(f"{restaurant['name']} - {restaurant['rating']}★")# If you have HTML content from a TripAdvisor restaurant listing page
html_content = """<your HTML content here>"""
restaurants = api.parse_restaurant_listings_html(html_content)python test.pyThis will:
- Search for London restaurants
- Get the restaurant listing URL
- Fetch and parse all restaurants
- Display the first 5 restaurants
- Save all data to JSON files
For each restaurant, the tool extracts:
- Name: Restaurant name
- Rating: Numerical rating (e.g., 4.5)
- Review Count: Number of reviews
- Cuisine Types: List of cuisine categories
- Price Range: Price level (e.g., "$$ - $$$")
- Status: "open" or "closed"
- URL: Full TripAdvisor restaurant page URL
- Travelers Choice 2024: Boolean flag
- Sponsored: Boolean flag for sponsored listings
{
"name": "Bustronome London",
"rating": 4.9,
"review_count": 580,
"cuisine_types": ["French", "European"],
"price_range": "$$$$",
"status": "open",
"url": "https://www.tripadvisor.com/Restaurant_Review-g186338-d19260282...",
"travelers_choice_2024": true,
"sponsored": true
}restaurants_url_<city>_<timestamp>.json: Restaurant listing URLrestaurants_data_<city>_<timestamp>.json: All restaurant dataall_urls_<city>_<timestamp>.json: All available TripAdvisor URLs
Test with a specific HTML snippet:
python test_html_parsing.py- The tool respects TripAdvisor's structure and uses appropriate headers
- Rate limiting is handled automatically
- Error handling for missing elements
- Supports multiple cities and locations
requests: HTTP requestsbeautifulsoup4: HTML parsinglxml: XML/HTML parser (faster)re: Regular expressionsjson: JSON handlingtime: Timestampslogging: Logging functionality