anacostiaAI / anacostia-pipeline

Anacostia is a framework for creating machine learning operations (MLOps) pipelines
Apache License 2.0
1 stars 2 forks source link

Create templating library for Anacostia #24

Open mdo6180 opened 1 month ago

mdo6180 commented 1 month ago

Problem: one of Anacostia's core principles is to enable plugin developers to create their own frontends to display visualizations about their nodes. In order for Anacostia to do this, Anacostia distributes html templates to developers in the form of functions that render the html via string formatting (see the files in the components folder) rather than using a templating engine like Jinja2. This has several advantages:

  1. Easier to send templates to other developers. Developers do not have to mount another template directory in FastAPI and inherit the blueprint.
  2. Easier to provide an example of what the template looks like. By providing a example of the generated html snippet in the docstring, the docstring can then be displayed by the vs code hover window.
  3. Easier input validation. These functions can also serve as a way to ensure the developer provides the template with the correct information. We can help make sure the developer provides the right information through type hints in the function definition as well as by writing some custom logic for validation.
  4. Easier debugging. These functions are also easier to debug with a debugger because it is just python.

With all of that said, there are also several disadvantages:

  1. Cross site scripting. Because we are not using a templating engine, we don't have access to auto-escape. With that said, it should be noted that jinja does not automatically enable auto-escaping either. See this easy way to prevent XSS by using auto-escaping.
  2. No html syntax highlighting and autocomplete in vs code.

Proposed solutions:

  1. Create a custom decorator @anacostia_html. Users will use this decorator to declare their html rendering functions. The decorator will ensure all code is subjected to auto-escape. There should be an auto-escaping library we can leverage, but we still need to create the decorator.
  2. Build an LSP for vs code. The LSP recognizes the @anacostia_html decorator and provides html syntax highlighting and autocomplete for html elements in the decorated html rendering function.