Skip to content

B2 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

B2 #1

Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 51 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "Chat MCQ App",
"image": "mcr.microsoft.com/devcontainers/python:3-bullseye",
"features": {
"ghcr.io/devcontainers/features/node:1": {
"version": "lts"
}
},
"forwardPorts": [8000, 5173],
"portsAttributes": {
"8000": {
"label": "Backend API",
"onAutoForward": "notify",
"visibility": "public"
},
"5173": {
"label": "Frontend",
"onAutoForward": "notify",
"visibility": "public"
}
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
],
"settings": {
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash",
"icon": "terminal-bash"
}
}
}
}
},
"initializeCommand": "echo 'Initializing...'",
"onCreateCommand": {
"Fix Script Permissions": "chmod +x ./.devcontainer/fix-permissions.sh && ./.devcontainer/fix-permissions.sh"
},
"postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh",
"postStartCommand": "bash ./.devcontainer/startup.sh",
"postAttachCommand": {
"Start Backend & Frontend": "bash -c 'echo \"To start the frontend in a separate terminal, run: bash ./.devcontainer/start-frontend.sh\"'"
},
"remoteUser": "vscode"
}
12 changes: 12 additions & 0 deletions .devcontainer/fix-permissions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

echo "🔑 Fixing permissions for all shell scripts..."

# Find all .sh files in the .devcontainer directory and make them executable
find "$(dirname "$0")" -name "*.sh" -exec chmod +x {} \;

# Make the main startup scripts executable
chmod +x "$(dirname "$0")/../startup.ps1" 2>/dev/null || true

echo "✅ Permissions fixed successfully!"
echo "You can now run the startup scripts."
47 changes: 47 additions & 0 deletions .devcontainer1/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "Chat MCQ App",
"image": "mcr.microsoft.com/devcontainers/python:3-bullseye",
"features": {
"ghcr.io/devcontainers/features/node:1": {
"version": "lts"
}
},
"forwardPorts": [8000, 5173],
"portsAttributes": {
"8000": {
"label": "Backend API",
"onAutoForward": "notify",
"visibility": "public"
},
"5173": {
"label": "Frontend",
"onAutoForward": "notify",
"visibility": "public"
}
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
],
"settings": {
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash",
"icon": "terminal-bash"
}
}
}
}
},
"postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh",
"postStartCommand": "bash ./.devcontainer/startup.sh",
"postAttachCommand": {
"Start Backend & Frontend": "bash -c 'echo \"To start the frontend in a separate terminal, run: bash ./.devcontainer/start-frontend.sh\"'"
},
"remoteUser": "vscode"
}
17 changes: 17 additions & 0 deletions .devcontainer1/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

echo "Setting up Chat MCQ Application..."

# Install backend dependencies
cd /workspaces/$(basename $(pwd))/backend || cd backend
python -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt

# Install frontend dependencies
cd /workspaces/$(basename $(pwd))/frontend || cd ../frontend
npm install

echo "✅ Dependencies installed successfully!"
53 changes: 53 additions & 0 deletions .devcontainer1/start-frontend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
set -e

echo "==============================================="
echo "🚀 FRONTEND STARTUP SCRIPT - $(date)"
echo "==============================================="

# Get the workspace root directory
WORKSPACE_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
echo "Workspace root: $WORKSPACE_ROOT"

# Create logs directory if it doesn't exist
mkdir -p $WORKSPACE_ROOT/backend/logs

# Navigate to frontend directory
cd $WORKSPACE_ROOT/frontend

echo "📌 ENVIRONMENT CHECK:"
echo "- Working Directory: $(pwd)"
echo "- Node Version: $(node -v)"
echo "- NPM Version: $(npm -v)"

echo "📌 CHECKING FRONTEND FILES:"
if [ -f "package.json" ]; then
echo "✅ package.json found"
cat package.json | grep -E '"name"|"version"|"dev"'
else
echo "❌ package.json not found!"
exit 1
fi

if [ -f "vite.config.ts" ]; then
echo "✅ vite.config.ts found"
else
echo "❌ vite.config.ts not found!"
fi

# Kill any existing Vite processes
echo "📌 CHECKING FOR EXISTING PROCESSES:"
pkill -f "vite" || echo "No vite process found to kill"

# Ensure dependencies are installed
if [ ! -d "node_modules" ] || [ ! -d "node_modules/vite" ]; then
echo "📥 Installing npm dependencies..."
npm ci || npm install
fi

# Start frontend in foreground to better see errors
echo "🚀 STARTING FRONTEND SERVER"
echo "- Command: npm run dev -- --host 0.0.0.0 --port 5173"

# Direct output to both console and log file
exec npm run dev -- --host 0.0.0.0 --port 5173 | tee $WORKSPACE_ROOT/backend/logs/frontend.log
98 changes: 98 additions & 0 deletions .devcontainer1/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash
set -e

echo "==============================================="
echo "🔍 BACKEND STARTUP SCRIPT - $(date)"
echo "==============================================="

# Get the workspace root directory
WORKSPACE_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
echo "Workspace root: $WORKSPACE_ROOT"

# Check environment
echo "📌 ENVIRONMENT CHECK:"
echo "- Working Directory: $(pwd)"
echo "- User: $(whoami)"
echo "- Python Version: $(python --version 2>&1)"
echo "- Bash Version: $BASH_VERSION"

# Create logs directory for backend
mkdir -p $WORKSPACE_ROOT/backend/logs
echo "📁 Created logs directory: $WORKSPACE_ROOT/backend/logs"

echo "🚀 Starting Backend Server..."

# Navigate to backend directory
echo "📌 NAVIGATING TO BACKEND DIRECTORY"
cd $WORKSPACE_ROOT/backend
echo "- Working Directory now: $(pwd)"

echo "📌 CHECKING BACKEND FILES:"
echo "- Main.py exists: $([ -f main.py ] && echo 'Yes' || echo 'No')"
echo "- Requirements.txt exists: $([ -f requirements.txt ] && echo 'Yes' || echo 'No')"

# Check for virtual environment and activate it
echo "📌 CHECKING VIRTUAL ENVIRONMENT:"
if [ -d "venv" ]; then
echo "- Using venv virtual environment"
VENV_DIR="venv"
elif [ -d "env" ]; then
echo "- Using env virtual environment"
VENV_DIR="env"
else
echo "⚠️ No virtual environment found (venv or env), creating one..."
python -m venv env
VENV_DIR="env"
fi

echo "🔄 Starting backend server at http://localhost:8000"
echo "- Activating virtual environment..."

# Activate venv
echo "- Attempting to source $VENV_DIR/bin/activate"
source $VENV_DIR/bin/activate

# Install dependencies if needed
if [ ! -f "$VENV_DIR/lib/python*/site-packages/fastapi" ]; then
echo "📥 Installing backend dependencies..."
pip install -r requirements.txt
fi

# Log Python path after venv activation
echo "- Using Python from: $(which python 2>/dev/null || echo 'Unknown')"
echo "- Python version: $(python --version 2>&1)"

# Kill any existing uvicorn processes
echo "📌 CHECKING FOR EXISTING PROCESSES:"
pkill -f "uvicorn" || echo "No uvicorn process found to kill"

echo "- Starting uvicorn server with command: python -m uvicorn main:app --reload --host 0.0.0.0"
python -m uvicorn main:app --reload --host 0.0.0.0 > ./logs/backend.log 2>&1 &
BACKEND_PID=$!
echo $BACKEND_PID > /tmp/backend.pid
echo "✅ Backend server started with PID $BACKEND_PID"

# Check if backend started successfully
sleep 2
if ps -p $BACKEND_PID > /dev/null; then
echo "✅ Backend process verified running"
echo "- First 10 lines of backend log:"
head -n 10 ./logs/backend.log
else
echo "❌ ERROR: Backend process failed to start!"
echo "- Log content:"
cat ./logs/backend.log
exit 1
fi

echo "==============================================="
echo "✅ Backend startup completed!"
echo "🔌 Backend API: http://localhost:8000"
echo "📋 Backend logs are available at: ./logs/backend.log"
echo ""
echo "💻 To start the frontend, open a new terminal and run:"
echo " bash ./.devcontainer/start-frontend.sh"
echo "==============================================="

# Keep script running to maintain backend process
wait
29 changes: 29 additions & 0 deletions .devcontainer1/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

echo "Stopping Chat MCQ Application services..."

# Stop the backend server
if [ -f /tmp/backend.pid ]; then
BACKEND_PID=$(cat /tmp/backend.pid)
if ps -p $BACKEND_PID > /dev/null; then
echo "Stopping backend server (PID: $BACKEND_PID)"
kill $BACKEND_PID
else
echo "Backend server is not running"
fi
rm /tmp/backend.pid
fi

# Stop the frontend server
if [ -f /tmp/frontend.pid ]; then
FRONTEND_PID=$(cat /tmp/frontend.pid)
if ps -p $FRONTEND_PID > /dev/null; then
echo "Stopping frontend server (PID: $FRONTEND_PID)"
kill $FRONTEND_PID
else
echo "Frontend server is not running"
fi
rm /tmp/frontend.pid
fi

echo "✅ All services stopped"
6 changes: 6 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Backend Environment Variables
OPENAI_API_KEY=your-openai-api-key-here
FRONTEND_URL=https://mcq-frontend.onrender.com

# Frontend Environment Variables
VITE_API_URL=https://mcq-backend.onrender.com
31 changes: 31 additions & 0 deletions .github/workflows/render-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Deploy to Render

on:
push:
branches:
- main
- master # Including master in case you use that as your default branch

jobs:
deploy:
name: Deploy to Render
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Deploy Backend to Render
uses: JorgeLNJunior/[email protected]
with:
service_id: ${{ secrets.RENDER_BACKEND_SERVICE_ID }}
api_key: ${{ secrets.RENDER_API_KEY }}
wait_deploy: true
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy Frontend to Render
uses: JorgeLNJunior/[email protected]
with:
service_id: ${{ secrets.RENDER_FRONTEND_SERVICE_ID }}
api_key: ${{ secrets.RENDER_API_KEY }}
wait_deploy: true
github_token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion backend/app/api/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
async def process_chat(request: ChatRequest):
"""Process a chat message and return a response or MCQs"""
try:
logger.debug(f"Received chat request: {request}")
# Enhanced logging for debugging
logger.info(f"POST /chat endpoint called with message: {request.message[:30]}...")
logger.debug(f"Full chat request details: {request}")
user_query = request.message

# Use LLM to detect MCQ intent
Expand Down
Loading