Templates
================
It is **highly** recommended to use the base templates to properly extract LLM output into the designated Python formats from these methods.
Below are some examples of the base prompt structure that should be used in this library with your customized prompt using the `PromptBuilder` class. More details of each methods' prompt structure is found in **l2p/templates**.
There are three main folders found in `/templates`:
.. raw:: html
templates/domain_templates
- /extract_nl_actions.txt: for `DomainBuilder.extract_nl_actions()`
- /formalize_domain_spec.txt: for `DomainBuilder.formalize_domain_specs()`
- /formalize_types.txt: for `DomainBuilder.formalize_types()
- /formalize_type_hierarchy.txt: for `DomainBuilder.formalize_type_hierarchy()
- /formalize_constants.txt: for `DomainBuilder.formalize_constants()
- /formalize_predicates.txt: for `DomainBuilder.formalize_predicates()
- /formalize_functions.txt: for `DomainBuilder.formalize_functions()
- /formalize_pddl_action.txt: for `DomainBuilder.formalize_pddl_action()
- /formalize_pddl_actions.txt: for `DomainBuilder.formalize_pddl_actions()
- /formalize_parameters.txt: for `DomainBuilder.formalize_parameters()
- /formalize_preconditions.txt: for `DomainBuilder.formalize_preconditions()
- /formalize_effects.txt: for `DomainBuilder.formalize_effects()
.. raw:: html
templates/task_templates
- /formalize_task.txt: for `TaskBuilder.formalize_task()
- /formalize_objects.txt: for `TaskBuilder.formalize_objects()
- /formalize_initial.txt: for `TaskBuilder.formalize_initial_state()
- /formalize_goal.txt: for `TaskBuilder.formalize_goal_state()
.. raw:: html
templates/feedback_templates
- /feedback.txt: base template needed for LLM to provide feedback in any functions in `FeedbackBuilder`
Domain Extraction Prompts Example
-------------------------------------------------------
This is an example using `l2p/templates/domain_templates/extract_pddl_action.txt`
.. code-block:: python
:linenos:
from l2p.prompt_builder import PromptBuilder
from l2p.utils import load_file
# LOAD BASE FORMAT TEMPLATE
template_path = "templates/domain_templates/formalize_pddl_action.txt"
format_template = load_file(template_path)
role_desc = "You are a PDDL action constructor. Your job is to take " \
"the task given in natural language and convert it into PDDL."
task_desc = """
## Domain
{domain_desc}
## Available types
{types}
## Future actions to be implemented later
{action_list}
## Action name (to implement now)
{action_name}
## Action description (corresponding action description)
{action_desc}
## Available predicates
{predicates}
"""
# assemble prompt
action_construction_prompt = PromptBuilder(
role=role_desc,
format=format_template,
task=task_desc
)
print(action_construction_prompt.generate_prompt())
The following is the output: ::
[ROLE]: You are a PDDL action constructor. Your job is to take the task given in natural language and convert it into PDDL.
------------------------------------------------
[FORMAT]: End your final answers underneath the headers: '### Action Parameters,' '### Action Preconditions,' '### Action Effects,' and '### New Predicates' with ``` ``` comment blocks in PDDL as so:
### Action Parameters
```
- ?t - type: 'parameter_description'
```
### Action Preconditions
```
(and
(predicate_name ?t1 ?t2) ; COMMENT DESCRIPTION
)
```
### Action Effects
```
(and
(predicate_name ?t1 ?t2) ; COMMENT DESCRIPTION
)
```
### New Predicates
```
- (predicate_name ?t1 - type_1 ?t2 - type_2): 'predicate_description'
```
If there are no new predicates created, keep an empty space enclosed ``` ``` with the '### New Predicates' header.
------------------------------------------------
[TASK]:
Here is the task to solve:
## Domain
{domain_desc}
## Available types
{types}
## Future actions to be implemented later
{action_list}
## Action name (to implement now)
{action_name}
## Action description (corresponding action description)
{action_desc}
## Available predicates
{predicates}
Users have the flexibility to customize all aspects of their prompts, with the exception of the provided base template. While users can include few-shot examples to guide the LLM, the base template must remain intact during inference.