This project is a FastAPI-based web service that uses Google Vertex AI for text classification. It provides endpoints to classify questions, store responses, and collect user feedback. The backend uses SQLAlchemy for database operations.
- /api/classify: Classifies a question using a Vertex AI model.
- /api/feedback: Allows users to submit feedback on the classification.
- /api/feedback/{response_id}: Retrieves feedback for a specific response.
- Stores all questions, responses, and feedback in a SQL database.
vertex-ai-fastAPI/
├── classify.py # Vertex AI classification logic
├── main.py # FastAPI app and API endpoints
├── db.py # Database models and session setup
├── test.py # API endpoint tests
├── requirements.txt # Python dependencies
├── service-account-key.json # (GCP credentials — should be in .gitignore)
- Clone the repository
git clone https://github.com/<your-username>/<repo-name>.git cd vertex-ai-fastAPI
- Create and activate a virtual environment
python -m venv venv venv\Scripts\activate # On Windows # source venv/bin/activate # On Linux/Mac
- Install dependencies
pip install -r requirement.txt
- Configure Google Cloud credentials
- Place your
service-account-key.jsonin the project root. - Important: Do NOT commit this file to GitHub.
- Set up your database
- Update DATABASE_URL in
db.pywith your actual database credentials.
-
Run the FastAPI server
uvicorn main:app --reload
-
Test the API -Use the included
test.pyor tools like Postman or curl# Test /api/classify endpoint curl -X POST http://127.0.0.1:8000/api/classify \ -H "Content-Type: application/json" \ -d '{"question": "Wifi issues at mc nair?"}' # Test /api/feedback endpoint curl -X POST http://127.0.0.1:8000/api/feedback \ -H "Content-Type: application/json" \ -d '{"response_id": 1, "feedback": "Accurate classification"}' # Test /api/feedback/{response_id} endpoint curl http://127.0.0.1:8000/api/feedback/1