Genesis AI Hackathon
The application uses a FastAPI backend server that:
- Connects to the Supabase database
- Provides RESTful endpoints for accessing news articles
- Handles analysis and processing of queries
The API modules (e.g., natural_language_understanding.py
) now communicate with the FastAPI backend via HTTP requests:
- They do not directly access the database
- They use the FastAPI backend as a gateway to the database
- This ensures a clean separation of concerns
Previous Implementation:
- API modules directly accessed the Supabase database through a
Database
class. - This created tight coupling between the API modules and the database.
New Implementation:
- API modules now communicate with the FastAPI backend server via HTTP requests.
- The FastAPI backend acts as a gateway to the database.
- This creates a clean separation of concerns and follows RESTful principles.
Benefits:
- Separation of concerns - API modules don't need to know database details
- Single source of truth - Only the FastAPI backend connects to the database
- Testability - API modules can be tested with mock responses
- Scalability - FastAPI backend can be scaled independently
Added Functionality:
- Robust error handling when the backend is not available
- Fallback to mock data when the database can't provide real articles
- Detailed error logging to help diagnose issues
- Start the FastAPI backend server:
python backend/main.py
-
The API modules will automatically connect to the backend server running at the URL specified in the
BACKEND_URL
environment variable (defaults tohttp://localhost:8000
) -
To test the Natural Language Understanding module:
python test_nlu_api.py
Set these in your .env
file:
SUPABASE_URL
: Your Supabase project URLSUPABASE_KEY
: Your Supabase API keyCOHERE_API_KEY
: Your Cohere API keyBACKEND_URL
: URL of the FastAPI backend (default: http://localhost:8000)
To test this implementation, make sure the FastAPI backend is running:
cd backend
python main.py
Then run the test script in another terminal:
python test_nlu_api.py
The application now uses a dedicated approach to search articles in the database:
-
Table Structure:
- The Supabase database contains a table named "news"
- Key columns: id, source_name, source_link, news_information
-
Search Functionality:
- A new
/search
endpoint that specifically searches the news_information column - Enhanced keyword matching in the NLU module
- Fallback mechanisms when search fails
- A new
-
Improvements:
- Direct searching in the news_information column for better relevance
- Multiple search strategies with progressive fallbacks
- Robust error handling and logging
- Mock data fallback for testing when the database is unavailable
To test the search functionality:
-
Start the FastAPI backend:
cd backend python main.py
-
Use the test script to search for specific terms:
python test_search.py "search term"
-
Or use the full NLU pipeline:
python test_nlu_api.py