This project focuses on the automated generation of formal event-based XML properties from natural language descriptions using Large Language Models (LLMs). It also provides a web-based interface, database storage, and integration with monitoring tools for deploying generated properties.
The system supports:
- Property generation from user input (chat interface)
- Property generation ffrom incoming remote events (MISP-like format)
- Validation and iterative refinement of XML properties
- Storage of properties in a PostgreSQL database
- Deployment of properties to a monitoring tool (e.g., MMT-Security)
This project is organized into the following directories and files:
project-root/
├── 5G_prompts/ # Generated prompts for 5G scenarios
├── 5G_results/ # Experimental results per model/scenario
├── 5G_stats/ # Aggregated statistics
├── 5G_tasks/ # Scenario descriptions (5G network scenarios)
│
├── backend/ # FastAPI backend (web + APIs)
│ ├── main.py # API entry point
│ ├── models.py # Request/response models
│ └── requirements # Backend dependencies
│
├── chat-ui/ # React frontend
│
├── src/ # Core logic (LLM + processing)
│ ├── data/
│ └── mmt-property-context.txt
│ ├── experiments.py
│ ├── generate_prompt.py
│ ├── generator.py
│ ├── llm_interaction.py
│ ├── retrieve_data.py
│ ├── save_property.py
│ ├── stats.py
│ ├── syntax_validation.py
│ └── utils.py
│
├── notebooks/
│ └── generate_property.ipynb
└── .env # (Not tracked) Environment variables for DB config
This project requires a PostgreSQL database with two tables: mmt_properties and protocols. Follow the steps below to set up your database environment.
- PostgreSQL installed on your system.
- Database creation privileges.
- Node v20.19.2 (for frontend)
- Create a new PostgreSQL database for the project:
CREATE DATABASE <your_database_name>;- Connect to the newly created database using
psql:
psql -d <your_database_name>Or, if you're already inside psql:
\c <your_database_name>- Create the required tables by executing the following SQL statements:
-- Create mmt_properties table
CREATE TABLE mmt_properties(
id SERIAL PRIMARY KEY,
description text,
protocol text,
xml_content text NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
name text UNIQUE
);
-- Create protocols table
CREATE TABLE protocols(
id SERIAL PRIMARY KEY,
name text NOT NULL UNIQUE,
attributes jsonb NOT NULL
);mmt_properties: Stores formally defined properties used for monitoring.
| Column | Type | Description |
|---|---|---|
id |
SERIAL | Auto-generated primary key. |
description |
TEXT | A description of the scenario represented by the XML (e.g., what the property is monitoring). |
protocol |
TEXT | Names of the protocols associated with the property, separated by commas (e.g., ocpp, mqtt). |
xml_content |
TEXT | The XML content defining the formal property. |
created_at |
TIMESTAMP | Automatically set when the property is added. |
name |
TEXT | The filename (or unique name) representing the property. Must be unique. |
protocols: Stores protocol names and their attribute definitions as used by MMT.
| Column | Type | Description |
|---|---|---|
id |
SERIAL | Auto-generated primary key. |
name |
TEXT | The name of the protocol (e.g., ocpp). Must be unique. |
attributes |
JSONB | A JSON object describing the protocol’s attributes and their meanings/types. |
To connect to the PostgreSQL database, create a .env file in the root directory of the project with the following variables:
DB_NAME=your_database_name
DB_USER=your_username
DB_PASSWORD=your_password
DB_HOST=localhost
DB_PORT=5432This project uses a local Large Language Model (LLM) served by Ollama to process and reason about scenario property generation.
- Ollama installed and running on your machine.
- A supported model pulled (e.g.,
mistral,llama2, etc).
- A scenario is provided (via notebook, API, or remote event)
retrieve_data.pyfetches protocol definitions, example propertiesgenerate_prompt.pybuilds a few-shot promptllm_interaction.pysends prompt to LLM, extracts XML, and validates syntax- Iteration continues until a valid property is generated or max attempts is reached
- Results can be returned to the user, stored in DB, or sent to monitoring tool.
It features:
- Chat-based property generation
- Editable XML properties
- Validation feedback for invalid properties
- Save properties to database
- Send properties to monitoring tools
- Automatic handling for incoming remote events
- Background processing for event-driven generation
Make sure your PostgreSQL and .env file are properly configured, the use of a virtul environment is recommended:
cd backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
#Run FastAPI ap using the virtualenv uvicorn
venv/bin/uvicorn main:app --reloadThe API will be available at http://localhost:8000 and you can access the API documentation at http://localhost:8000/docs.
To change the LLM model that the backend is using, modify src/generator.py
cd chat-ui
npm install
npm run devThe frontend should be available at http://localhost:5173 and will communicate with the backend for property generation and storage.
The backend exposes
POST /send-to-monitoring
This sends XML properties to an external monitoring receiver. Response includes status, receiver response, error details (if any)
The system supports ingestion of external events (MISP-like format):
POST /receive-event
5G_tasks/: scenario descriptions5G_prompts/: generated outputs5G_results/: model outputs5G_stats/: aggregated metrics
- Set up your PostgreSQL database and
.envfile (see above). - Intall Ollama and pull a model
- Run backend
- Run frontend
- Open UI and start generating properties
Optional:
- Use notebook for experiments
- Send remote events to trigger automatic generation
