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:
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()
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()
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
1from l2p.prompt_builder import PromptBuilder
2from l2p.utils import load_file
3
4# LOAD BASE FORMAT TEMPLATE
5template_path = "templates/domain_templates/formalize_pddl_action.txt"
6format_template = load_file(template_path)
7
8role_desc = "You are a PDDL action constructor. Your job is to take " \
9 "the task given in natural language and convert it into PDDL."
10
11task_desc = """
12## Domain
13{domain_desc}
14
15## Available types
16{types}
17
18## Future actions to be implemented later
19{action_list}
20
21## Action name (to implement now)
22{action_name}
23
24## Action description (corresponding action description)
25{action_desc}
26
27## Available predicates
28{predicates}
29"""
30
31# assemble prompt
32action_construction_prompt = PromptBuilder(
33 role=role_desc,
34 format=format_template,
35 task=task_desc
36 )
37
38print(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.