TemplateFormatter
.
In most cases, you will want to create templates when adding a new component to the standard library or when customizing an existing component for a new model.
TemplateFormatter
uses jinja2 templates to format objects when passing them to models for generation.
These templates can be stored directly in the class/object, or, more typically, the templates are stored in a directory, with each object having a specific file. For examples of the templates, see mellea/templates/prompts/default
.
See the customization section below for a description of how the formatter chooses which template to use.
format_for_llm()
function. It returns either a string or a TemplateRepresentation
.
string
: the simplest approach is for this method to return a string representation of the object. This avoids templating altogether.
TemplateRepresentation
: It can also return a TemplateRepresentation
object.
This representation contains: - a reference to the component - a dictionary of arguments that will be passed to the template renderer - a list of tools/functions that relate to the component
It also contains either of the following fields
*
denotes the class name.template_order
field, the default TemplateFormatter grabs the relevant template by looking at the following places in order for each template in the template_order
:
.../templates/prompts/...
directoryibm-granite/granite-3.2-8b-instruct
will match .../templates/prompts/granite/granite-3-2/instruct
) or default (ie .../templates/prompts/default
)templates
directory with both prompts/granite/...
and prompts/ibm/...
for ibm-granite/granite-3.2-8b-instruct
should not happenmellea/docs/examples/mify/rich_document_advanced.py