From 5a511d1ac4837c22aacde36fec4c9459aae34321 Mon Sep 17 00:00:00 2001 From: mangdavid <117346875+mangdavid@users.noreply.github.com> Date: Mon, 22 Jul 2024 12:30:19 +0200 Subject: [PATCH 1/3] Add documentation to README.md (#1) --- README.md | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 130 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b81d2c8..642a1c7 100644 --- a/README.md +++ b/README.md @@ -1 +1,130 @@ -# THAII \ No newline at end of file +# Thaii + +Thaii (Tool to analyze Human-AI-Interaction) is designed to provide users with insights into their AI usage for self-learning purposes. This research project aims to help users reflect on their interaction with conversational agents by tracking their usage and regulating their learning process. By offering these insights, Thaii seeks to reduce users' overdependency on conversational agents during their learning activities. + +## Main Features +- **Chatbot**: Utilize OpenAI's LLM to power a chatbot for active communication within the platform, allowing users to create, edit, label, and delete chats. +- **Pages**: Users can create, edit, and delete pages, assigning chats to organize them according to their needs. Pages enable personalization and structuring of chats, with tagging options for semantic connections. +- **Insights**: Users can analyze their chatbot interactions, filtering insights by pages, labels, and tags for a detailed view of their usage, aiding in monitoring and regulating their learning process. +- **User Management**: Admins can manage users and authorize email addresses eligible for registration in the system. + +## Prequesites + +Ensure you have the following installed on your machine: + +- Node.js (v14 or higher) +- npm (v6 or higher) +- Python (v3.8 or higher) +- pip +- virtualenv + +## Client Setup (React + Vite) + +1. Clone the respository + +```bash +https://github.com/ls1intum/Thaii.git +cd thaii +``` +2. Navigate to client directory +```bash +cd client +``` +3. Install dependencies: +```bash +npm install +``` +4. Start the development server: +```bash +npm run dev +``` +The client development server should now be running at `http://localhost:5173`. + +## Server Setup (Django) + +1. Navigate to the server directory: +```bash +cd ../server +``` +2. Create a virtual environment: +```bash +virtualenv venv +``` +3. Activate the virtual environment: +- On Windows: +```bash +venv\Scripts\activate +``` +- On macOS/Linux: +```bash +source venv/bin/activate +``` +4. Install dependencies: +```bash +pip install -r requirements.txt +``` +5. Run database migrations: +```bash +python manage.py migrate +``` +6. Create a superuser: +```bash +python manage.py createsuperuser +``` +- Follow the prompts to set up your superuser account. +- Superusers can log in to the system without being whitlisted first. +- Superusers can access the admin panel at `http://localhost:8000/api/admin` and manage the stored data. + +7. Start the development server: +```bash +python manage.py runserver +``` + +The server development server should now be running at `http://localhost:8000`. + +## Environment Variables +Ensure you have the necessary environment variables set up for both the frontend and backend. You can create a `.env` file in the root of each directory and add the required variables. + +### Client `.env` Example +```plaintext +VITE_API_URL=http://localhost:8000/ +``` + +### Server `.env` Example +```plaintext +OPENAI_API_KEY=your_open_ai_key +DEBUG=True +SECRET_KEY=your_secret_key +POSTGRES_DB=your_db_name +POSTGRES_USER=your_db_user +POSTGRES_PASSWORD=your_db_password +POSTGRES_HOST=your_db_host +EMAIL_USE_TLS=True +EMAIL_HOST=your_email_host +EMAIL_HOST_USER=your_email_host_user +EMAIL_HOST_PASSWORD=your_email_host_user_password +DEFAULT_FROM_EMAIL=your_default_email_host +EMAIL_PORT=587 +DJANGO_SUPERUSER_USERNAME=your_django_superuser +DJANGO_SUPERUSER_PASSWORD=your_django_superuser_password +DJANGO_SUPERUSER_EMAIL=your_django_superuser_email +``` +- `OPENAI_API_KEY`: Key for an OpenAI project to leverage the OpenAI API +- `POSTGRES_DB`, `POSTGRES_USER`, `POSTGRES_PASSWORD`, `POSTGRES_HOST`: Variables to setup and connect to a PostgreSQL database used to store the data created. +- `EMAIL_HOST`, `EMAIL_HOST_USER`, `EMAIL_HOST_PASSWORD`, `DEFAULT_FROM_EMAIL`: Email configurations to send activation emails for the register flow of users +- `DJANGO_SUPERUSER_USERNAME`, `DJANGO_SUPERUSER_PASSWORD`, `DJANGO_SUPERUSER_EMAIL`: Only important for the productive environment. When deployed a superuser with these credentials is created if it does not exist already. + +## Running Application +With both the client and server running, you should be able to access the web application at http://localhost:5173. + +## Additional Information +- **Client Build:** To create a production build of the frontend, run: +```bash +npm run build +``` +- **Server Management:** You can use standard Django management commands for additional backend tasks. +- **Data Management:** You can access the data using the admin panel at `http://localhost:8000/api/admin` with your superuser account or connect to the local database with pgAdmin. + +## License + +[MIT](https://choosealicense.com/licenses/mit/) From 4175a38db4ce12cbb9638f3d10d52e253f9dc200 Mon Sep 17 00:00:00 2001 From: mangdavid <117346875+mangdavid@users.noreply.github.com> Date: Mon, 19 Aug 2024 20:13:40 +0200 Subject: [PATCH 2/3] Add dev compose file for local development (#3) Co-authored-by: David Mang --- compose.dv.yml | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 compose.dv.yml diff --git a/compose.dv.yml b/compose.dv.yml new file mode 100644 index 0000000..ed4806a --- /dev/null +++ b/compose.dv.yml @@ -0,0 +1,86 @@ +services: + traefik: + restart: always + image: "traefik:latest" + command: + - --log.level=ERROR + - --providers.docker=true + - --entrypoints.web.address=:80 + - --providers.docker.exposedbydefault=false + - --providers.docker.network=web + ports: + - "80:80" + - "8080:8080" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + networks: + - web + + backend: + container_name: server + hostname: server + build: + context: . + dockerfile: docker/server/Dockerfile + labels: + - "traefik.enable=true" + - "traefik.http.routers.backend.rule=Host(`localhost`) && PathPrefix(`/api`)" + - "traefik.http.services.backend-service.loadbalancer.server.port=8000" + - "traefik.http.routers.backend.service=backend-service" + - "traefik.http.routers.backend.entrypoints=web" + env_file: + - .env + depends_on: + - db + networks: + - web + - backend + expose: + - "8000" + volumes: + - templates:/server/templates + + db: + image: postgres:16-alpine + env_file: + - .env + volumes: + - db-data:/var/lib/postgresql/data + networks: + - backend + + client: + container_name: client + hostname: client + build: + context: . + dockerfile: docker/client/Dockerfile + args: + VITE_API_URL: "http://localhost:80" + labels: + - "traefik.enable=true" + - "traefik.http.routers.client.rule=Host(`localhost`)" + - "traefik.http.services.client-service.loadbalancer.server.port=3000" + - "traefik.http.routers.client.service=client-service" + - "traefik.http.routers.client.entrypoints=web" + volumes: + - node_modules:/client/node_modules + depends_on: + - backend + networks: + - web + expose: + - "3000" + +networks: + web: + external: true + driver: bridge + backend: + external: false + driver: bridge + +volumes: + db-data: + node_modules: + templates: From aa6e518e3c408c6ac6d7f202a3d395640b4fa0fa Mon Sep 17 00:00:00 2001 From: mangdavid <117346875+mangdavid@users.noreply.github.com> Date: Mon, 19 Aug 2024 20:35:45 +0200 Subject: [PATCH 3/3] Feature/add deployment for GitHub (#4) * Add dev compose file for local development * Add deployment config for github actions --------- Co-authored-by: David Mang --- .github/workflows/deploy.yml | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..b10df13 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,58 @@ +name: Deploy + +on: + push: + branches: + - main # or the branch you want to deploy from + +jobs: + build: + name: Build Docker Images + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Set up Docker + uses: docker/setup-buildx-action@v2 + + - name: Log in to Container Registry + run: echo "${{ secrets.CI_REGISTRY_PASSWORD }}" | docker login ${{ secrets.CI_REGISTRY }} -u ${{ secrets.CI_REGISTRY_USER }} --password-stdin + + - name: Build Docker Images + run: docker compose build + + - name: Push Docker Images + run: | + docker push ${{ secrets.CI_REGISTRY }}/your-repo:client + docker push ${{ secrets.CI_REGISTRY }}/your-repo:server + + deploy: + name: Deploy Application + runs-on: ubuntu-latest + needs: build + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Install SSH Client + run: sudo apt-get update && sudo apt-get install -y openssh-client + + - name: Add SSH Key + uses: webfactory/ssh-agent@v0.8.1 + with: + ssh-private-key: ${{ secrets.SSH_KEY }} + + - name: Copy Files to Server + run: | + scp -o StrictHostKeyChecking=no ./compose.yml ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_DOMAIN }}:~/compose.yml + scp -o StrictHostKeyChecking=no -r ./letsencrypt ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_DOMAIN }}:~/letsencrypt + + - name: Deploy on Server + run: | + ssh -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_DOMAIN }} "mkdir -p ~/" + ssh -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_DOMAIN }} "touch ~/letsencrypt/acme.json && chmod 600 ~/letsencrypt/acme.json" + ssh -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_DOMAIN }} "docker login -u ${{ secrets.CI_REGISTRY_USER }} -p ${{ secrets.CI_REGISTRY_PASSWORD }} ${{ secrets.CI_REGISTRY }}" + ssh -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_DOMAIN }} "docker compose pull && docker compose up -d && docker compose logs"