- What is this repo?
- Why function‑calling tools are the secret sauce?
- Core Architecture – A Quick Tour
- New Feature Spotlight: Discount‑For‑Sales Tool ✨
- Getting Started – Run It Locally in 5 Minutes
- Extending the Assistant – Add Your Own Magic
- Best‑Practices, Gotchas & Tips
- License & Contributing
Flight AI Assistant is a playful yet powerful chatbot that demonstrates how to blend large‑language‑model chat (OpenAI GPT‑4o‑mini, Anthropic Claude, Google Gemini) with function‑calling tools to fetch real‑time, reliable data.
Think of it as a virtual airline agent that never makes up ticket prices—because the prices live in a tiny, well‑structured Python dictionary (or a future live API).
TL;DR: Chat with a model, let it call Python functions for you, and get spot‑on answers.
| ✅ Benefit | 🎯 What it means for you |
|---|---|
| Separation of concerns | The system prompt handles tone (courteous, one‑sentence answers). The tools handle the hard facts (prices, discounts). |
| Zero hallucinations | The model never guesses a price; it must call get_ticket_price or get_discounted_price. |
| Structured, JSON‑friendly data | Responses are machine‑readable, no fragile regex parsing required. |
| Easy extensibility | Add a new function → update its JSON schema → append to tools. No system‑prompt rewrites! |
| Auditability | Every tool call can be logged for compliance or debugging. |
| Security by design | The model never gets direct DB or network access—only the curated functions you expose. |
User → Gradio UI → chat() → OpenAI API
↘ (no tool) ↘ (tool call)
↘ ↘
OpenAI response handle_tool_call()
↘ ↘
UI displays answer tool response → second OpenAI call → final answer
system_message– sets the personality: short, courteous, always accurate.- Tool definitions – JSON schemas (
price_function,discount_function) describing the callable Python functions. chat()– orchestrates the conversation, decides when a tool call is needed, and stitches everything together.handle_tool_calls()– parses the model’s tool request, runs the real Python function, and builds the tool‑response payload.- Gradio UI – a sleek web front‑end (
gr.ChatInterface) for instant testing.
We’ve added a second tool that returns discounted ticket prices for special promotions (Black Friday, Christmas sales, etc.).
- User asks “What’s the sale price for a Tokyo ticket?”
- The model sees the
discount_functionschema, decides to call it. handle_tool_calls()runsget_discounted_price(city)against thediscount_pricesdict.- The model receives the JSON result and crafts a short, friendly reply like:
“A Tokyo round‑trip is currently on sale for $999 🎉”
discount_function = {
"name": "get_discounted_price",
"description": "Get the discounted price of a return ticket to the destination city. Use this during sales periods (e.g., Black Friday, Christmas).",
"parameters": {
"type": "object",
"properties": {
"destination_city": {
"type": "string",
"description": "The city the customer wants to travel to."
}
},
"required": ["destination_city"],
"additionalProperties": False,
},
}
tools += [{"type": "function", "function": discount_function}]Now the assistant can smoothly switch between regular and discounted pricing without any extra prompt gymnastics.
-
Clone the repo
git clone https://github.com/AsutoshaNanda/Flight-AI-Assistant.git cd Flight-AI-Assistant -
Create a virtual environment (optional but recommended)
python -m venv venv && source venv/bin/activate # macOS/Linux .\venv\Scripts\activate # Windows
-
Install dependencies
pip install openai anthropic google-generativeai gradio python-dotenv beautifulsoup4
-
Add your API keys in a
.envfile at the project root:OPENAI_API_KEY=sk-... ANTHROPIC_API_KEY=sk-ant-... GOOGLE_API_KEY=AIzaSy... -
Launch the notebook or script
Notebook:jupyter lab→ openFlight AI Assistant.ipynb→ run all cells.
Script: copy the notebook code into aapp.pyand runpython app.py. -
Open the Gradio UI (usually at
http://127.0.0.1:7860) and start chatting!
- Write a Python function – e.g.,
def get_flight_status(flight_number): ... - Create a matching tool schema (name, description, JSON parameters).
- Append it to the
toolslist. - Update
handle_tool_calls()to route the newfunction.nameto your Python function.
Tip: Keep the function pure (no side‑effects) and validate inputs (whitelist city names, regex flight numbers) for security.
| 🎯 Area | ✅ Recommendation |
|---|---|
| Infinite loops | Limit max_tool_calls per turn (e.g., 2) to avoid recursion. |
| Schema mismatches | Test tool schemas in OpenAI Playground before coding. |
| User‑supplied data | Sanitize/whitelist all arguments inside your functions. |
| Deprecation warnings | Use type='messages' in gr.ChatInterface (as shown). |
| Rate limits | Implement exponential back‑off & exponential jitter for API calls. |
| Debugging | Print/log the raw tool_calls payload to see exactly what the model sent. |
| Fun factor | Sprinkle emojis, friendly language, and short sentences (the system prompt already enforces it!). |
This project is licensed under the Apache License 2.0 – see the LICENSE file for full details.
💡 Contributions welcome! Feel free to fork, add new tools (e.g., flight status, baggage allowance), improve the UI, or write tests. Open an issue or submit a pull request, and let’s make this little airline agent even smarter together.
Please contribute to this and hope this repo would be some help of yours.