Skip to content

Latest commit

Β 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Plant Based Assistant - AI Chatbot

A production-ready Python chatbot that analyzes vegan ingredients, suggests alternatives, recommends recipes, and provides nutritional insights using LangChain orchestration and multiple data sources.

🎯 Project Status

Completed Phases

  • βœ… Phase 1: Project Foundation (config, logging, exceptions)
  • βœ… Phase 2: Data Source Integration (USDA, Spoonacular, Vegan DB)
  • βœ… Phase 3: Tool Functions (ingredient, recipe, nutrition, meal planning)
  • βœ… Phase 4: LangChain Agent Architecture (router agent, memory, synthesizer)
  • βœ… Phase 5: Streamlit UI Enhancement (chat interface, nature theme, preferences, history)

In Progress

  • πŸ”„ Phase 6: Error Handling & Robustness (API rate limits, timeouts, graceful degradation)

Coming Soon

  • Phase 7: Testing & Quality Assurance (unit/integration tests, coverage targets)
  • Phase 8: Documentation & Demo Video (API docs, demo video, GitHub CI/CD)

πŸ“‹ Features

Core Capabilities

  • Ingredient Analysis: Check vegan status with multi-source verification
  • Vegan Alternatives: Get substitution suggestions with nutritional matching
  • Recipe Discovery: Find recipes by ingredients with dietary filtering
  • Nutrition Insights: Get USDA nutrition data with serving size scaling
  • Meal Planning: Generate shopping lists and meal plans from recipes

Technical Features

  • Multi-Source Synthesis: Combines data from USDA, Spoonacular, and local database
  • LangChain Orchestration: Router agent with tool-based architecture
  • Conversation Memory: 10-turn conversation context with user profile storage
  • Caching Layer: File-based cache with TTL for API efficiency
  • Error Handling: Graceful degradation with fallback strategies
  • Type Safety: Full type hints throughout codebase

πŸš€ Quick Start

Prerequisites

  • Python 3.9+
  • Virtual environment (recommended)
  • Git (for version control)

Installation

  1. Clone/Set up project
cd c:\CODE KY\PlantBasedAssist
  1. Create virtual environment
python -m venv .venv
.venv\Scripts\activate  # On Windows
source .venv/bin/activate  # On macOS/Linux
  1. Install dependencies
pip install -r requirements.txt
  1. Configure environment variables
cp .env.example .env
# Edit .env with your API keys:
# GITHUB_TOKEN=your_github_token_with_gpt4o_access
# SPOONACULAR_API_KEY=your_spoonacular_key
# USDA_API_KEY=your_usda_key (free from USDA)
  1. Run the application
streamlit run ui/app.py

The chatbot will be available at http://localhost:8501

Using the UI

Quick Start:

  1. Click one of 8 suggested prompts, or type your question
  2. View response with multi-source data
  3. Continue conversation (10-turn memory)

Settings (Sidebar):

  • Preferences Tab: Set dietary restrictions, cuisines, protein goals, budget
  • History Tab: View conversation, export as JSON, clear history
  • About Tab: View version and technologies

Features:

  • 🌱 Nature-themed UI with forest green palette
  • πŸ’¬ Chat with user/assistant avatars
  • πŸ“ Export conversations for analysis
  • βš™οΈ Customize user preferences
  • πŸ’‘ 8 quick-start prompts for new users

πŸ—οΈ Architecture

Layer Structure

User Interface Layer (Streamlit)
         ↓
LangChain Orchestration Layer
- RouterAgent (main decision-maker)
- Tools (ingredient, recipe, nutrition, meal planning)
- Memory Manager (conversation + user profile)
         ↓
Data Access Layer
- USDA API Client (nutrition data)
- Spoonacular API Client (recipes)
- Vegan Database Client (local fallback)
- Cache Manager (response caching)

Key Components

agents/router_agent.py

  • Main orchestrator using LangChain
  • Defines tools and handles routing
  • Manages conversation flow

agents/memory_manager.py

  • Conversation history with sliding window
  • User profile (preferences, restrictions, goals)
  • LLM-compatible message formatting

agents/response_synthesizer.py

  • Multi-source output formatting
  • Error handling and user-friendly messages
  • Response quality optimization

tools/ - Core tool implementations

  • ingredient_tools.py - Vegan status checking, alternatives
  • recipe_tools.py - Recipe search and details
  • nutrition_tools.py - Nutrition analysis and comparisons
  • meal_planning_tools.py - Shopping lists and meal plans

data_sources/ - Data integration layer

  • usda_client.py - USDA FoodData Central API
  • spoonacular_client.py - Recipe API (5M+ recipes)
  • vegan_database.py - SQLite local database
  • cache_manager.py - TTL-based caching

Configuration

Environment Variables

# AI & Authentication (GitHub token for Copilot GPT-4o)
GITHUB_TOKEN=ghp_...  # Your GitHub personal access token

# External APIs
SPOONACULAR_API_KEY=...  # Get from spoonacular.com
USDA_API_KEY=...  # Get from fdc.nal.usda.gov

# LLM Configuration
LLM_MODEL=gpt-4o  # Model to use
LLM_TEMPERATURE=0.7  # Creativity level (0-1)
LLM_MAX_TOKENS=2000  # Max response length

# Application Settings
DEBUG=False  # Development mode
LOG_LEVEL=INFO  # Logging level
CACHE_TYPE=file  # Cache backend
CACHE_TTL_HOURS=24  # Cache time-to-live

# UI Settings
STREAMLIT_SERVER_PORT=8501
NATURE_THEME=True

API Configuration Notes

GitHub Token for GPT-4o: The application is configured to use your GitHub token for GPT-4o access via Copilot. The standard OpenAI endpoint is currently used, but can be switched to the GitHub Copilot API by:

  1. Setting the API base URL to GitHub Copilot endpoint
  2. Using appropriate authentication headers
  3. Adjusting model name if needed

Refer to GitHub Copilot documentation for specific configuration details.

πŸ“š Usage Examples

1. Check if an ingredient is vegan

User: "Is milk vegan?"
Assistant: Milk: βœ— Not Vegan
Why: Animal product - from cow lactation
Vegan Alternatives:
1. Soy Milk...

2. Find recipes with ingredients

User: "I have tofu and broccoli. What can I make?"
Assistant: [Lists 10 vegan recipes using these ingredients]

3. Compare nutrition

User: "Compare milk and oat milk nutrition"
Assistant: [Nutritional comparison table with analysis]

4. Get meal plan

User: "Generate a 3-day vegan meal plan"
Assistant: [Meal plan with shopping list]

πŸ§ͺ Testing

Run tests

# All tests
pytest tests/ -v

# Specific test file
pytest tests/test_ingredient_tools.py -v

# With coverage
pytest tests/ --cov=. --cov-report=html

Current test status

  • βœ… Ingredient tools: 5/5 passing
  • βœ… Configuration: Working
  • βœ… Data sources: Connected
  • βœ… Cache system: Functional

πŸ“ Project Structure

plant-based-assistant/
β”œβ”€β”€ agents/              # LangChain agents and orchestration
β”‚   β”œβ”€β”€ router_agent.py  # Main decision-making agent
β”‚   β”œβ”€β”€ memory_manager.py # Conversation memory + user profile
β”‚   └── response_synthesizer.py
β”œβ”€β”€ data_sources/        # API clients and databases
β”‚   β”œβ”€β”€ usda_client.py
β”‚   β”œβ”€β”€ spoonacular_client.py
β”‚   β”œβ”€β”€ vegan_database.py
β”‚   β”œβ”€β”€ cache_manager.py
β”‚   └── data/vegan_ingredients.csv
β”œβ”€β”€ tools/               # Tool functions for agents
β”‚   β”œβ”€β”€ ingredient_tools.py
β”‚   β”œβ”€β”€ recipe_tools.py
β”‚   β”œβ”€β”€ nutrition_tools.py
β”‚   └── meal_planning_tools.py
β”œβ”€β”€ ui/                  # Streamlit interface
β”‚   └── app.py
β”œβ”€β”€ config/              # Configuration
β”‚   β”œβ”€β”€ settings.py
β”‚   β”œβ”€β”€ constants.py
β”‚   └── logger_config.py
β”œβ”€β”€ utils/               # Utilities
β”‚   β”œβ”€β”€ exceptions.py
β”‚   β”œβ”€β”€ retry_logic.py
β”‚   β”œβ”€β”€ validators.py
β”‚   β”œβ”€β”€ formatting.py
β”‚   └── logging_util.py
β”œβ”€β”€ tests/               # Test suite
β”‚   β”œβ”€β”€ conftest.py
β”‚   β”œβ”€β”€ test_ingredient_tools.py
β”‚   └── fixtures/
β”œβ”€β”€ docs/                # Documentation
β”œβ”€β”€ requirements.txt     # Python dependencies
β”œβ”€β”€ setup.py             # Package setup
β”œβ”€β”€ .env.example         # Environment template
β”œβ”€β”€ .gitignore           # Git ignore rules
└── README.md            # This file

πŸ›£οΈ Roadmap

Current: Phases 5-8

  • Data sources (USDA, Spoonacular, local DB)
  • Tool functions (7+ tools)
  • LangChain agents (router, memory, synthesis)
  • Streamlit UI (in progress)
  • Comprehensive error handling
  • Full test suite (80%+ coverage)
  • Documentation and demo video

Future Enhancements

  • User authentication and persistent profiles
  • Multi-language support
  • Advanced meal planning with nutritional targets
  • Recipe scaling and substitution suggestions
  • Integration with grocery delivery APIs
  • Mobile app (React Native)
  • Advanced analytics and user insights

πŸ“ API Documentation

Tool Functions

check_ingredient_vegan_status(ingredient: str) β†’ Dict

Check if ingredient is vegan with multi-source verification.

get_vegan_alternatives(ingredient: str, limit: int = 5) β†’ List[Dict]

Get vegan substitutes with nutritional matching scores.

search_recipes_by_ingredients(ingredients: List[str], diet_type: str = None) β†’ List[Dict]

Find recipes matching ingredients with dietary filters.

get_ingredient_nutrition(ingredient: str, serving_size: float = 100) β†’ Dict

Get USDA nutrition facts for ingredient + serving size.

generate_shopping_list(recipe_ids: List[int], servings: int = 1) β†’ Dict

Aggregate ingredients from multiple recipes.

See API_DOCUMENTATION.md for complete reference.

🀝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Commit changes with clear messages
  4. Push to branch
  5. Create Pull Request

πŸ“„ License

MIT License - See LICENSE file for details

πŸ‘¨β€πŸ’» Author

Plant Based Assistant Team

πŸ™ Acknowledgments

  • USDA FoodData Central for nutrition data
  • Spoonacular for recipe database
  • LangChain for AI orchestration
  • Streamlit for UI framework
  • GitHub Copilot for code assistance

πŸ“ž Support

For issues, questions, or suggestions:

  1. Check existing GitHub issues
  2. Create new issue with detailed description
  3. Include error logs and environment info
  4. Reference relevant code sections

Built with ❀️ for plant-based living

About

AICapstoneProject

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages