
📚 Documentation • 🖥️ Application • 🏠 Home
- Install
pyenv- Install python 3.12:
pyenv install 3.12
- Install python 3.12:
- Install
pyenv-virtualenv - Install
poetry - Create a virtualenv:
pyenv virtualenv 3.12 python-airline-support-bot- Activate the virtualenv:
pyenv activate python-airline-support-bot
- Activate the virtualenv:
- Install dependencies:
poetry install - Install pre-commit:
poetry run pre-commit install
An AI-powered airline customer support bot that can handle flight-related questions using OpenAI's GPT models with intelligent tool calling.
- 🤖 AI Tool Calling: Uses OpenAI's function calling to intelligently choose when to look up flight information
- Flight Information: Check real-time flight status, gates, terminals, and schedules
- Intelligent Conversations: Natural language processing for customer inquiries
- Smart Function Selection: AI automatically decides which tools to use based on customer questions
- Multi-topic Support: Handles questions about:
- Flight schedules and status
- Booking assistance
- Baggage policies
- Check-in procedures
- Cancellation and refund policies
- Special assistance requests
- Frequent flyer programs
- General travel information
- Command Line Interface: Easy-to-use interactive CLI
- Programmatic API: Use the bot in your own applications
The bot uses OpenAI's function calling feature to intelligently decide when to look up flight information:
- Automatic Detection: The AI determines when a customer question requires flight data
- Smart Tool Selection: Chooses the appropriate tool (flight lookup, route search, or general info)
- Contextual Responses: Combines tool results with natural language responses
get_flight_info: Look up specific flight details by flight numbersearch_flights_by_route: Find flights between citiesget_all_flights: List all available flights
- Python 3.12+
- OpenAI API key (Get one here)
-
Clone the repository:
git clone <repository-url> cd python-airline-support-bot
-
Install dependencies using Poetry:
poetry install
-
Set up your OpenAI API key:
export OPENAI_API_KEY="your_api_key_here"
Or create a
.envfile:echo "OPENAI_API_KEY=your_api_key_here" > .env
Run the bot in interactive mode:
poetry run airline-botOr using Python directly:
poetry run python -m python_airline_support_bot.cliYou: What's the status of flight AA123?
🤖 Bot: I'll look up flight AA123 for you.
Flight AA123:
• Route: New York (JFK) → Los Angeles (LAX)
• Departure: 08:00 AM
• Arrival: 11:30 AM
• Status: On Time
• Terminal: Terminal 4
• Gate: A12
Flight AA123 is currently on time and will be departing from gate A12 in Terminal 4.
You: Can you find flights from New York to Los Angeles?
🤖 Bot: Let me search for flights from New York to Los Angeles.
Found 1 flight(s) from New York to Los Angeles:
Flight AA123:
• Route: New York (JFK) → Los Angeles (LAX)
• Departure: 08:00 AM
• Arrival: 11:30 AM
• Status: On Time
• Terminal: Terminal 4
• Gate: A12
You: What's your baggage policy?
🤖 Bot: I'd be happy to help you with baggage information! For carry-on bags, most airlines allow one personal item and one carry-on bag...
The AI automatically chooses which tools to use:
| Customer Question | Tool Called | Result |
|---|---|---|
| "What's the status of flight AA123?" | get_flight_info |
Detailed flight information |
| "Find flights from NYC to LA" | search_flights_by_route |
List of matching flights |
| "What flights are available?" | get_all_flights |
All available flights |
| "What's your baggage policy?" | None | General airline information |
from python_airline_support_bot import AirlineSupportBot
# Initialize the bot
bot = AirlineSupportBot()
# Ask questions - AI will automatically use tools when needed
response = bot.process_message("What's the status of flight AA123?")
print(response)
# The AI will automatically call get_flight_info tool and format the response
# Direct access to public methods is still available
flights = bot.get_available_flights()
for flight in flights:
print(f"{flight.flight_number}: {flight.status}")
# Search for flights by route
ny_to_la_flights = bot.search_flights_by_route("New York", "Los Angeles")
for flight in ny_to_la_flights:
print(f"Found: {flight.flight_number} - {flight.departure_time}")The bot comes with sample flight data for demonstration:
| Flight | Route | Status | Gate | Terminal |
|---|---|---|---|---|
| AA123 | New York (JFK) → Los Angeles (LAX) | On Time | A12 | Terminal 4 |
| DL456 | Chicago (ORD) → Miami (MIA) | Delayed - 30 minutes | B8 | Terminal 1 |
| UA789 | San Francisco (SFO) → Seattle (SEA) | Boarding | C15 | Terminal 3 |
| SW101 | Denver (DEN) → Phoenix (PHX) | Cancelled | - | Terminal West |
__init__(api_key: Optional[str] = None): Initialize the botprocess_message(user_message: str) -> str: Process a user message and return response (uses AI tool calling)reset_conversation(): Clear conversation historyget_available_flights() -> List[FlightInfo]: Get all available flightssearch_flights_by_route(departure_city: str, arrival_city: str) -> List[FlightInfo]: Search flights
The AI can automatically call these functions based on user questions:
get_flight_info(flight_number: str): Look up specific flight detailssearch_flights_by_route(departure_city: str, arrival_city: str): Search flights by routeget_all_flights(): Get all available flights
class FlightInfo(BaseModel):
flight_number: str
departure_city: str
arrival_city: str
departure_time: str
arrival_time: str
status: str
gate: Optional[str] = None
terminal: Optional[str] = NoneOPENAI_API_KEY: Your OpenAI API key (required)OPENAI_MODEL: OpenAI model to use (default: gpt-3.5-turbo)MAX_TOKENS: Maximum tokens for responses (default: 500)
You can extend the bot by:
- Adding new tools: Extend the
_create_tools()method and_execute_function()method - Adding more flight data: Modify the
_create_sample_flight_data()method - Connecting to real APIs: Replace the sample data with calls to airline APIs
- Customizing responses: Modify the system prompt in
_create_system_prompt()