Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ls1intum/Thaii
Browse files Browse the repository at this point in the history
  • Loading branch information
David Mang committed Aug 19, 2024
2 parents c3a18ed + aa6e518 commit cba5f52
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 1 deletion.
58 changes: 58 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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"
131 changes: 130 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,130 @@
# THAII
# 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/)
86 changes: 86 additions & 0 deletions compose.dv.yml
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit cba5f52

Please sign in to comment.