|
Cookies Manager Backend
|
API service used to generate rules for Consent-O-Matic chrome extension
Start the server with hot reloading:
Lint your code by running:
Run all tests:
Add additional tests in tests directory. The test file should follow such format: test_*.pywhere * would be substituted with the name of the test.
To view all API endpoints, visit http://localhost:8000/docs
The rulegen/generator.py module is responsible for the actual extraction of the rules from provided HTML. It utilizes models from rulegen/models.py and integrates with OpenAI's GPT-3.5 for dynamic rule creation. Below are its main functionalities:
instructor library to patch an OpenAI client for interfacing with GPT-3.5.save_model_as_json: Saves the generated model in JSON format.extract_model: Extracts the model based on a system task and user content, and generates responses using the specified response model.get_selector: Retrieves CSS selectors based on content, useful for identifying specific elements in a web application.The rulegen/models.py file contains several Pydantic modeled after consent-o-matic rule definitions. These models define the structure for various elements like style filters, DOM selections, matchers, actions, detectors, methods, and the main CMP (Consent Management Platform) rules. Below is a brief overview of each model:
Defines CSS style property filters. Includes fields for the CSS property option, value, and a negation flag.
Represents a DOM selection with various filters like CSS selector, text filter, style filter, display filter, iframe filter, and child filter.
Define matchers for CSS and checkbox elements in the DOM. These are used to identify specific elements on a web page.
Represent actions that can be performed on DOM elements. ClickAction is a specific type of action for simulating mouse clicks.
A union of CssMatcher and CheckboxMatcher, used for defining present and showing matchers in the Detector model.
Used to define detection criteria for the Consent Management Platform, including present and showing matchers.
Defines methods with optional actions and names. The NAME literal defines specific method names like OPEN_OPTIONS, DO_CONSENT, etc.
Consent Management Platform model that combines detectors and methods for rule definition.
The main model encapsulating the CMP rules and schema information for the Cookie Popup Manager.
These models are central to the operation of the Cookie Popup Manager, providing a structured approach to defining and managing consent rules.