Skip to content

Modified chatbot

Modified chatbot #6

name: Deploy Python Chatbot
on:
push:
branches: [ "main" ]
paths:
- 'Python RAG chatbot/**'
- '.github/workflows/deploy_chatbot.yml'
jobs:
deploy-chatbot:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Copy chatbot files to EC2
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.CHATBOT_EC2_HOST }}
username: ec2-user
key: ${{ secrets.EC2_SSH_KEY }}
source: "Python RAG chatbot/*"
target: "/home/ec2-user/"
strip_components: 0
- name: Deploy and restart chatbot service
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.CHATBOT_EC2_HOST }}
username: ec2-user
key: ${{ secrets.EC2_SSH_KEY }}
script: |
cd "/home/ec2-user/Python RAG chatbot"
# Install/update dependencies
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt
# Create/update .env file with secrets
cat > .env <<EOF
PINECONE_API_KEY=${{ secrets.CHATBOT_PINECONE_API_KEY }}
PINECONE_CLOUD=${{ secrets.PINECONE_CLOUD }}
PINECONE_REGION=${{ secrets.PINECONE_REGION }}
PINECONE_INDEX=${{ secrets.CHATBOT_PINECONE_INDEX }}
PINECONE_NAMESPACE=${{ secrets.PINECONE_NAMESPACE }}
EMBED_MODEL=${{ secrets.EMBED_MODEL }}
CHAT_MODEL=${{ secrets.CHAT_MODEL }}
OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}
EOF
# Create/update systemd service file
sudo tee /etc/systemd/system/chatbot.service > /dev/null <<EOF
[Unit]
Description=Tariff RAG Chatbot API
After=network.target
[Service]
Type=simple
User=ec2-user
WorkingDirectory=/home/ec2-user/Python RAG chatbot
ExecStart=/usr/bin/python3 -m uvicorn src.api_server:app --host 0.0.0.0 --port 8000
Restart=on-failure
RestartSec=10
StandardOutput=journal
StandardError=journal
SyslogIdentifier=chatbot
[Install]
WantedBy=multi-user.target
EOF
# Reload and restart service
sudo systemctl daemon-reload
sudo systemctl enable chatbot
sudo systemctl restart chatbot
# Check service status
sudo systemctl status chatbot --no-pager