Skip to content

Commit 151d583

Browse files
committed
Initial commit: project structure and readme
0 parents  commit 151d583

File tree

143 files changed

+620
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+620
-0
lines changed

.env.example

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
POSTGRES_USER=seratonin
2+
POSTGRES_PASSWORD=seratonin_pass
3+
POSTGRES_DB=seratonin_db
4+
POSTGRES_HOST=postgres
5+
POSTGRES_PORT=5432
6+
7+
REDIS_HOST=redis
8+
REDIS_PORT=6379
9+
10+
QDRANT_HOST=qdrant
11+
QDRANT_PORT=6333
12+
QDRANT_GRPC_PORT=6334
13+
14+
EXTERNAL_POSTGRES_PORT=5433
15+
EXTERNAL_REDIS_PORT=6380
16+
EXTERNAL_QDRANT_PORT=6333
17+
EXTERNAL_QDRANT_GRPC_PORT=6334
18+
19+
OPENAI_API_KEY=sk-dummy-test-key-for-ci
20+
ANTHROPIC_API_KEY=dummy-test-key-for-ci
21+
PUBMED_API_KEY=dummy-test-key-for-ci

.github/workflows/build.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Stub build
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
placeholder:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- run: echo "Це просто заглушка, щоб файл не був порожнім."

.github/workflows/deploy.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Stub deploy
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
placeholder:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- run: echo "Це просто заглушка, щоб файл не був порожнім."

.github/workflows/lint.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Linting & Type Checking
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
env:
13+
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Python 3.13.11
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.13.11"
21+
22+
- name: Install Poetry
23+
run: pip install poetry
24+
25+
- name: Install dependencies
26+
run: poetry install
27+
28+
- name: Run Ruff Linter
29+
run: poetry run ruff check .
30+
31+
- name: Run Ruff Formatter check
32+
run: poetry run ruff format --check .
33+
34+
- name: Run Pyright Type Checker
35+
run: poetry run pyright

.github/workflows/test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
env:
13+
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Python 3.13.11
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.13.11"
21+
22+
- name: Install Poetry
23+
run: pip install poetry
24+
25+
- name: Install dependencies
26+
run: poetry install
27+
28+
- name: Setup test environment
29+
run: cp .env.example .env
30+
31+
- name: Run pytest
32+
run: poetry run pytest

.gitignore

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Knowledge Base
2+
knowledge_base/doctor_style
3+
knowledge_base/medical_guidelines
4+
test_output.txt
5+
# Python
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
*.so
10+
.Python
11+
env/
12+
venv/
13+
ENV/
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
wheels/
26+
*.egg-info/
27+
.installed.cfg
28+
*.egg
29+
30+
# IDE
31+
.vscode/
32+
.idea/
33+
*.swp
34+
*.swo
35+
*~
36+
37+
# Environment
38+
.env
39+
.env.local
40+
.env.*.local
41+
42+
# Database
43+
*.db
44+
*.sqlite
45+
*.sqlite3
46+
47+
# OS
48+
.DS_Store
49+
Thumbs.db
50+
51+
# Testing
52+
.pytest_cache/
53+
.coverage
54+
htmlcov/
55+
56+
# Logs
57+
logs/
58+
*.log
59+
60+
seed_test_data.py
61+
collect_context.pyw
62+
project_context.txt
63+
debug_raw_search.json
64+
debug_serper.py
65+
scripts/test_pipeline.py

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13.11

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Makefile

README.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# 🧠 Serotonin Script
2+
3+
![Python](https://img.shields.io/badge/python-3.11+-blue.svg)
4+
![FastAPI](https://img.shields.io/badge/FastAPI-0.109+-green.svg)
5+
![Taskiq](https://img.shields.io/badge/Taskiq-Async--Native-orange.svg)
6+
![RAG](https://img.shields.io/badge/RAG-LlamaIndex%2FQdrant-red.svg)
7+
![License](https://img.shields.io/badge/license-MIT-green.svg)
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

Comments
 (0)