This document will outline how to setup and run the Mourshid backend
- A machine with access to the internet running a Ubuntu Server or a similar linux distribution
- The machine must have at lest 8 gigabytes of RAM
-
The backend is written in spring boot and so JRE must be installed, it can be installed on linux using the following command
sudo apt install default-jdk
-
LLM inference is done using the llama.cpp-server python binding so installing python is required, install it by running the following command
sudo apt install python3
-
Data is persisted in the backend using a MySQL, in case you will be hosting the DB locally , install MySQL server on the local machine and start it as a service
sudo apt install mysql-server #check if the service is up sudo systemctl status mysql #if the service is down start it sudo systemctl start mysql
-
to avoid requiring owning a domain and DNS hosting, a trial cloudflare tunnel can be used to access the backend remotely . Install cloudflare daemon using the command
#Add Cloudflare's GPG key sudo mkdir -p --mode=0755 /usr/share/keyrings curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null #Add the official Cloudflare repository to your sources list echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflared.list #Update apt indexes and install cloudflared sudo apt-get update && sudo apt-get install cloudflared
-
clone the backend code
git clone https://github.com/Mourshid/backend.git
-
create in your mysql db (whether local or remote) a database to be used by the backend you can call it i
mourshid-db -
create in the root directory of the backend (same level as the src directory) a .env file with file as follows
DB_USER=<user name of your db> DB_PASSWORD=<pass word of your db> DB_URL=<url to local or remote db> JWT_SECRET=<64 char secret key for signing jwt> JWT_DURATION_MS=3600000 JWT_REFRESH_DURATION_MS = 604800000 GOAL_DECOMPOSER_URL = http://localhost:8000/v1/chat/completionsthe DB_URL will usually start with
jdbc:mysql:// -
Run the backend using
./mvnw spring-boot:run
-
Create a directory to store LLM related files, you can call it
llm -
Go to the
llmdirectory and create a python virtual environment, you can call it venvpython -m venv venv
-
Activate the virtual environment
source venv/bin/activate -
Install llama.cpp-server python binding using pip
pip install llama-cpp-python
-
download the fine-tuned and quantized model from this Hugging Face Repository
-
create a configuration file with the following content
{ "host": "localhost", "port": 8000, "models":[ { "model":"./v2/phi-4-tuned-v2-Q8_0.gguf", "n_threads":4, "n_threads_batch":4, "n_gpu_layers": -1, "verbose": true } ] }the
modelfield should be the path to the model downloaded in step 5 relative to where thellmdirectory created in step 1 is -
Run the inference server
python -m llama_cpp.server --config_file ./server_config.json
- to avoid needing to own a domain and to have DNS hosting cloudflare tunnel could be used as temporary experimental domains
to allow access to the server using the public internet. create a trial cloudflare tunnel and point it at the spring backend as follows
cloudflared tunnel --url http://localhost:8080