l2p 0.1.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- l2p-0.1.7/LICENSE +21 -0
- l2p-0.1.7/PKG-INFO +234 -0
- l2p-0.1.7/README.md +206 -0
- l2p-0.1.7/l2p/__init__.py +6 -0
- l2p-0.1.7/l2p/domain_builder.py +763 -0
- l2p-0.1.7/l2p/feedback_builder.py +695 -0
- l2p-0.1.7/l2p/llm_builder.py +413 -0
- l2p-0.1.7/l2p/prompt_builder.py +107 -0
- l2p-0.1.7/l2p/task_builder.py +468 -0
- l2p-0.1.7/l2p/utils/__init__.py +4 -0
- l2p-0.1.7/l2p/utils/pddl_parser.py +462 -0
- l2p-0.1.7/l2p/utils/pddl_planner.py +161 -0
- l2p-0.1.7/l2p/utils/pddl_types.py +58 -0
- l2p-0.1.7/l2p/utils/pddl_validator.py +508 -0
- l2p-0.1.7/l2p/utils/utils.py +10 -0
- l2p-0.1.7/l2p.egg-info/PKG-INFO +234 -0
- l2p-0.1.7/l2p.egg-info/SOURCES.txt +22 -0
- l2p-0.1.7/l2p.egg-info/dependency_links.txt +1 -0
- l2p-0.1.7/l2p.egg-info/requires.txt +3 -0
- l2p-0.1.7/l2p.egg-info/top_level.txt +1 -0
- l2p-0.1.7/setup.cfg +4 -0
- l2p-0.1.7/setup.py +24 -0
- l2p-0.1.7/tests/test_domain_builder.py +142 -0
- l2p-0.1.7/tests/test_task_builder.py +44 -0
l2p-0.1.7/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Marcus Tantakoun
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
l2p-0.1.7/PKG-INFO
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: l2p
|
|
3
|
+
Version: 0.1.7
|
|
4
|
+
Summary: Library to connect LLMs and planning tasks
|
|
5
|
+
Home-page: https://github.com/AI-Planning/l2p
|
|
6
|
+
Author: Marcus Tantakoun, Christian Muise
|
|
7
|
+
Author-email: mtantakoun@gmail.com, christian.muise@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: retry
|
|
16
|
+
Requires-Dist: pddl
|
|
17
|
+
Requires-Dist: typing_extensions
|
|
18
|
+
Dynamic: author
|
|
19
|
+
Dynamic: author-email
|
|
20
|
+
Dynamic: classifier
|
|
21
|
+
Dynamic: description
|
|
22
|
+
Dynamic: description-content-type
|
|
23
|
+
Dynamic: home-page
|
|
24
|
+
Dynamic: license
|
|
25
|
+
Dynamic: requires-dist
|
|
26
|
+
Dynamic: requires-python
|
|
27
|
+
Dynamic: summary
|
|
28
|
+
|
|
29
|
+
# l2p : LLM-driven Planning Model library kit
|
|
30
|
+
|
|
31
|
+
This library is a collection of tools for PDDL model generation extracted from natural language driven by large language models. This library is an expansion from the survey paper **Leveraging Large Language Models for Automated Planning and Model Construction: A Survey** (coming soon)
|
|
32
|
+
|
|
33
|
+
L2P is an offline, natural language -to- planning model system that supports domain-agnostic planning. It does this via creating an intermediate [PDDL](https://planning.wiki/guide/whatis/pddl) representation of the domain and task, which can then be solved by a classical planner.
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
This is the general setup to build domain predicates:
|
|
38
|
+
```python
|
|
39
|
+
from l2p.llm_builder import OPENAI
|
|
40
|
+
from l2p.utils import load_file
|
|
41
|
+
from l2p.domain_builder import DomainBuilder
|
|
42
|
+
|
|
43
|
+
domain_builder = DomainBuilder()
|
|
44
|
+
|
|
45
|
+
api_key = os.environ.get('OPENAI_API_KEY')
|
|
46
|
+
llm = OPENAI(model="gpt-4o-mini", api_key=api_key)
|
|
47
|
+
|
|
48
|
+
# retrieve prompt information
|
|
49
|
+
base_path='tests/usage/prompts/domain/'
|
|
50
|
+
domain_desc = load_file(f'{base_path}blocksworld_domain.txt')
|
|
51
|
+
extract_predicates_prompt = load_file(f'{base_path}extract_predicates.txt')
|
|
52
|
+
types = load_file(f'{base_path}types.json')
|
|
53
|
+
action = load_file(f'{base_path}action.json')
|
|
54
|
+
|
|
55
|
+
# extract predicates via LLM
|
|
56
|
+
predicates, llm_output = domain_builder.extract_predicates(
|
|
57
|
+
model=llm,
|
|
58
|
+
domain_desc=domain_desc,
|
|
59
|
+
prompt_template=extract_predicates_prompt,
|
|
60
|
+
types=types,
|
|
61
|
+
nl_actions={action['action_name']: action['action_desc']}
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# format key info into PDDL strings
|
|
65
|
+
predicate_str = "\n".join([pred["clean"].replace(":", " ; ") for pred in predicates])
|
|
66
|
+
|
|
67
|
+
print(f"PDDL domain predicates:\n{predicate_str}")
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Here is how you would setup a PDDL problem:
|
|
71
|
+
```python
|
|
72
|
+
from l2p.task_builder import TaskBuilder
|
|
73
|
+
|
|
74
|
+
task_builder = TaskBuilder()
|
|
75
|
+
|
|
76
|
+
api_key = os.environ.get('OPENAI_API_KEY')
|
|
77
|
+
llm = OPENAI(model="gpt-4o-mini", api_key=api_key)
|
|
78
|
+
|
|
79
|
+
# load in assumptions
|
|
80
|
+
problem_desc = load_file(r'tests/usage/prompts/problem/blocksworld_problem.txt')
|
|
81
|
+
extract_task_prompt = load_file(r'tests/usage/prompts/problem/extract_task.txt')
|
|
82
|
+
types = load_file(r'tests/usage/prompts/domain/types.json')
|
|
83
|
+
predicates_json = load_file(r'tests/usage/prompts/domain/predicates.json')
|
|
84
|
+
predicates: List[Predicate] = [Predicate(**item) for item in predicates_json]
|
|
85
|
+
|
|
86
|
+
# extract PDDL task specifications via LLM
|
|
87
|
+
objects, initial_states, goal_states, llm_response = task_builder.extract_task(
|
|
88
|
+
model=llm,
|
|
89
|
+
problem_desc=problem_desc,
|
|
90
|
+
prompt_template=extract_task_prompt,
|
|
91
|
+
types=types,
|
|
92
|
+
predicates=predicates
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
# format key info into PDDL strings
|
|
96
|
+
objects_str = task_builder.format_objects(objects)
|
|
97
|
+
initial_str = task_builder.format_initial(initial_states)
|
|
98
|
+
goal_str = task_builder.format_goal(goal_states)
|
|
99
|
+
|
|
100
|
+
# generate task file
|
|
101
|
+
pddl_problem = task_builder.generate_task(
|
|
102
|
+
domain="blocksworld",
|
|
103
|
+
problem="blocksworld_problem",
|
|
104
|
+
objects=objects_str,
|
|
105
|
+
initial=initial_str,
|
|
106
|
+
goal=goal_str)
|
|
107
|
+
|
|
108
|
+
print(f"### LLM OUTPUT:\n {pddl_problem}")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Here is how you would setup a Feedback Mechanism:
|
|
112
|
+
```python
|
|
113
|
+
from l2p.feedback_builder import FeedbackBuilder
|
|
114
|
+
|
|
115
|
+
feedback_builder = FeedbackBuilder()
|
|
116
|
+
|
|
117
|
+
api_key = os.environ.get('OPENAI_API_KEY')
|
|
118
|
+
llm = OPENAI(model="gpt-4o-mini", api_key=api_key)
|
|
119
|
+
|
|
120
|
+
problem_desc = load_file(r'tests/usage/prompts/problem/blocksworld_problem.txt')
|
|
121
|
+
types = load_file(r'tests/usage/prompts/domain/types.json')
|
|
122
|
+
feedback_template = load_file(r'tests/usage/prompts/problem/feedback.txt')
|
|
123
|
+
predicates_json = load_file(r'tests/usage/prompts/domain/predicates.json')
|
|
124
|
+
predicates: List[Predicate] = [Predicate(**item) for item in predicates_json]
|
|
125
|
+
llm_response = load_file(r'tests/usage/prompts/domain/llm_output_task.txt')
|
|
126
|
+
|
|
127
|
+
objects, initial, goal, feedback_response = feedback_builder.task_feedback(
|
|
128
|
+
model=llm,
|
|
129
|
+
problem_desc=problem_desc,
|
|
130
|
+
feedback_template=feedback_template,
|
|
131
|
+
feedback_type="llm",
|
|
132
|
+
predicates=predicates,
|
|
133
|
+
types=types,
|
|
134
|
+
llm_response=llm_response)
|
|
135
|
+
|
|
136
|
+
print("FEEDBACK:\n", feedback_response)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
## Installation and Setup
|
|
141
|
+
Currently, this repo has been tested for Python 3.11.10 but should be fine to install newer versions.
|
|
142
|
+
|
|
143
|
+
You can set up a Python environment using either [Conda](https://conda.io) or [venv](https://docs.python.org/3/library/venv.html) and install the dependencies via the following steps.
|
|
144
|
+
|
|
145
|
+
**Conda**
|
|
146
|
+
```
|
|
147
|
+
conda create -n L2P python=3.11.10
|
|
148
|
+
conda activate L2P
|
|
149
|
+
pip install -r requirements.txt
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**venv**
|
|
153
|
+
```
|
|
154
|
+
python3.11.10 -m venv env
|
|
155
|
+
source env/bin/activate
|
|
156
|
+
pip install -r requirements.txt
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
These environments can then be exited with `conda deactivate` and `deactivate` respectively. The instructions below assume that a suitable environemnt is active.
|
|
160
|
+
|
|
161
|
+
**API keys**
|
|
162
|
+
L2P requires access to an LLM. L2P provides support for OpenAI's GPT-series models. To configure these, provide the necessary API-key in an environment variable.
|
|
163
|
+
|
|
164
|
+
**OpenAI**
|
|
165
|
+
```
|
|
166
|
+
export OPENAI_API_KEY='YOUR-KEY' # e.g. OPENAI_API_KEY='sk-123456'
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Refer to [here](https://platform.openai.com/docs/quickstart) for more information.
|
|
170
|
+
|
|
171
|
+
**HuggingFace**
|
|
172
|
+
|
|
173
|
+
Additionally, we have included support for using Huggingface models. One can set up their environment like so:
|
|
174
|
+
```
|
|
175
|
+
parser = argparse.ArgumentParser(description="Define Parameters")
|
|
176
|
+
parser.add_argument('-test_dataset', action='store_true')
|
|
177
|
+
parser.add_argument("--temp", type=float, default=0.01, help = "temperature for sampling")
|
|
178
|
+
parser.add_argument("--max_len", type=int, default=4e3, help = "max number of tokens in answer")
|
|
179
|
+
parser.add_argument("--num_sample", type=int, default=1, help = "number of answers to sample")
|
|
180
|
+
parser.add_argument("--model_path", type=str, default="/path/to/model", help = "path to llm")
|
|
181
|
+
args = parser.parse_args()
|
|
182
|
+
|
|
183
|
+
huggingface_model = HUGGING_FACE(model_path=args.model_path, max_tokens=args.max_len, temperature=args.temp)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**llm_builder.py** contains an abstract class and method for implementing any model classes in the case of other third-party LLM uses.
|
|
187
|
+
|
|
188
|
+
## Planner
|
|
189
|
+
For ease of use, our library contains submodule [FastDownward](https://github.com/aibasel/downward/tree/308812cf7315fe896dbcd319493277d82aa36bd2). Fast Downward is a domain-independent classical planning system that users can run their PDDL domain and problem files on. The motivation is that the majority of papers involving PDDL-LLM usage uses this library as their planner.
|
|
190
|
+
|
|
191
|
+
## Current Works Reconstructed Using L2P
|
|
192
|
+
The following are papers that have been reconstructed so far. This list will be updated in the future.
|
|
193
|
+
|
|
194
|
+
- [x] `NL2Plan`
|
|
195
|
+
- [x] `LLM+DM`
|
|
196
|
+
- [x] `LLM+P`
|
|
197
|
+
- [x] `PROC2PDDL`
|
|
198
|
+
|
|
199
|
+
## Current Model Construction Works
|
|
200
|
+
This section provides a taxonomy of research within Model Construction. **More detailed overview coming soon**.
|
|
201
|
+
|
|
202
|
+
**Model Generation**
|
|
203
|
+
|
|
204
|
+
***Task Translation Frameworks***
|
|
205
|
+
- **"Structured, flexible, and robust: benchmarking and improving large language models towards more human-like behaviour in out-of-distribution reasoning tasks"** Collins et al. (2022) [paper](https://arxiv.org/abs/2205.05718) [code](https://github.com/collinskatie/structured_flexible_and_robust)
|
|
206
|
+
- **"Translating natural language to planning goals with large-language models"** Xie et al. (2023) [paper](https://arxiv.org/abs/2302.05128) [code](https://github.com/clear-nus/gpt-pddl)
|
|
207
|
+
- **"Faithful Chain-of-Thought Reasoning"** Lyu et al. (2023) [paper](https://arxiv.org/abs/2301.13379) [code](https://github.com/veronica320/faithful-cot)
|
|
208
|
+
- **"LLM+P: Empowering Large Language Models with Optimal Planning Proficiency"** Liu et al. (2023) [paper](https://arxiv.org/abs/2304.11477) [code](https://github.com/Cranial-XIX/llm-pddl)
|
|
209
|
+
- **"Dynamic Planning with a LLM"** Dagan et al. (2023) [paper](https://arxiv.org/abs/2308.06391) [code](https://github.com/itl-ed/llm-dp)
|
|
210
|
+
- **"TIC: Translate-Infer-Compile for accurate 'text to plan' using LLMs and logical intermediate representations"** Agarwal and Sreepathy (2024) [paper](https://arxiv.org/abs/2402.06608) [code](N/A)
|
|
211
|
+
- **"PDDLEGO: Iterative Planning in Textual Environments"** Zhang et al. (2024) [paper](https://arxiv.org/abs/2405.19793) [code](https://github.com/zharry29/nl-to-pddl)
|
|
212
|
+
|
|
213
|
+
***Domain Translation Frameworks***
|
|
214
|
+
- **"Learning adaptive planning representations with natural language guidance"** Wong et al. (2023) [paper](https://arxiv.org/abs/2312.08566) [code](N/A)
|
|
215
|
+
- **"Leveraging Pre-trained Large Language Models to Construct and Utilize World Models for Model-based Task Planning"** Guan et al. (2023) [paper](https://arxiv.org/abs/2305.14909) [code](https://github.com/GuanSuns/LLMs-World-Models-for-Planning)
|
|
216
|
+
- **"PROC2PDDL: Open-Domain Planning Representations from Texts"** Zhang et al. (2024) [paper](https://arxiv.org/abs/2403.00092) [code](https://github.com/zharry29/proc2pddl)
|
|
217
|
+
|
|
218
|
+
***Hybrid Translation Frameworks***
|
|
219
|
+
- **"There and Back Again: Extracting Formal Domains for Controllable Neurosymbolic Story Authoring"** Kelly et al. (2023) [paper](https://ojs.aaai.org/index.php/AIIDE/article/view/27502/27275) [code](https://github.com/alex-calderwood/there-and-back)
|
|
220
|
+
- **"DELTA: Decomposed Efficient Long-Term Robot Task Planning using Large Language Models"** Liu et al. (2024) [paper](https://arxiv.org/abs/2404.03275) [code](N/A)
|
|
221
|
+
- **"ISR-LLM: Iterative Self-Refined Large Language Model for Long-Horizon Sequential Task Planning"** Zhou et al. (2023) [paper](https://arxiv.org/abs/2308.13724) [code](https://github.com/ma-labo/ISR-LLM)
|
|
222
|
+
- **"Consolidating Trees of Robotic Plans Generated Using Large Language Models to Improve Reliability"** Sakib and Sun (2024) [paper](https://arxiv.org/abs/2401.07868) [code](N/A)
|
|
223
|
+
- **"NL2Plan: Robust LLM-Driven Planning from Minimal Text Descriptions"** Gestrin et al. (2024) [paper](https://arxiv.org/abs/2405.04215) [code](https://github.com/mrlab-ai/NL2Plan)
|
|
224
|
+
- **"Leveraging Environment Interaction for Automated PDDL Generation and Planning with Large Language Models"** Mahdavi et al. (2024) [paper](https://arxiv.org/abs/2407.12979) [code]()
|
|
225
|
+
- **"Generating consistent PDDL domains with Large Language Models"** Smirnov et al. (2024) [paper](https://arxiv.org/abs/2404.07751) [code](N/A)
|
|
226
|
+
|
|
227
|
+
**Model Editing and Benchmarking**
|
|
228
|
+
- **"Exploring the limitations of using large language models to fix planning tasks"** Gragera and Pozanco (2023) [paper](https://icaps23.icaps-conference.org/program/workshops/keps/KEPS-23_paper_3645.pdf) [code](N/A)
|
|
229
|
+
- **"Can LLMs Fix Issues with Reasoning Models? Towards More Likely Models for AI Planning"** Caglar et al. (2024) [paper](https://arxiv.org/abs/2311.13720) [code](N/A)
|
|
230
|
+
- **"Large Language Models as Planning Domain Generators"** Oswald et al. (2024) [paper](https://arxiv.org/abs/2405.06650) [code](https://github.com/IBM/NL2PDDL)
|
|
231
|
+
- **"Planetarium: A Rigorous Benchmark for Translating Text to Structured Planning Languages"** Zuo et al. (2024) [paper](https://arxiv.org/abs/2407.03321) [code](https://github.com/batsresearch/planetarium)
|
|
232
|
+
|
|
233
|
+
## Contact
|
|
234
|
+
Please contact `20mt1@queensu.ca` for questions, comments, or feedback about the L2P library.
|
l2p-0.1.7/README.md
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# l2p : LLM-driven Planning Model library kit
|
|
2
|
+
|
|
3
|
+
This library is a collection of tools for PDDL model generation extracted from natural language driven by large language models. This library is an expansion from the survey paper **Leveraging Large Language Models for Automated Planning and Model Construction: A Survey** (coming soon)
|
|
4
|
+
|
|
5
|
+
L2P is an offline, natural language -to- planning model system that supports domain-agnostic planning. It does this via creating an intermediate [PDDL](https://planning.wiki/guide/whatis/pddl) representation of the domain and task, which can then be solved by a classical planner.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
This is the general setup to build domain predicates:
|
|
10
|
+
```python
|
|
11
|
+
from l2p.llm_builder import OPENAI
|
|
12
|
+
from l2p.utils import load_file
|
|
13
|
+
from l2p.domain_builder import DomainBuilder
|
|
14
|
+
|
|
15
|
+
domain_builder = DomainBuilder()
|
|
16
|
+
|
|
17
|
+
api_key = os.environ.get('OPENAI_API_KEY')
|
|
18
|
+
llm = OPENAI(model="gpt-4o-mini", api_key=api_key)
|
|
19
|
+
|
|
20
|
+
# retrieve prompt information
|
|
21
|
+
base_path='tests/usage/prompts/domain/'
|
|
22
|
+
domain_desc = load_file(f'{base_path}blocksworld_domain.txt')
|
|
23
|
+
extract_predicates_prompt = load_file(f'{base_path}extract_predicates.txt')
|
|
24
|
+
types = load_file(f'{base_path}types.json')
|
|
25
|
+
action = load_file(f'{base_path}action.json')
|
|
26
|
+
|
|
27
|
+
# extract predicates via LLM
|
|
28
|
+
predicates, llm_output = domain_builder.extract_predicates(
|
|
29
|
+
model=llm,
|
|
30
|
+
domain_desc=domain_desc,
|
|
31
|
+
prompt_template=extract_predicates_prompt,
|
|
32
|
+
types=types,
|
|
33
|
+
nl_actions={action['action_name']: action['action_desc']}
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# format key info into PDDL strings
|
|
37
|
+
predicate_str = "\n".join([pred["clean"].replace(":", " ; ") for pred in predicates])
|
|
38
|
+
|
|
39
|
+
print(f"PDDL domain predicates:\n{predicate_str}")
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Here is how you would setup a PDDL problem:
|
|
43
|
+
```python
|
|
44
|
+
from l2p.task_builder import TaskBuilder
|
|
45
|
+
|
|
46
|
+
task_builder = TaskBuilder()
|
|
47
|
+
|
|
48
|
+
api_key = os.environ.get('OPENAI_API_KEY')
|
|
49
|
+
llm = OPENAI(model="gpt-4o-mini", api_key=api_key)
|
|
50
|
+
|
|
51
|
+
# load in assumptions
|
|
52
|
+
problem_desc = load_file(r'tests/usage/prompts/problem/blocksworld_problem.txt')
|
|
53
|
+
extract_task_prompt = load_file(r'tests/usage/prompts/problem/extract_task.txt')
|
|
54
|
+
types = load_file(r'tests/usage/prompts/domain/types.json')
|
|
55
|
+
predicates_json = load_file(r'tests/usage/prompts/domain/predicates.json')
|
|
56
|
+
predicates: List[Predicate] = [Predicate(**item) for item in predicates_json]
|
|
57
|
+
|
|
58
|
+
# extract PDDL task specifications via LLM
|
|
59
|
+
objects, initial_states, goal_states, llm_response = task_builder.extract_task(
|
|
60
|
+
model=llm,
|
|
61
|
+
problem_desc=problem_desc,
|
|
62
|
+
prompt_template=extract_task_prompt,
|
|
63
|
+
types=types,
|
|
64
|
+
predicates=predicates
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
# format key info into PDDL strings
|
|
68
|
+
objects_str = task_builder.format_objects(objects)
|
|
69
|
+
initial_str = task_builder.format_initial(initial_states)
|
|
70
|
+
goal_str = task_builder.format_goal(goal_states)
|
|
71
|
+
|
|
72
|
+
# generate task file
|
|
73
|
+
pddl_problem = task_builder.generate_task(
|
|
74
|
+
domain="blocksworld",
|
|
75
|
+
problem="blocksworld_problem",
|
|
76
|
+
objects=objects_str,
|
|
77
|
+
initial=initial_str,
|
|
78
|
+
goal=goal_str)
|
|
79
|
+
|
|
80
|
+
print(f"### LLM OUTPUT:\n {pddl_problem}")
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Here is how you would setup a Feedback Mechanism:
|
|
84
|
+
```python
|
|
85
|
+
from l2p.feedback_builder import FeedbackBuilder
|
|
86
|
+
|
|
87
|
+
feedback_builder = FeedbackBuilder()
|
|
88
|
+
|
|
89
|
+
api_key = os.environ.get('OPENAI_API_KEY')
|
|
90
|
+
llm = OPENAI(model="gpt-4o-mini", api_key=api_key)
|
|
91
|
+
|
|
92
|
+
problem_desc = load_file(r'tests/usage/prompts/problem/blocksworld_problem.txt')
|
|
93
|
+
types = load_file(r'tests/usage/prompts/domain/types.json')
|
|
94
|
+
feedback_template = load_file(r'tests/usage/prompts/problem/feedback.txt')
|
|
95
|
+
predicates_json = load_file(r'tests/usage/prompts/domain/predicates.json')
|
|
96
|
+
predicates: List[Predicate] = [Predicate(**item) for item in predicates_json]
|
|
97
|
+
llm_response = load_file(r'tests/usage/prompts/domain/llm_output_task.txt')
|
|
98
|
+
|
|
99
|
+
objects, initial, goal, feedback_response = feedback_builder.task_feedback(
|
|
100
|
+
model=llm,
|
|
101
|
+
problem_desc=problem_desc,
|
|
102
|
+
feedback_template=feedback_template,
|
|
103
|
+
feedback_type="llm",
|
|
104
|
+
predicates=predicates,
|
|
105
|
+
types=types,
|
|
106
|
+
llm_response=llm_response)
|
|
107
|
+
|
|
108
|
+
print("FEEDBACK:\n", feedback_response)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
## Installation and Setup
|
|
113
|
+
Currently, this repo has been tested for Python 3.11.10 but should be fine to install newer versions.
|
|
114
|
+
|
|
115
|
+
You can set up a Python environment using either [Conda](https://conda.io) or [venv](https://docs.python.org/3/library/venv.html) and install the dependencies via the following steps.
|
|
116
|
+
|
|
117
|
+
**Conda**
|
|
118
|
+
```
|
|
119
|
+
conda create -n L2P python=3.11.10
|
|
120
|
+
conda activate L2P
|
|
121
|
+
pip install -r requirements.txt
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**venv**
|
|
125
|
+
```
|
|
126
|
+
python3.11.10 -m venv env
|
|
127
|
+
source env/bin/activate
|
|
128
|
+
pip install -r requirements.txt
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
These environments can then be exited with `conda deactivate` and `deactivate` respectively. The instructions below assume that a suitable environemnt is active.
|
|
132
|
+
|
|
133
|
+
**API keys**
|
|
134
|
+
L2P requires access to an LLM. L2P provides support for OpenAI's GPT-series models. To configure these, provide the necessary API-key in an environment variable.
|
|
135
|
+
|
|
136
|
+
**OpenAI**
|
|
137
|
+
```
|
|
138
|
+
export OPENAI_API_KEY='YOUR-KEY' # e.g. OPENAI_API_KEY='sk-123456'
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Refer to [here](https://platform.openai.com/docs/quickstart) for more information.
|
|
142
|
+
|
|
143
|
+
**HuggingFace**
|
|
144
|
+
|
|
145
|
+
Additionally, we have included support for using Huggingface models. One can set up their environment like so:
|
|
146
|
+
```
|
|
147
|
+
parser = argparse.ArgumentParser(description="Define Parameters")
|
|
148
|
+
parser.add_argument('-test_dataset', action='store_true')
|
|
149
|
+
parser.add_argument("--temp", type=float, default=0.01, help = "temperature for sampling")
|
|
150
|
+
parser.add_argument("--max_len", type=int, default=4e3, help = "max number of tokens in answer")
|
|
151
|
+
parser.add_argument("--num_sample", type=int, default=1, help = "number of answers to sample")
|
|
152
|
+
parser.add_argument("--model_path", type=str, default="/path/to/model", help = "path to llm")
|
|
153
|
+
args = parser.parse_args()
|
|
154
|
+
|
|
155
|
+
huggingface_model = HUGGING_FACE(model_path=args.model_path, max_tokens=args.max_len, temperature=args.temp)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**llm_builder.py** contains an abstract class and method for implementing any model classes in the case of other third-party LLM uses.
|
|
159
|
+
|
|
160
|
+
## Planner
|
|
161
|
+
For ease of use, our library contains submodule [FastDownward](https://github.com/aibasel/downward/tree/308812cf7315fe896dbcd319493277d82aa36bd2). Fast Downward is a domain-independent classical planning system that users can run their PDDL domain and problem files on. The motivation is that the majority of papers involving PDDL-LLM usage uses this library as their planner.
|
|
162
|
+
|
|
163
|
+
## Current Works Reconstructed Using L2P
|
|
164
|
+
The following are papers that have been reconstructed so far. This list will be updated in the future.
|
|
165
|
+
|
|
166
|
+
- [x] `NL2Plan`
|
|
167
|
+
- [x] `LLM+DM`
|
|
168
|
+
- [x] `LLM+P`
|
|
169
|
+
- [x] `PROC2PDDL`
|
|
170
|
+
|
|
171
|
+
## Current Model Construction Works
|
|
172
|
+
This section provides a taxonomy of research within Model Construction. **More detailed overview coming soon**.
|
|
173
|
+
|
|
174
|
+
**Model Generation**
|
|
175
|
+
|
|
176
|
+
***Task Translation Frameworks***
|
|
177
|
+
- **"Structured, flexible, and robust: benchmarking and improving large language models towards more human-like behaviour in out-of-distribution reasoning tasks"** Collins et al. (2022) [paper](https://arxiv.org/abs/2205.05718) [code](https://github.com/collinskatie/structured_flexible_and_robust)
|
|
178
|
+
- **"Translating natural language to planning goals with large-language models"** Xie et al. (2023) [paper](https://arxiv.org/abs/2302.05128) [code](https://github.com/clear-nus/gpt-pddl)
|
|
179
|
+
- **"Faithful Chain-of-Thought Reasoning"** Lyu et al. (2023) [paper](https://arxiv.org/abs/2301.13379) [code](https://github.com/veronica320/faithful-cot)
|
|
180
|
+
- **"LLM+P: Empowering Large Language Models with Optimal Planning Proficiency"** Liu et al. (2023) [paper](https://arxiv.org/abs/2304.11477) [code](https://github.com/Cranial-XIX/llm-pddl)
|
|
181
|
+
- **"Dynamic Planning with a LLM"** Dagan et al. (2023) [paper](https://arxiv.org/abs/2308.06391) [code](https://github.com/itl-ed/llm-dp)
|
|
182
|
+
- **"TIC: Translate-Infer-Compile for accurate 'text to plan' using LLMs and logical intermediate representations"** Agarwal and Sreepathy (2024) [paper](https://arxiv.org/abs/2402.06608) [code](N/A)
|
|
183
|
+
- **"PDDLEGO: Iterative Planning in Textual Environments"** Zhang et al. (2024) [paper](https://arxiv.org/abs/2405.19793) [code](https://github.com/zharry29/nl-to-pddl)
|
|
184
|
+
|
|
185
|
+
***Domain Translation Frameworks***
|
|
186
|
+
- **"Learning adaptive planning representations with natural language guidance"** Wong et al. (2023) [paper](https://arxiv.org/abs/2312.08566) [code](N/A)
|
|
187
|
+
- **"Leveraging Pre-trained Large Language Models to Construct and Utilize World Models for Model-based Task Planning"** Guan et al. (2023) [paper](https://arxiv.org/abs/2305.14909) [code](https://github.com/GuanSuns/LLMs-World-Models-for-Planning)
|
|
188
|
+
- **"PROC2PDDL: Open-Domain Planning Representations from Texts"** Zhang et al. (2024) [paper](https://arxiv.org/abs/2403.00092) [code](https://github.com/zharry29/proc2pddl)
|
|
189
|
+
|
|
190
|
+
***Hybrid Translation Frameworks***
|
|
191
|
+
- **"There and Back Again: Extracting Formal Domains for Controllable Neurosymbolic Story Authoring"** Kelly et al. (2023) [paper](https://ojs.aaai.org/index.php/AIIDE/article/view/27502/27275) [code](https://github.com/alex-calderwood/there-and-back)
|
|
192
|
+
- **"DELTA: Decomposed Efficient Long-Term Robot Task Planning using Large Language Models"** Liu et al. (2024) [paper](https://arxiv.org/abs/2404.03275) [code](N/A)
|
|
193
|
+
- **"ISR-LLM: Iterative Self-Refined Large Language Model for Long-Horizon Sequential Task Planning"** Zhou et al. (2023) [paper](https://arxiv.org/abs/2308.13724) [code](https://github.com/ma-labo/ISR-LLM)
|
|
194
|
+
- **"Consolidating Trees of Robotic Plans Generated Using Large Language Models to Improve Reliability"** Sakib and Sun (2024) [paper](https://arxiv.org/abs/2401.07868) [code](N/A)
|
|
195
|
+
- **"NL2Plan: Robust LLM-Driven Planning from Minimal Text Descriptions"** Gestrin et al. (2024) [paper](https://arxiv.org/abs/2405.04215) [code](https://github.com/mrlab-ai/NL2Plan)
|
|
196
|
+
- **"Leveraging Environment Interaction for Automated PDDL Generation and Planning with Large Language Models"** Mahdavi et al. (2024) [paper](https://arxiv.org/abs/2407.12979) [code]()
|
|
197
|
+
- **"Generating consistent PDDL domains with Large Language Models"** Smirnov et al. (2024) [paper](https://arxiv.org/abs/2404.07751) [code](N/A)
|
|
198
|
+
|
|
199
|
+
**Model Editing and Benchmarking**
|
|
200
|
+
- **"Exploring the limitations of using large language models to fix planning tasks"** Gragera and Pozanco (2023) [paper](https://icaps23.icaps-conference.org/program/workshops/keps/KEPS-23_paper_3645.pdf) [code](N/A)
|
|
201
|
+
- **"Can LLMs Fix Issues with Reasoning Models? Towards More Likely Models for AI Planning"** Caglar et al. (2024) [paper](https://arxiv.org/abs/2311.13720) [code](N/A)
|
|
202
|
+
- **"Large Language Models as Planning Domain Generators"** Oswald et al. (2024) [paper](https://arxiv.org/abs/2405.06650) [code](https://github.com/IBM/NL2PDDL)
|
|
203
|
+
- **"Planetarium: A Rigorous Benchmark for Translating Text to Structured Planning Languages"** Zuo et al. (2024) [paper](https://arxiv.org/abs/2407.03321) [code](https://github.com/batsresearch/planetarium)
|
|
204
|
+
|
|
205
|
+
## Contact
|
|
206
|
+
Please contact `20mt1@queensu.ca` for questions, comments, or feedback about the L2P library.
|