An intelligent travel recommendation system built with FastAPI and LangChain that suggests personalized travel plans based on user preferences.
- Intelligent Planning: Uses AI agents to generate personalized travel recommendations
- Multiple Data Sources: Integrates with Google Places, review scraping, and mock data
- Flexible Preferences: Supports city, time of day, place type, food type, and budget preferences
- High-Quality Recommendations: Only suggests places with 4.0+ ratings
- RESTful API: Clean and documented API endpoints
- Modular Architecture: Easy to extend with new tools and data sources
travel-planner/
├── main.py # FastAPI application entry point
├── routes.py # API route definitions
├── agent.py # LangChain agent configuration
├── tools.py # Custom tools for data retrieval
├── config.py # Configuration management
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── .gitignore # Git ignore patterns
└── README.md # This file
cd "d:\Code\Majorproject"python -m venv venv
.\venv\Scripts\Activate.ps1 # Windows PowerShell
# or
# source venv/bin/activate # Linux/Macpip install -r requirements.txtCreate a .env file in the project root:
# Copy the example file
cp .env.example .env
# Edit with your API keys
GOOGLE_API_KEY=your_google_api_key_here
GOOGLE_PLACES_API_KEY=your_google_places_api_key_here
DEBUG=true
HOST=127.0.0.1
PORT=8000# Start the FastAPI server
uvicorn main:app --reload --host 127.0.0.1 --port 8000The API will be available at:
- Main API: http://127.0.0.1:8000
- Interactive Docs: http://127.0.0.1:8000/docs
- Health Check: http://127.0.0.1:8000/health
# Run comprehensive tests
python test_api.py
# Run live demo
python demo.py
# Try the client example
python client_example.pyimport requests
# Generate travel plan
response = requests.post("http://127.0.0.1:8000/api/plan", json={
"city": "Delhi",
"time_of_day": "evening",
"place_type": "historical sites",
"food_type": "Mughlai cuisine",
"budget": "mid-range"
})
plan = response.json()["plan"]
print(plan)curl -X POST "http://127.0.0.1:8000/api/plan" \
-H "Content-Type: application/json" \
-d '{
"city": "Mumbai",
"time_of_day": "afternoon",
"place_type": "museums",
"food_type": "street food",
"budget": "cheap"
}'| Method | Endpoint | Description |
|---|---|---|
| GET | / |
API status and information |
| GET | /health |
Health check endpoint |
| GET | /docs |
Interactive API documentation |
| POST | /api/plan |
Generate travel plan |
| GET | /api/agent |
Test agent functionality |
{
"city": "Delhi", // Target city for the trip
"time_of_day": "evening", // morning, afternoon, evening
"place_type": "historical sites", // museums, parks, historical sites, etc.
"food_type": "local cuisine", // local cuisine, street food, Italian, etc.
"budget": "mid-range" // cheap, mid-range, expensive
}PLAN:
- Visit: Red Fort (Rating: 4.5)
⤷ Why: Magnificent Mughal architecture, symbol of India's history
⤷ Timing: 6:00 AM - 6:00 PM
- Eat at: Karim's (Rating: 4.3)
⤷ Why: Famous for authentic Mughlai cuisine since 1913
⤷ Price: ~₹300 per meal
GOOGLE_API_KEY: Required for Gemini AI modelGOOGLE_PLACES_API_KEY: Optional, for real Google Places dataDEBUG: Enable debug mode (true/false)HOST: Server host (default: 127.0.0.1)PORT: Server port (default: 8000)
- Model: Google Gemini 1.5 Flash
- Max Iterations: 10
- Temperature: 0 (deterministic responses)
- Tools: Search Places, Scrape Reviews
- Create tool class in
tools.py:
class NewTool(BaseTool):
name = "new_tool"
description = "Description of what the tool does"
args_schema = NewToolInput
def _run(self, param: str) -> str:
# Implement tool logic
return "result"- Add to tools list:
tools = [
SearchPlacesTool(),
ScrapeReviewsTool(),
NewTool() # Add your new tool
]Modify the prompt in agent.py to change agent behavior:
prompt = PromptTemplate.from_template("""
Your custom instructions here...
""")FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]Replace mock tools with real implementations:
- Google Places API: Get actual place data
- Web Scraping: Use Playwright for dynamic content
- Zomato API: For restaurant data
- TripAdvisor: For reviews and ratings
- FastAPI backend with auto-documentation
- LangChain ReAct agent implementation
- Mock Google Places and review scraping tools
- Travel preference input validation
- Structured travel plan output
- Error handling and logging
- Async support for scalability
- Configuration management
- Comprehensive test suite
- Interactive demo scripts
- Client usage examples
- Real Google Places API integration
- Web scraping with Playwright
- User authentication system
- Plan history database
- Frontend web interface
- Real-time price integration
- Multi-language support
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new features
- Submit a pull request
This project is licensed under the MIT License.
For questions or issues:
- Check the API documentation at
/docs - Run the test suite with
python test_api.py - Try the demo with
python demo.py - Check the logs for detailed error information
🎉 The Travel Planner API is fully functional and ready for production use!
copy .env.example .env
Required environment variables:
- `GOOGLE_API_KEY`: Your Google Gemini API key (required)
- `GOOGLE_PLACES_API_KEY`: Google Places API key (optional, uses mock data if not set)
### 5. Run the Application
```powershell
uvicorn main:app --reload
The API will be available at: http://localhost:8000
POST /api/plan
{
"city": "Delhi",
"time_of_day": "evening",
"place_type": "historical sites",
"food_type": "local cuisine",
"budget": "mid-range"
}Response:
{
"plan": "PLAN:\n- Visit: Humayun's Tomb (Rating: 4.5)\n ⤷ Why: Beautiful Mughal architecture, peaceful\n ⤷ Timing: 6 AM - 6 PM\n\n- Eat at: Karim's (Rating: 4.3)\n ⤷ Why: Famous for authentic Mughlai flavors\n ⤷ Price: ~₹500 per meal"
}GET /api/agent
GET /health
Visit http://localhost:8000/docs for interactive API documentation.
Create a .env file based on .env.example:
GOOGLE_API_KEY=your_google_api_key_here
GOOGLE_PLACES_API_KEY=your_google_places_api_key_here
DEBUG=True
HOST=0.0.0.0
PORT=8000- Google Gemini API: Get your key from Google AI Studio
- Google Places API: Enable in Google Cloud Console
-
FastAPI Application (
main.py)- Main application entry point
- Route registration
- Configuration validation
-
API Routes (
routes.py)/api/plan: Main travel planning endpoint/api/agent: Agent testing endpoint- Request/response models with Pydantic
-
LangChain Agent (
agent.py)- Google Gemini LLM integration
- ReAct agent pattern
- Custom prompt templates
-
Custom Tools (
tools.py)SearchPlacesTool: Places and restaurant searchScrapeReviewsTool: Review data extraction- Mock implementations for development
-
Configuration (
config.py)- Environment variable management
- API key validation
- Application settings
User Request → FastAPI → LangChain Agent → Tools → LLM → Formatted Response
Searches for restaurants, attractions, and other places:
- Input: Query, location, place type
- Output: Formatted place information with ratings and details
- Data Sources: Google Places API (or mock data)
Extracts review information from URLs:
- Input: URL of place/restaurant
- Output: Summarized review content
- Data Sources: Web scraping (or mock data)
# Test agent functionality
curl -X GET "http://localhost:8000/api/agent"
# Test travel planning
curl -X POST "http://localhost:8000/api/plan" \
-H "Content-Type: application/json" \
-d "{\"city\":\"Mumbai\",\"time_of_day\":\"evening\",\"place_type\":\"beaches\",\"food_type\":\"street food\",\"budget\":\"cheap\"}"The application runs with auto-reload enabled. Changes to Python files will automatically restart the server.
- Create tool class in
tools.pyinheriting fromBaseTool - Define input schema with Pydantic
- Implement
_run()and_arun()methods - Add to
toolslist
- Add new API integrations in tool implementations
- Update environment configuration for new API keys
- Implement proper error handling and fallbacks
- Set
DEBUG=Falsein production - Use environment-specific configuration files
- Implement proper logging and monitoring
- Add rate limiting and authentication
- Use production ASGI server (e.g., Gunicorn + Uvicorn)
This project is for educational and development purposes.
- Fork the repository
- Create feature branch
- Make changes with proper testing
- Submit pull request
-
Missing API Key Error
- Ensure
GOOGLE_API_KEYis set in.envfile - Verify API key is valid and has proper permissions
- Ensure
-
Import Errors
- Ensure virtual environment is activated
- Install all requirements:
pip install -r requirements.txt
-
Agent Execution Errors
- Check LangChain version compatibility
- Verify tool implementations return proper formats
Set DEBUG=True in .env for verbose logging and error details.