Creating a Travel Planner RESTful API with Flask

Introduction and Lesson Overview

Welcome to the first lesson of our course, Building a CrewAI-Powered Travel Planner App with Flask. In this lesson, we will embark on an exciting journey to create a RESTful API using Flask, a popular web framework for Python. This API will serve as the backbone of our travel planner application, allowing users to submit travel planning requests and receive structured itinerary responses. Our API will integrate seamlessly with the CrewAI travel planner crew, which you have previously learned to work with. By the end of this lesson, you will have a solid understanding of how to set up and run a Flask application that interacts with CrewAI to deliver personalized travel plans.

Setting Up Flask

Flask is a lightweight and flexible web framework that is perfect for building small to medium-sized web applications. It provides the tools needed to create web servers and handle HTTP requests. To get started with Flask on your local device, you would typically install it using pip with the command:

pip install Flask

However, since you are working in the CodeSignal environment, Flask is already pre-installed, so you can focus on learning and building without worrying about setup.

Structuring the Project

Our project will be organized in a structured manner to support the design and functionality of our API. Here's how we'll organize our files:

app/
├── main.py                        # Main application file
└── travel_planner/
    ├── travel_planner_crew.py     # Main travel planner logic
    ├── models/
    │   ├── daily_plan.py          # Daily planning model
    │   ├── travel_itinerary.py    # Itinerary model
    │   └── attraction.py          # Attraction model
    ├── tools/
    │   └── custom_search_tool.py  # Custom search tool
    └── config/
        ├── tasks.yaml             # Task configurations
        └── agents.yaml            # Agent configurations

The main.py file will house the core logic of our Flask application, including initializing the app, defining routes, and handling requests. The travel_planner directory contains all the CrewAI-related components:

  • travel_planner_crew.py implements the main travel planning logic
  • The models directory contains Pydantic models for structuring our data
  • The tools directory includes tools like our custom search tool
  • The config directory stores YAML configuration files for tasks and agents

This modular structure ensures our code is organized, maintainable, and scalable as we build more complex features throughout the course.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal