|
| 1 | +# 🧠 Serotonin Script |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +> AI-driven medical content engine using RAG (LlamaIndex/Qdrant), FastAPI, and Taskiq for automated multi-platform publishing with physician style preservation. |
| 10 | +
|
| 11 | +--- |
| 12 | + |
| 13 | +## 🎯 Overview |
| 14 | + |
| 15 | +**Serotonin Script** is an autonomous system for generating and distributing medically-accurate content across social platforms. It leverages **RAG (Retrieval-Augmented Generation)** to ensure medical precision while preserving the unique authorial voice of healthcare professionals. |
| 16 | + |
| 17 | +### Key Capabilities |
| 18 | +- **Style Preservation**: Vector-based retrieval of physician's writing patterns |
| 19 | +- **Medical Accuracy**: Fact-checking against clinical guidelines (PubMed, protocols) |
| 20 | +- **Multi-Platform Publishing**: Automated distribution to Telegram, X (Twitter), Threads |
| 21 | +- **Async-First Architecture**: High-performance task processing via Taskiq + Redis |
| 22 | +- **Slack-Native UX**: Draft approval workflow with interactive Block Kit UI |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## 🛠 Tech Stack |
| 27 | + |
| 28 | +| Layer | Technology | Purpose | |
| 29 | +|-------|-----------|---------| |
| 30 | +| **API Framework** | FastAPI | Async-native REST API | |
| 31 | +| **Task Queue** | [Taskiq](https://github.com/taskiq-python/taskiq) + Redis | Background job processing | |
| 32 | +| **AI Engine** | Claude 3.5 Sonnet / GPT-4o | Content generation with fallback | |
| 33 | +| **Vector Store** | Qdrant | Semantic search for style/knowledge | |
| 34 | +| **RAG Framework** | LlamaIndex | Retrieval-augmented generation pipeline | |
| 35 | +| **Orchestration** | n8n | Workflow automation & scheduling | |
| 36 | +| **Database** | PostgreSQL + Alembic | Relational data with migrations | |
| 37 | +| **Monitoring** | Prometheus + Grafana + Loki | Metrics, dashboards, logs | |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +## 📁 Project Structure |
| 42 | +```text |
| 43 | +seratonin_script/ |
| 44 | +├── backend/ |
| 45 | +│ ├── api/ # FastAPI routes & middleware |
| 46 | +│ ├── services/ # Business logic orchestration |
| 47 | +│ ├── agents/ # LangChain agents + tools |
| 48 | +│ ├── rag/ # LlamaIndex indexing & retrieval |
| 49 | +│ ├── integrations/ # External APIs (LLMs, social platforms, PubMed) |
| 50 | +│ ├── workers/ # Taskiq async workers |
| 51 | +│ └── tests/ # Unit, integration, E2E tests |
| 52 | +├── knowledge_base/ # Training data for RAG |
| 53 | +│ ├── doctor_style/ # Physician's articles & posts |
| 54 | +│ └── medical_guidelines/ # Clinical protocols (PDFs) |
| 55 | +├── slack_app/ # Slack Block Kit UI & handlers |
| 56 | +├── orchestration/n8n/ # Workflow definitions |
| 57 | +├── database/migrations/ # Alembic schema versions |
| 58 | +├── infra/docker/ # Docker Compose + monitoring configs |
| 59 | +└── docs/ # Architecture & ADRs |
| 60 | +``` |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +## 🚀 Quick Start |
| 65 | + |
| 66 | +### Prerequisites |
| 67 | +- Docker & Docker Compose |
| 68 | +- Python 3.11+ (for local development) |
| 69 | +- Slack workspace (for approval workflow) |
| 70 | +- API keys: Anthropic/OpenAI, Telegram, X, Threads |
| 71 | + |
| 72 | +### Installation |
| 73 | +```bash |
| 74 | +# Clone repository |
| 75 | +git clone https://github.com/PyDevDeep/serotonin-script.git |
| 76 | +cd serotonin-script |
| 77 | + |
| 78 | +# Configure environment |
| 79 | +cp .env.example .env |
| 80 | +# Edit .env with your API keys and credentials |
| 81 | + |
| 82 | +# Start all services |
| 83 | +docker-compose up --build |
| 84 | +``` |
| 85 | + |
| 86 | +### Service URLs |
| 87 | +- **API**: http://localhost:8000 |
| 88 | +- **API Docs**: http://localhost:8000/docs |
| 89 | +- **n8n**: http://localhost:5678 |
| 90 | +- **Grafana**: http://localhost:3000 |
| 91 | + |
| 92 | +--- |
| 93 | + |
| 94 | +## 📖 Usage |
| 95 | + |
| 96 | +### 1. Index Knowledge Base |
| 97 | +```bash |
| 98 | +# Ingest physician's writing samples + medical guidelines into Qdrant |
| 99 | +python scripts/index_knowledge_base.py |
| 100 | +``` |
| 101 | + |
| 102 | +### 2. Generate Draft (via Slack) |
| 103 | +``` |
| 104 | +/draft anxiety management tips |
| 105 | +``` |
| 106 | + |
| 107 | +**Workflow**: |
| 108 | +1. Slack command triggers n8n webhook |
| 109 | +2. n8n calls `POST /draft` with topic |
| 110 | +3. Backend enqueues Taskiq task `generate_draft` |
| 111 | +4. Worker: |
| 112 | + - Retrieves similar physician posts (style matching) |
| 113 | + - Fetches relevant medical facts (knowledge retrieval) |
| 114 | + - Generates draft via Claude 3.5 Sonnet |
| 115 | +5. Slack receives Block Kit card with draft + action buttons |
| 116 | + |
| 117 | +### 3. Approve & Publish |
| 118 | + |
| 119 | +Click **"Publish to Telegram"** button in Slack: |
| 120 | +- Taskiq task `publish_post` executes |
| 121 | +- Content posted to configured channels |
| 122 | +- Slack notification confirms success |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +## 🔧 Development |
| 127 | + |
| 128 | +### Run Tests |
| 129 | +```bash |
| 130 | +# Unit tests |
| 131 | +make test-unit |
| 132 | + |
| 133 | +# Integration tests (requires running containers) |
| 134 | +make test-integration |
| 135 | + |
| 136 | +# Full test suite |
| 137 | +make test |
| 138 | +``` |
| 139 | + |
| 140 | +### Local Backend Development |
| 141 | +```bash |
| 142 | +# Install dependencies |
| 143 | +poetry install |
| 144 | + |
| 145 | +# Run API server |
| 146 | +poetry run uvicorn backend.api.main:app --reload |
| 147 | + |
| 148 | +# Run Taskiq worker |
| 149 | +poetry run taskiq worker backend.workers.broker:broker |
| 150 | +``` |
| 151 | + |
| 152 | +### Database Migrations |
| 153 | +```bash |
| 154 | +# Generate migration |
| 155 | +alembic revision --autogenerate -m "description" |
| 156 | + |
| 157 | +# Apply migrations |
| 158 | +alembic upgrade head |
| 159 | +``` |
| 160 | + |
| 161 | +--- |
| 162 | + |
| 163 | +## 📊 Monitoring |
| 164 | + |
| 165 | +- **Metrics**: http://localhost:3000/d/backend_metrics |
| 166 | +- **LLM Costs**: http://localhost:3000/d/llm_costs |
| 167 | +- **Taskiq Jobs**: http://localhost:3000/d/taskiq_metrics |
| 168 | + |
| 169 | +--- |
| 170 | + |
| 171 | +## 🗺️ Roadmap |
| 172 | + |
| 173 | +- [x] **Phase 1**: Infrastructure & Dev Environment Setup |
| 174 | +- [ ] **Phase 2**: RAG Pipeline Implementation (Doctor Style Matcher) |
| 175 | +- [ ] **Phase 3**: Taskiq Workers for Background Generation |
| 176 | +- [ ] **Phase 4**: Multi-Platform Publishing (Telegram, X, Threads) |
| 177 | +- [ ] **Phase 5**: Scheduled Posting & Analytics Dashboard |
| 178 | + |
| 179 | +--- |
| 180 | + |
| 181 | +## 🤝 Contributing |
| 182 | + |
| 183 | +1. Fork the repository |
| 184 | +2. Create feature branch (`git checkout -b feature/amazing-feature`) |
| 185 | +3. Commit changes (`git commit -m 'Add amazing feature'`) |
| 186 | +4. Push to branch (`git push origin feature/amazing-feature`) |
| 187 | +5. Open Pull Request |
| 188 | + |
| 189 | +See [CONTRIBUTING.md](docs/CONTRIBUTING.md) for detailed guidelines. |
| 190 | + |
| 191 | +--- |
| 192 | + |
| 193 | +## 📄 License |
| 194 | + |
| 195 | +This project is licensed under the MIT License - see [LICENSE](LICENSE) file for details. |
| 196 | + |
| 197 | +--- |
| 198 | + |
| 199 | +## 🙏 Acknowledgments |
| 200 | + |
| 201 | +- **LlamaIndex** for RAG framework |
| 202 | +- **Taskiq** for modern async task processing |
| 203 | +- **Qdrant** for vector search capabilities |
| 204 | +--- |
| 205 | + |
| 206 | +**Created by** [PyDevDeep](https://github.com/PyDevDeep) |
0 commit comments