Skip to content

Commit

Permalink
adding run.sh and setup environement variables automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
lordx64 committed Jan 9, 2025
1 parent 1118ef2 commit 127bc5a
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ Example Response Format:
ANTHROPIC_API_KEY=your-anthropic-key
CUSTOM_MODEL_ENDPOINT=your-endpoint
```

5. Optional : You can use run.sh to start the backend and frontend and have all the environment variables set up for you
```bash
./run.sh
```
## 🚀 Running the Framework

1. Start the backend:
Expand Down
5 changes: 3 additions & 2 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
from orchestrator import Orchestrator
import traceback
from typing import Dict, Any

import logging
logger = logging.getLogger(__name__)
app = Flask(__name__)
orchestrator = Orchestrator()

@app.route('/api/query', methods=['POST'])
def query() -> tuple[Dict[str, Any], int]:
try:
data = request.json
print(data)
logger.debug(f"Received data: {data}")
if not data or 'input' not in data:
return jsonify({"error": "No input provided", "status": "error"}), 400

Expand Down
6 changes: 4 additions & 2 deletions frontend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
chainlit>=0.7.0
requests
flask
python-dotenv
requests
chainlit
66 changes: 66 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

# Function to stop background processes on script exit
cleanup() {
echo "Stopping all processes..."
kill $(jobs -p) 2>/dev/null
exit
}

# Set up trap to catch script termination
trap cleanup EXIT INT TERM

# Check if python3 is installed
if ! command -v python3 &> /dev/null; then
echo "Python3 is not installed. Please install Python3 to continue."
exit 1
fi

# Check if pip is installed
if ! command -v pip3 &> /dev/null; then
echo "pip3 is not installed. Please install pip3 to continue."
exit 1
fi

# Create virtual environments if they don't exist
if [ ! -d "backend/venv" ]; then
echo "Creating backend virtual environment..."
python3 -m venv backend/venv
fi

if [ ! -d "frontend/venv" ]; then
echo "Creating frontend virtual environment..."
python3 -m venv frontend/venv
fi

# Install backend dependencies
echo "Installing backend dependencies..."
source backend/venv/bin/activate
pip install -r backend/requirements.txt
deactivate

# Install frontend dependencies
echo "Installing frontend dependencies..."
source frontend/venv/bin/activate
pip install -r frontend/requirements.txt
deactivate

# Start backend
echo "Starting backend server..."
source backend/venv/bin/activate
cd backend && python app.py &
deactivate


echo $(pwd)
# Start frontend
echo "Starting frontend server..."
source frontend/venv/bin/activate
cd frontend && chainlit run main.py &
cd ..


# Wait for both processes
echo "Both servers are running..."
echo "Press Ctrl+C to stop both servers"
wait

0 comments on commit 127bc5a

Please sign in to comment.