[Python] Bundling Jinja2 temlate with UV

Discussão em 'Python' iniciado por Stack, Fevereiro 1, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to include jinja2 templates within my uv build but it does not seem to work. My directory structure is as follows.

    project/
    ├── src/
    │ ├── mypackage/
    │ └──── j2/ (all templates live here)

    └── pyproject.toml


    Following is my py project toml

    [project]
    name = "dojipipeline"
    version = "0.1.0"
    description = "Add your description here"
    readme = "README.md"
    requires-python = ">=3.12"
    dependencies = [
    "groq>=0.16.0",
    "jinja2>=3.1.5",
    "pydantic>=2.10.6",
    "python-dotenv>=1.0.1",
    "pyyaml>=6.0.2",
    ]


    My work around is to capture all the j2 as doc_string in .py file like below and import it

    #j2_template.py
    GENERATE_DATA_MODEL = """
    You are a data governance expert and are tasked to perform the following
    { % for task in tasks % }
    {{ task }}
    { % endfor % }
    ===========================
    {% if contexts %}
    Following are the contexts for the tasks:
    {% for context in contexts %}
    {{ context }}
    {% endfor %}
    {% endif %}

    The required responses must be in JSON format.
    "response": {
    "data": {{ data_shema }}
    "thoughts": List of thoughts
    }

    Generate a valid data object and explain your thought process.
    Answer only with json and do not include any other information.
    """

    Continue reading...

Compartilhe esta Página