How ishaanvijaypuniya/interactiveagent-withmemory-recurrent-neural-network- works
Project Type & Purpose
• Type: A backend-focused full-stack service (no UI code in repo)
• Purpose:
• Expose a web API (Flask/FastAPI) for conversational AI
• Maintain per-user conversation memory
• Collect user feedback and continuously retrain an LSTM model
File Structure
.
• app.py # API entrypoint (Flask/FastAPI)
• train_model.py # Model training pipeline
• config.py # Environment & hyperparameters
• requirements.txt
• models/
• chatbot_model.py # LSTM architecture & inference
• memory_handler.py # Read/write conversation context
• utils/
• helpers.py # Text preprocessing, tokenization
• data/
• training_data.json # Seed dataset
• feedback_data.json # User ratings & corrections
• conversations.json # Session histories
• Layers
• API Layer (app.py)
• Application Logic (memory_handler.py, helpers.py)
• Model Layer (chatbot_model.py)
• Persistence (JSON file store)
• Training Pipeline (train_model.py)
README Insights
• Frameworks: Flask/FastAPI, TensorFlow/Keras
• Data Flow:
1. User → API → Memory → Model → Response
2. User rates response → Feedback store
3. Periodic retraining merges initial & feedback data
User Client
• Chat UI or CLI that sends/receives JSON
API Gateway (app.py)
• POST /chat
• POST /feedback
Memory Manager (memory_handler.py)
• Loads/saves per-user context from conversations.json
Text Processor (utils/helpers.py)
• Tokenization, cleaning, embedding prep
Chatbot Model (chatbot_model.py)
• LSTM inference
Data Store (JSON files)
• training_data.json, feedback_data.json, conversations.json
Training Service (train_model.py)
• Combines JSON datasets, retrains LSTM, exports new model weights
Configuration (config.py)
• Hyperparameters, file paths, API settings
Architectural Patterns & Design Principles
• Layered Architecture:
• Presentation (API) → Business (Memory + Model) → Persistence (JSON)
• Separation of Concerns:
• Inference vs. Training code are decoupled
• Event-Driven Feedback Loop:
• Feedback endpoint triggers data append → retraining pipeline
• Modular Code Organization:
• Clear directories for models, utils, data
• [User Client]
• POST /chat
• ▼
• ┌────────────┐
• API Layer │
• ┘
• ▼
┌──────────────────┐ ┌───────────────────┐
• Memory Manager │◀──────▶│ Conversation Store│ (conversations.json)
• ┘ └───────────────────┘
• ▼
┌──────────────────┐ ┌───────────────────┐
• Text Processor │ │ Training Script │◀───┐
• (helpers.py) │ │ (train_model.py) │ │
• ┘ └───────────────────┘ │
• Merge & Retrain
• ▼ │
┌──────────────────┐ │
• Chatbot Model │ │
• (LSTM Inference) │ │
• ┘ │
• ▼ │
• [Response JSON] ▼
• Updated Model Weights