Skip to content

GovernmentPlates/railbuddy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RailBuddy

A conversational AI agent for UK train information. Built with LangChain, Flask, React, and SQLite.

Motivation

LangChain has changed quite a bit over the past year, so, in order to "stay current" with how LangChain is used, I decided to build this project as a tech demo and learning (or refresher) exercise.

Features

  • Live UK train departures and schedules
  • TfL (Transport for London) status information
  • Ticket fare information (estimates only)
  • Natural language date/time understanding (e.g. "tomorrow at 3pm" etc.)

Technical Details

Backend (Flask + SQLAlchemy)

  • LangChain: Utilizes GPT-4o* with custom tools (these tools help with station lookups, live departures, fare estimates, and TfL status)
  • Station Database: 2,598+ UK stations (Data Source)
  • Selenium: Used for scraping some information
  • Conversation Storage: Full conversation history with snowflake IDs
  • REST API: Endpoints for chat, conversations, and management

*This can be easily swapped out for other LLMs supported by LangChain - I was lazy and had some OpenAI credits to burn.

Frontend (React + Tailwind CSS)

  • ChatGPT-style UI: Modern and clean interface with icons from Lucide Icons
  • Markdown Support: Rich formatting for agent responses
  • Dark Mode: Persistent theme preference

Getting up and running

1. Setup Environment

Rename the .env.example file in the backend directory to .env and fill in your OpenAI API key and Realtime Trains credentials:

OPENAI_API_KEY=your_openai_api_key_here
RTT_USERNAME=your_rtt_username
RTT_PASSWORD=your_rtt_password

2. Backend Setup

cd backend

# Create virtual environment
python -m venv venv
source venv/bin/activate  # or venv\Scripts\activate on Windows

# Install dependencies
uv pip install -r requirements.in

# Initialize database (creates single SQLite database with all tables and loads the station data)
python src/init_db.py

# Run server
python app.py

Backend runs on http://localhost:5000

3. Frontend Setup

cd frontend

# Install dependencies
npm install

# Run dev server
npm run dev

Frontend runs on http://localhost:5174 (or similar)

Usage Examples

Try these queries:

  • "What trains are leaving from London Waterloo?"
  • "Show me trains from Birmingham New Street to London Euston"
  • "Are there any delays on the Metropolitan line?"

You can even ask follow-up questions:

  • "When is the next train to Guildford?" (after asking about Waterloo)
  • "How much is a return ticket for this train?" (after asking about trains from Birmingham to London)
  • "What lines are currently disrupted on the TfL network?" (after asking about delays)

And you can even use natural language for date/time queries:

  • "Show me trains from Reading tomorrow"
  • "Trains from Paddington next Monday morning"
  • "What trains are there from London Victoria to Manchester at 3pm?"

Data Sources

*derived from Trainline EU's data repository where the UK data is derived from official National Rail data.

License

MIT

Screenshots

Frontpage

Desktop Chat

About

A conversational AI agent for UK train information

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published