A Django REST API for classifying and managing vegetarian/vegan food conversations using AI-powered classification.
Herbi is an intelligent API that helps classify conversations about food to determine if they indicate vegetarian or vegan dietary preferences. It uses AI models to analyze food-related conversations and extract structured data about food consumption patterns.
- AI-Powered Classification: Uses OpenAI models to classify food conversations
- RESTful API: Clean, documented API endpoints with Swagger UI
- Conversation Simulation: Tools for generating and simulating food-related conversations
- Food Extraction: Extracts structured food data from natural language
- Authentication: Secure user authentication system
- Interactive Documentation: Built-in Swagger UI for API exploration
- Python 3.8+
- OpenAI API key
- PostgreSQL (optional, SQLite is used by default)
-
Clone the repository
git clone <repository-url> cd herbi
-
Install dependencies
cd herbiapi pip install -r requirements.txt -
Set up environment variables Create a
.env.django.devfile in theherbiapidirectory:OPENAI_SECRET=your_openai_api_key_here
-
Run migrations
python manage.py migrate
-
Create a superuser (optional)
python manage.py createsuperuser
-
Start the development server
python manage.py runserver
Once the server is running, you can access the interactive API documentation:
- Swagger UI: http://localhost:8000/
- ReDoc: http://localhost:8000/redoc/
- Raw Schema: http://localhost:8000/schema/
POST /login/- User login with username and password
GET /conversations/- List all conversations with extracted food dataGET /conversations/vegs/- List only vegetarian/vegan conversations
GET /admin/- Django admin interface
GET /- Swagger UI documentationGET /redoc/- ReDoc documentationGET /schema/- OpenAPI schema
herbiapi/
├── chat/ # Conversation management app
│ ├── models.py # SimulatedConversation model
│ ├── views.py # API views
│ ├── serializers.py # Data serialization
│ └── food_classifiers/ # AI classification logic
├── login/ # Authentication app
│ ├── models.py # User models
│ ├── views.py # Login views
│ └── serializers.py # Auth serializers
├── utils/ # Utility modules
│ ├── conversation_simulator.py
│ ├── llm_interface.py
│ └── openai_client.py
├── core/ # Django settings and configuration
│ ├── settings.py # Project settings
│ └── urls.py # URL routing
└── requirements.txt # Python dependencies
- Conversation Input: The system accepts food-related conversations
- AI Classification: Uses OpenAI models to analyze the conversation
- Food Extraction: Extracts structured food data from the text
- Diet Classification: Determines if the foods indicate vegetarian/vegan preferences
- Data Storage: Stores the extracted food data from the classified conversation
Run the test suite:
pytest app_directory/tests- Follow PEP 8 style guidelines
- Use type hints where appropriate
- Write docstrings for functions and classes
- Create models in the appropriate app
- Add serializers for API responses
- Create views with proper documentation
- Update URL routing
- Add tests for new functionality
| Variable | Description | Required |
|---|---|---|
OPENAI_SECRET |
OpenAI API key for AI classification | Yes |