Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
84f8da1
git ignore
MariaGorodetski Feb 4, 2026
6dce12d
Stop tracking docs/ folder (build output)
MariaGorodetski Feb 4, 2026
8047af2
Fix image paths in notebooks, update UI styling, and add untargeted m…
MariaGorodetski Feb 4, 2026
104251f
Re-add docs/ folder for GitHub Pages deployment
MariaGorodetski Feb 4, 2026
c747a29
removed extra link from all notebooks
MariaGorodetski Feb 4, 2026
96f3bc6
Recreate voice notebook from markdown and fix bullet formatting
MariaGorodetski Feb 4, 2026
6141065
Render all site changes and update gait notebook
MariaGorodetski Feb 4, 2026
ded90dd
Update publications from Notion database
MariaGorodetski Feb 5, 2026
4505900
Fix publication links and add missing authors
MariaGorodetski Feb 5, 2026
4fdd3a3
Deploy chatbot to GitHub Pages
shaykraitman Feb 5, 2026
320265c
chatbot integration
shaykraitman Feb 5, 2026
1ad7ff9
Enable chatbot widget and redeploy
shaykraitman Feb 5, 2026
3900c09
Fix duplicate CORS headers and Lambda URL path
shaykraitman Feb 5, 2026
8169540
Update the README.md
shaykraitman Feb 5, 2026
da40f53
update the knowledge-base
shaykraitman Feb 8, 2026
26efd75
Improve chatbot UX: better formatting, shorter responses, localStorag…
shaykraitman Feb 8, 2026
5ee7838
Improve chatbot UX: shorter responses, better formatting, localStorag…
shaykraitman Feb 8, 2026
9e18c8d
Merge feat/chatbot-integration into main - remove lambda-deployment.z…
shaykraitman Feb 9, 2026
2e8943a
edit .gitignore file so it won't include pheno_knowledge_base_expande…
shaykraitman Feb 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Build outputs
docs-expanded/
# docs/ - removed from gitignore to track for GitHub Pages deployment

# Quarto files
.quarto/
Expand All @@ -17,8 +18,9 @@ __pycache__/
venv/
env/

# Generated knowledge base
pheno_knowledge_base_expanded/knowledge-base-context.txt

# Lambda deployment package (build artifact)
lambda/lambda-deployment.zip

# OS files
.DS_Store
Expand All @@ -31,3 +33,4 @@ Thumbs.db
*.swo
*~


149 changes: 149 additions & 0 deletions LAMBDA_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Lambda Backend Setup - Summary

## What Was Created

### 1. Lambda Function (`lambda/lambda_function.py`)
- **What it does:** Converts Flask app to Lambda handler
- **Features:**
- Handles HTTP requests (GET /api/health, POST /api/chat)
- CORS protection (only your GitHub Pages URL can call)
- Loads context file from Lambda package
- Calls OpenRouter API (same as before)
- Saves conversations to S3 (with logging)
- Returns answers in same format

### 2. Lambda Requirements (`lambda/requirements.txt`)
- **What it does:** Lists Python packages needed
- **Packages:**
- `requests` - For calling OpenRouter API
- `boto3` - For saving to S3

### 3. Packaging Script (`lambda/package_lambda.sh`)
- **What it does:** Creates zip file for Lambda deployment
- **Includes:**
- Lambda function code
- Python dependencies
- Knowledge base context file

### 4. IAM Policy (`lambda/iam-policy.json`)
- **What it does:** Defines permissions Lambda needs
- **Permissions:**
- Write to S3 bucket (save conversations)
- Write to CloudWatch logs (automatic logging)

### 5. Updated Files
- **`deploy.sh`:** Changed to use BACKEND_URL (Lambda URL) instead of API key
- **`env.example`:** Updated to show Lambda URL format

## How It Works

### Architecture Flow:
```
GitHub Pages (Frontend)
CORS Check (Lambda)
Lambda Function
OpenRouter API
S3 (Save conversation)
Return answer to frontend
```

### Key Differences from Flask:

1. **No Flask:** Lambda uses handler function, not Flask routes
2. **CORS:** Manual headers instead of Flask-CORS
3. **Context:** Loaded from package, not filesystem
4. **S3 Logging:** Conversations saved to S3 automatically
5. **Environment:** Uses AWS environment variables, not .env file

## Next Steps

### 1. Create S3 Bucket
- Name: `pheno-chatbot-conversations` (or your choice)
- Region: Same as Lambda

### 2. Package Lambda
```bash
cd lambda
chmod +x package_lambda.sh
./package_lambda.sh
```

### 3. Deploy to AWS Lambda
- Upload `lambda-deployment.zip`
- Set handler: `lambda_function.lambda_handler`
- Set environment variables:
- `OPENROUTER_API_KEY` - Your OpenRouter API key
- `S3_BUCKET_NAME` - Your S3 bucket name
- `FRONTEND_URL` - Your GitHub Pages URL (for CORS)

### 4. Configure IAM Role
- Attach policy from `iam-policy.json` to Lambda execution role
- Update bucket name in policy if different

### 5. Enable Function URL
- In Lambda console, create Function URL
- Copy the URL
- Update `.env` with: `BACKEND_URL=<lambda-url>`

### 6. Deploy Frontend
```bash
./deploy.sh
```

## Environment Variables Needed

### In Lambda (AWS Console):
- `OPENROUTER_API_KEY` - Required
- `S3_BUCKET_NAME` - Required (default: pheno-chatbot-conversations)
- `FRONTEND_URL` - Required (your GitHub Pages URL for CORS)

### In Local .env:
- `BACKEND_URL` - Lambda Function URL

## Security

✅ **API Key:** Stored in Lambda environment (never in frontend)
✅ **CORS:** Only your GitHub Pages URL can call Lambda
✅ **S3:** Conversations saved securely
✅ **Logs:** CloudWatch logs (automatic)

## Testing

### Test Lambda locally:
```bash
# Test health endpoint
curl https://your-lambda-url/api/health

# Test chat endpoint
curl -X POST https://your-lambda-url/api/chat \
-H "Content-Type: application/json" \
-d '{"question": "What is the population dataset?"}'
```

### Test frontend:
```bash
./deploy.sh
cd docs
python3 -m http.server 8000
# Visit http://localhost:8000
```

## Troubleshooting

### Lambda can't find context file:
- Make sure `create-knowledge-base.sh` was run first
- Context file should be in `pheno_knowledge_base_expanded/knowledge-base-context.txt`

### CORS errors:
- Check `FRONTEND_URL` environment variable matches your GitHub Pages URL exactly
- Include protocol: `https://your-username.github.io`

### S3 errors:
- Check IAM policy is attached to Lambda role
- Verify S3 bucket name matches `S3_BUCKET_NAME` environment variable
- Check bucket exists and is in same region as Lambda
Loading