InShort is a mobile application designed to help users discover and understand legislative bills that are relevant to their personal interests and location. Using a powerful AI backend, the app delivers personalized bill recommendations and custom-tailored summaries, making complex legislation accessible and engaging.
- Personalized Recommendations: Leverages a vector database (Pinecone) to find bills that semantically match a user's unique profile, including their interests, location, and occupation.
- AI-Generated Summaries: Uses a Large Language Model (Groq) to generate concise, easy-to-understand summaries of bills, personalized to be relevant to the user.
- Dynamic Profile Updates: Seamlessly updates recommendations when a user changes their profile interests.
- SwiftUI Frontend: A modern, reactive iOS application built with SwiftUI and the MVVM pattern.
- FastAPI Backend: A robust and efficient Python backend serving the recommendation engine.
The project is a monorepo containing two main components: a SwiftUI frontend and a Python backend.
- Language: Swift
- UI Framework: SwiftUI
- Architecture: Model-View-ViewModel (MVVM)
- Views: SwiftUI views define the UI and bind to ViewModel properties.
- ViewModels: Contain the presentation logic and state for the views.
- Models: Represent the data structures of the app (e.g.,
Bill,UserProfile). - Services: Handle networking (
BillService,UserService) and other shared logic (NotificationService).
- Data Persistence:
UserDefaultsis used to persist the user's profile locally. - Concurrency:
Combineandasync/awaitare used for managing asynchronous operations and state updates.
- Framework: FastAPI
- Database: Pinecone (Vector Database for semantic search)
- AI Services:
- OpenAI: Used to generate vector embeddings for text data.
- Groq: Used to generate personalized bill summaries with a fast LLM.
- Core Logic: The
BillRecommenderclass inRAG/encapsulates the logic for querying the vector database and formatting results.
- macOS with Xcode installed.
- Python 3.8+
pipfor Python package management.
First, set up and run the Python server.
-
Navigate to the Backend Directory:
cd InShort -
Create an Environment File: Create a file named
.envin theInShort/directory and add your API keys:PINECONE_API_KEY="YOUR_PINECONE_KEY" OPENAI_API_KEY="YOUR_OPENAI_KEY" GROQ_API_KEY="YOUR_GROQ_KEY" -
Install Dependencies:
pip install -r requirements.txt
-
Populate the Database: Run the upsert script to populate your Pinecone index with bill data. Make sure your Pinecone index is configured for 384 dimensions to match the
text-embedding-3-smallmodel.python3 RAG/pcupsert.py
-
Run the Server:
uvicorn api:app --reload
The server will be running at
http://127.0.0.1:8000.
With the backend running, you can now launch the iOS application.
-
Navigate to the Frontend Project:
cd ../InShortFrontEnd -
Open in Xcode: Open the
InShort.xcodeprojfile in Xcode.open InShort.xcodeproj
-
Build and Run: Select an iOS Simulator (e.g., iPhone 15 Pro) or a physical device and press the "Run" button (or
Cmd+R). The app will launch and connect to your local backend.
.
βββ InShort/ # Python Backend
β βββ api.py # FastAPI application endpoints
β βββ requirements.txt # Python dependencies
β βββ .env.example # Example environment file
β βββ RAG/
β βββ billRecommender.py # Core recommendation logic
β βββ pcupsert.py # Script to populate Pinecone
β
βββ InShortFrontEnd/ # iOS Frontend
βββ InShort/
βββ InShort.xcodeproj # Xcode Project
βββ InShort/
βββ Models/ # Data models (Bill, UserProfile)
βββ ViewModels/ # ViewModel layer (NewsViewModel, etc.)
βββ Views/ # SwiftUI views
βββ Services/ # Networking and data services
-
Congress.gov API Key: Get a free API key from Congress.gov API
- Visit https://api.congress.gov/
- Sign up for a free account
- Generate your API key
- Already there in google docs file
-
Groq API Key: Get an API key from Groq
- Visit https://console.groq.com/
- Sign up for an account
- Generate your API key
- Already there in google docs file
-
Python Dependencies: Install the required packages
pip install -r requirements.txt
full_bill_scraper.py- Scrapes comprehensive bill data from Congress.govinshort_summarizer.py- Generates personalized AI summaries using Groqinshort_bills.json- Bill data (generated by scraper)requirements.txt- Python dependenciesREADME.md- This file
Set your API keys as environment variables:
# Set Congress.gov API key
export CONGRESS_API_KEY="your_congress_api_key_here"
# Set Groq API key
export GROQ_API_KEY="your_groq_api_key_here"Run the bill scraper to collect comprehensive bill data:
python3 full_bill_scraper.pyThis will:
- Fetch the most recent 100 bills from Congress.gov
- Collect full details including sponsors, actions, amendments, text, and more
- Save the data to
inshort_bills.json
Run the AI summarizer to create personalized summaries:
python3 inshort_summarizer.pyThis will:
- Load the bill data from
inshort_bills.json - Generate personalized summaries for different user profiles
- Show how the same bill affects different users differently
The full_bill_scraper.py script collects comprehensive bill data:
# Basic usage (collects 100 bills)
python3 full_bill_scraper.py
# The script automatically:
# - Fetches bills from the 119th Congress
# - Collects full details for each bill
# - Saves data to inshort_bills.jsonThe inshort_summarizer.py script generates personalized summaries for:
- Sarah (25yo, Texas, recent graduate) - Focus on student loans, job market, housing
- Mike (45yo, California, small business owner) - Focus on business regulations, taxes, healthcare
- Lisa (62yo, Florida, retired teacher) - Focus on Medicare, Social Security, education
- David (35yo, New York, tech worker) - Focus on tech regulations, privacy, immigration
Each summary is tailored to show how the bill specifically impacts that user's situation.
Fetching bills 0 to 10...
Getting full details for HR1234 (119th Congress)...
Title: Homebuyers Privacy Protection Act...
β Successfully collected full details (1/100)
Total bills with full details collected: 100
Saved 100 bills with full details to inshort_bills.json
π± Sarah (25yo, Texas, recent graduate)
--------------------------------------------------
π Bill 1: Homebuyers Privacy Protection Act
π‘ This bill directly impacts your ability to buy a home! It protects your personal
financial information when applying for mortgages, preventing lenders from sharing
your sensitive data without permission. As a recent graduate looking to buy your
first home, this gives you more control over your financial privacy and could
help you avoid predatory lending practices.
π Bill 2: Student Loan Forgiveness Act
π‘ Great news for your student debt! This bill expands loan forgiveness programs
for recent graduates working in public service or low-income areas. You could
qualify for partial or full forgiveness of your student loans if you work in
education, healthcare, or government for 10 years.
Create a .env file or set environment variables:
# Congress.gov API
CONGRESS_API_KEY=your_congress_api_key
# Groq API
GROQ_API_KEY=your_groq_api_keyEdit the user profiles in inshort_summarizer.py to match your target audience:
USER_PROFILES = [
{
"name": "Your Custom Profile",
"age": 30,
"location": "Your State",
"occupation": "Your Job",
"interests": ["relevant", "topics", "here"]
}
]- Congress.gov: 1,000 requests per hour (free tier)
- Groq: Varies by plan, typically 100+ requests per minute
The scripts include rate limiting to stay within these limits.
- Invalid API Keys: Make sure your API keys are correct and active
- Rate Limit Exceeded: Wait before making more requests
- Python Command Not Found: Use
python3instead ofpython - Environment Variable Not Set: Export your API keys in the terminal
Invalid API Key: Check your API key is correctRate Limit Exceeded: Wait before retryingFile Not Found: Make sureinshort_bills.jsonexists
- API keys are stored as environment variables (not in code)
- Bill data is public information from Congress.gov
- User profiles are fictional examples for demonstration
This tool is for educational and research purposes. Please respect the Congress.gov and Groq API terms of service and rate limits. The bill data is provided by the United States Congress and is in the public domain.
InShort now includes a RAG (Retrieval-Augmented Generation) system that uses Pinecone for vector storage and Groq for generating summaries.
-
Pinecone API Key: Get a free API key from Pinecone
- Visit https://www.pinecone.io/
- Sign up for a free account
- Generate your API key
-
OpenAI API Key: For generating embeddings
- Visit https://platform.openai.com/
- Generate your API key
Set your additional API keys:
# Set Pinecone API key
export PINECONE_API_KEY="your_pinecone_api_key_here"
# Set OpenAI API key (for embeddings)
export OPENAI_API_KEY="your_openai_api_key_here"First, update the bills in Pinecone with summaries:
python3 upsert_bills.pyThis will:
- Read the bill data from
inshort_bills.json - Extract summaries from the bill data
- Generate embeddings for each bill
- Store everything in Pinecone with metadata including summaries
Test the bill recommender with Groq integration:
python3 test_bill_recommender.pyOr run the recommender directly:
python3 RAG/billRecommender.pyThe updated BillRecommender class provides:
- Vector Search: Uses embeddings to find relevant bills based on user interests
- Groq Integration: Automatically generates summaries using Groq when not available in metadata
- Personalized Recommendations: Returns bills ranked by relevance to user interests
- Comprehensive Metadata: Includes bill title, sponsor, congress, and summary
Based on your interests, we recommend the following bills:
#1 - HR1234 (Score: 0.856)
π Title: Student Loan Forgiveness Act
π€ Sponsor: Sponsored by John Smith
ποΈ Congress: 119
π Summary: This bill expands student loan forgiveness programs for graduates working in public service. It could save you thousands of dollars on your student debt if you work in education, healthcare, or government for 10 years. This affects you.
--------------------------------------------------
- Vector Storage: Pinecone stores bill embeddings and metadata
- Embedding Generation: OpenAI's text-embedding-3-small model
- Summary Generation: Groq's llama3-8b-8192 model
- Retrieval: Semantic search based on user interests
- Generation: AI-generated summaries when not available in metadata
You can modify the BillRecommender class to:
- Change Search Parameters: Adjust
top_kandmin_scorethresholds - Customize Summaries: Modify the Groq prompt for different summary styles
- Add User Profiles: Integrate with the personalized summarizer
- Filter Results: Add additional filtering based on bill status, date, etc.
This is the backend server for the InShort app, which provides API endpoints for the iOS app to communicate with.
-
Install the required dependencies:
pip install -r requirements.txt -
Create a
.envfile with your API keys (seeexample.envfor reference). -
Run the FastAPI server:
uvicorn api:app --reload --host 0.0.0.0 --port 8000This will start the server on
http://localhost:8000.
/chat/: Chat with the bill agent/recommendations/: Get bill recommendations based on user profile/bills/: Get all bills/bills/details/{bill_id}: Get details for a specific bill/bills/like/{bill_id}: Like a bill/bills/dislike/{bill_id}: Dislike a bill/bills/subscribe/{bill_id}: Subscribe to a bill/bills/unsubscribe/{bill_id}: Unsubscribe from a bill
If you're experiencing issues with the Swift app communicating with the Python backend:
-
Make sure the backend server is running on the correct port (default: 8000).
-
Check that the Swift app is using the correct API URL:
- For local development:
http://localhost:8000 - For production:
https://test.rudolfmetro.it
- For local development:
-
Ensure the request format matches what the API expects:
- The chat endpoint expects a JSON object with
user_input,session_id, anduser_profilefields. - The
user_profileshould include fields likename,age,gender,location,interests, etc.
- The chat endpoint expects a JSON object with
-
Check the console logs in Xcode for detailed error messages.
-
If using a simulator, make sure it can access localhost (this should work by default).
-
If using a physical device on the same network as the server, use the computer's local IP address instead of localhost.
The chatbot functionality is implemented using LangGraph and LangChain. The main components are:
inShort_agent.py: Contains the agent graph definition and logic for processing user input.api.py: Contains the FastAPI endpoints, including the/chat/endpoint that interfaces with the agent.fetch_bills.py: Contains tools for fetching bill information that the agent can use.
The agent uses a system message that includes the user's profile to personalize responses about bills and legislation.