236 lines
4.9 KiB
Markdown
236 lines
4.9 KiB
Markdown
# Quick Start Guide
|
|
|
|
## Installation (5 minutes)
|
|
|
|
```bash
|
|
# 1. Install dependencies with uv
|
|
uv pip install -r requirements.txt
|
|
|
|
# 2. Start Docker services (PostgreSQL + MinIO)
|
|
docker-compose up -d
|
|
|
|
# 3. Initialize database
|
|
python init_db.py
|
|
# Choose option 1: Create tables
|
|
|
|
# 4. Verify setup
|
|
docker exec rag_ai_postgres psql -U postgres -d rag_ai_assistant -c "\dt"
|
|
# Should show: users, profiles tables
|
|
```
|
|
|
|
## Running the Application
|
|
|
|
### Option 1: All-in-One (Recommended for Development)
|
|
```bash
|
|
python bot.py
|
|
```
|
|
This starts both the FastAPI server and Telegram bot together.
|
|
|
|
### Option 2: Separate Processes (For Testing)
|
|
```bash
|
|
# Terminal 1: API Server
|
|
uvicorn app:app --reload --host localhost --port 8000
|
|
|
|
# Terminal 2: Telegram Bot
|
|
.venv/bin/python -c "from bot import start_bot; import asyncio; asyncio.run(start_bot())"
|
|
```
|
|
|
|
## Testing the API
|
|
|
|
### 1. Test Login Endpoint
|
|
```bash
|
|
curl http://localhost:8000/login
|
|
```
|
|
**Expected response:**
|
|
```json
|
|
{
|
|
"message": "Нажмите на кнопку для регистрации",
|
|
"url": "https://t.me/ITMOshkaBot?start={token}",
|
|
"check_status_url": "/check-auth/{token}"
|
|
}
|
|
```
|
|
|
|
### 2. Check Database Tokens
|
|
```bash
|
|
curl http://localhost:8000/database/tokens
|
|
```
|
|
**Expected response:**
|
|
```json
|
|
[
|
|
{
|
|
"token": "uuid-here",
|
|
"status": "pending",
|
|
"username": null
|
|
}
|
|
]
|
|
```
|
|
|
|
### 3. Test Profile Creation
|
|
```bash
|
|
curl -X POST http://localhost:8000/profile \
|
|
-F "name=John Doe" \
|
|
-F "email=john@example.com" \
|
|
-F "position=Python Developer" \
|
|
-F "skills=Python, FastAPI, PostgreSQL" \
|
|
-F "cv=@/path/to/resume.pdf"
|
|
```
|
|
|
|
### 4. Get Profile
|
|
```bash
|
|
curl http://localhost:8000/profile/john@example.com
|
|
```
|
|
|
|
### 5. List Vacancies
|
|
```bash
|
|
curl http://localhost:8000/vacancies
|
|
```
|
|
|
|
## Database Quick Commands
|
|
|
|
### View All Users
|
|
```bash
|
|
docker exec rag_ai_postgres psql -U postgres -d rag_ai_assistant -c "SELECT * FROM users;"
|
|
```
|
|
|
|
### View All Profiles
|
|
```bash
|
|
docker exec rag_ai_postgres psql -U postgres -d rag_ai_assistant -c "SELECT email, name, position FROM profiles;"
|
|
```
|
|
|
|
### Delete All Users (Reset)
|
|
```bash
|
|
docker exec rag_ai_postgres psql -U postgres -d rag_ai_assistant -c "DELETE FROM users;"
|
|
```
|
|
|
|
### Count Records
|
|
```bash
|
|
docker exec rag_ai_postgres psql -U postgres -d rag_ai_assistant -c "SELECT COUNT(*) FROM users;"
|
|
docker exec rag_ai_postgres psql -U postgres -d rag_ai_assistant -c "SELECT COUNT(*) FROM profiles;"
|
|
```
|
|
|
|
## Common Tasks
|
|
|
|
### Reset Database
|
|
```bash
|
|
python init_db.py
|
|
# Choose option 2: Drop and recreate tables
|
|
```
|
|
|
|
### Check PostgreSQL Logs
|
|
```bash
|
|
docker logs rag_ai_postgres -f
|
|
```
|
|
|
|
### Check MinIO Status
|
|
```bash
|
|
docker ps | grep minio
|
|
# Or visit: http://localhost:9001
|
|
# Login: minioadmin / minioadmin
|
|
```
|
|
|
|
### Backup Database
|
|
```bash
|
|
docker exec rag_ai_postgres pg_dump -U postgres rag_ai_assistant > backup_$(date +%Y%m%d).sql
|
|
```
|
|
|
|
### Restore Database
|
|
```bash
|
|
docker exec -i rag_ai_postgres psql -U postgres rag_ai_assistant < backup_20240109.sql
|
|
```
|
|
|
|
## Environment Variables (.env)
|
|
|
|
Make sure these are set correctly:
|
|
|
|
```env
|
|
# Bot
|
|
BOT_API_KEY=your_telegram_bot_token_here
|
|
|
|
# Database
|
|
POSTGRES_USER=postgres
|
|
POSTGRES_PASSWORD=postgres
|
|
POSTGRES_DB=rag_ai_assistant
|
|
POSTGRES_HOST=localhost
|
|
POSTGRES_PORT=5432
|
|
|
|
# MinIO
|
|
MINIO_ENDPOINT=localhost:9000
|
|
MINIO_ACCESS_KEY=minioadmin
|
|
MINIO_SECRET_KEY=minioadmin
|
|
MINIO_BUCKET=resumes
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### "Connection refused" errors
|
|
```bash
|
|
# Check if PostgreSQL is running
|
|
docker ps | grep postgres
|
|
|
|
# Restart if needed
|
|
docker-compose restart rag_ai_postgres
|
|
```
|
|
|
|
### "No module named 'X'" errors
|
|
```bash
|
|
# Reinstall dependencies
|
|
uv pip install -r requirements.txt
|
|
```
|
|
|
|
### Database tables don't exist
|
|
```bash
|
|
# Reinitialize
|
|
python init_db.py
|
|
```
|
|
|
|
### Bot not responding
|
|
```bash
|
|
# Check bot token in .env
|
|
cat .env | grep BOT_API_KEY
|
|
|
|
# Test bot manually
|
|
curl https://api.telegram.org/bot{YOUR_TOKEN}/getMe
|
|
```
|
|
|
|
## API Documentation
|
|
|
|
Once running, visit:
|
|
- **Swagger UI:** http://localhost:8000/docs
|
|
- **ReDoc:** http://localhost:8000/redoc
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
├── app.py # FastAPI application
|
|
├── bot.py # Telegram bot
|
|
├── config.py # Configuration
|
|
├── init_db.py # Database setup script
|
|
├── requirements.txt # Dependencies
|
|
├── .env # Environment variables (create this!)
|
|
├── database/
|
|
│ └── database.py # ORM models & DB session
|
|
└── tests/ # Your tests
|
|
```
|
|
|
|
## Next Steps
|
|
|
|
1. ✅ Database is set up
|
|
2. ✅ API is working
|
|
3. ✅ Bot is connected
|
|
4. 📝 Test the authentication flow
|
|
5. 📝 Test profile creation
|
|
6. 📝 Add your custom business logic
|
|
|
|
## Support
|
|
|
|
- **Documentation:** See [README.md](README.md) for full details
|
|
- **Implementation Details:** See [IMPLEMENTATION_SUMMARY.md](IMPLEMENTATION_SUMMARY.md)
|
|
- **Database Schema:** See diagrams in implementation summary
|
|
|
|
---
|
|
|
|
**Status:** ✅ All systems operational
|
|
**PostgreSQL:** Port 5432
|
|
**MinIO:** Port 9000 (API) / 9001 (Console)
|
|
**FastAPI:** Port 8000
|