by Ivan Saldikov
Social: https://www.linkedin.com/in/ivansaldikov/
Email: i at armonia.day
Tech Stack:
Docker
(everything is packed here)Django
Postgres
Redis
RabbitMQ
Celery
Supported Anthropic API, but also can be used OpenAI and TogetherAI APIs.
This framework can be used for developing different AI Assistants in the Web.
This framework is used by such projects:
- Armonia.day https://armonia.day
- MyAIGf.online https://myaigf.online
- StDiff.io https://stdiff.io
Source code of AI Theraphist Project: https://armonia.day.
Ensure you have docker-compose
at least of version 2.*.
-
Copy
.env
to.env.local
and modify it according to your needs. -
Run the command
make b
- If you're doing this first time please run these commands:
make migs
make mig
make csup
Once all this is done, you can navigate to http://localhost:8007/api/ping
to see is everything working.
pip install -r app/requirements.txt
- Django Root is the
app
folder.settings.py
is inconfig
folder.
Go to http://localhost:8007/admin/ and enter your superuser credentials to enter to the Admin panel.
docker-compose down
Run production environment
make b
make mig
make coll
Check for errors in the logs
docker-compose logs -f [CONTAINERNAME]
You can also filter log to get specific celery task logs.
docker-compose logs -f worker | sed -n '<SEACH_STRING>'
We use some pre-commit hooks to ensure that:
- Each new commit respect the recommended coding style conventions (PEP-8).
- We have a more harmonious code.
- No discussion between developers, we all agree to follow Black, isort & flake8 instructions.
- More time to focus on the functionalities rather than the coding style.
How to install it?
pip install pre-commit
pre-commit install
Further details about installation here
You might also need to install packer
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install packer
Then initialize packer
packer init provisioning/packer/source.pkr.hcl
And also install ansible
sudo apt install ansible
sudo nano /etc/systemd/system/armonia.service
- Copy this block of code:
[Unit]
Description=Start docker app
[Service]
ExecStart=/bin/bash -c 'cd /home/ubuntu/armonia; docker-compose -f docker-compose.server.yml up -d --build;'
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable armonia.service
$ python3 manage.py shell
>>> import channels.layers
>>> channel_layer = channels.layers.get_channel_layer()
>>> from asgiref.sync import async_to_sync
>>> async_to_sync(channel_layer.send)('test_channel', {'type': 'hello'})
>>> async_to_sync(channel_layer.receive)('test_channel')
{'type': 'hello'}
To connect to database on the prod you need to use SSH tunnel.
To check code style in the Python files of the project before a Pull Request use the command:
make lint
which is equivalent of the command (see the Makefile
in the root directory):
flake8 --ignore=E501,F401,E402 --exclude=node_modules app
Before using this you need to install flake8 in your Terminal by:
pip install flake8
To use make
command in Microsoft Windows OS install it by:
choco install make
After changing of .gitlab-ci.yml you can use CI Lint at Gitlab Pipelines section to verify that the file works fine.
TODO: https://tartarus.org/james/diary/2013/07/18/fun-with-django-storage-backends
Make collect static not to the server, but to the S3 storage.
- Just got to Google Console and increase the disk size:
- SSH to VM and use this commands to tell Linux to update the volume size:
https://cloud.google.com/compute/docs/disks/resize-persistent-disk
sudo resize2fs /dev/nvme0n1
- Install Docker.
- Create new user
devops_user
: https://linuxhint.com/addinng_new_user_debian/ - Allow
devops_user
user to run docker withoutsudo
: https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user - Copy SSH keys to
/home/devops_user/.ssh
: https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-debian-11 - To Generate Certificates - see section below (certbot).
- Copy
default.conf
fromservers/main/nginx
folder to/opt/armonia/nginx/
folder on remote machine. - Create
docker-comose.prod.yml
in/opt/armonia
folder. - Create
/mnt/media
and/mnt/static
folder for media and static files and make devops_user the owner of it:mkdir /mnt/media mkdir /mnt/static chown 911:911 /mnt/media chown 911:911 /mnt/static
911
is a UID of app user in the app docker containers. - Use Gitlab CI/CD to build and deploy the app.
To optimize it we can use these settings: https://docs.nginx.com/nginx/admin-guide/security-controls/controlling-access-proxied-tcp/
Box-Icons for showing "G" icon when Google Auth is used: https://boxicons.com/?query=home
Remove all unused Docker things (safe to execute):
docker system prune -a
Then we need manually run the command docker compose up -d --build
and
run migrations (with the help of Gitlab is okay).
We need to show user country related content to provide good service. It's always better to communicate with your own culture instead of anything else.
To achieve that we use the middleware from countries app. We can use API to get IP2Country or a database file with the list of correspond countries from ips.
Local database file:
- Download: https://ipinfo.io/account/data-downloads
- Use: https://dev.maxmind.com/geoip/geolocate-an-ip/databases?lang=en
API:
- https://github.com/ipinfo/python
- or this one (less paid per month, but no free plans): https://dev.maxmind.com/geoip/geolocate-an-ip
Ref: https://mindsers.blog/en/post/https-using-nginx-certbot-docker/
Renew:
docker compose run --rm certbot renew
- Dry run (when no certificates) - comment them in nginx.conf:
docker compose --profile=certbot run --rm certbot certonly --webroot --webroot-path /var/www/certbot/ --dry-run -d armonia.day
- Real Run - still need to be commented in nginx.conf (see nginx.conf.init):
docker compose --profile=certbot run --rm certbot certonly --webroot --webroot-path /var/www/certbot/ -d armonia.day
- Run the renew command sometimes:
docker compose --profile=certbot run --rm certbot renew
https://superuser.com/questions/300606/how-to-analyse-disk-usage-in-command-line-linux
ncdu -q .
Intro:
### System Prompt
You are a psychologist who helps the user with their issues.
Your task, using different approaches from psycology, conduct therapy with the user so that he feels better.
First of all you need to understand user issue, try to figure out what you need to solve the problem, plan the therapy and conduct it step by step after user's replies.
https://www.meetgor.com/django-htmx-chat-app/
Like we use in chats incoming messages.
https://pixabay.com/sound-effects/search/sound/
https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-22-04