qa-and-rag-ai-assistant/QUICK_START.md
2026-01-13 15:38:27 +03:00

4.9 KiB

Quick Start Guide

Installation (5 minutes)

# 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

python bot.py

This starts both the FastAPI server and Telegram bot together.

Option 2: Separate Processes (For Testing)

# 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

curl http://localhost:8000/login

Expected response:

{
  "message": "Нажмите на кнопку для регистрации",
  "url": "https://t.me/ITMOshkaBot?start={token}",
  "check_status_url": "/check-auth/{token}"
}

2. Check Database Tokens

curl http://localhost:8000/database/tokens

Expected response:

[
  {
    "token": "uuid-here",
    "status": "pending",
    "username": null
  }
]

3. Test Profile Creation

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

curl http://localhost:8000/profile/john@example.com

5. List Vacancies

curl http://localhost:8000/vacancies

Database Quick Commands

View All Users

docker exec rag_ai_postgres psql -U postgres -d rag_ai_assistant -c "SELECT * FROM users;"

View All Profiles

docker exec rag_ai_postgres psql -U postgres -d rag_ai_assistant -c "SELECT email, name, position FROM profiles;"

Delete All Users (Reset)

docker exec rag_ai_postgres psql -U postgres -d rag_ai_assistant -c "DELETE FROM users;"

Count Records

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

python init_db.py
# Choose option 2: Drop and recreate tables

Check PostgreSQL Logs

docker logs rag_ai_postgres -f

Check MinIO Status

docker ps | grep minio
# Or visit: http://localhost:9001
# Login: minioadmin / minioadmin

Backup Database

docker exec rag_ai_postgres pg_dump -U postgres rag_ai_assistant > backup_$(date +%Y%m%d).sql

Restore Database

docker exec -i rag_ai_postgres psql -U postgres rag_ai_assistant < backup_20240109.sql

Environment Variables (.env)

Make sure these are set correctly:

# 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

# Check if PostgreSQL is running
docker ps | grep postgres

# Restart if needed
docker-compose restart rag_ai_postgres

"No module named 'X'" errors

# Reinstall dependencies
uv pip install -r requirements.txt

Database tables don't exist

# Reinitialize
python init_db.py

Bot not responding

# 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:

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


Status: All systems operational PostgreSQL: Port 5432 MinIO: Port 9000 (API) / 9001 (Console) FastAPI: Port 8000