Skip to content

Commit

Permalink
Merge pull request #7 from MarcusTantakoun/bugfix/dependencies
Browse files Browse the repository at this point in the history
Clean up of code
  • Loading branch information
haz authored Dec 24, 2024
2 parents 91c3222 + 86ec622 commit 49085f2
Show file tree
Hide file tree
Showing 77 changed files with 2,985 additions and 1,843 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ cython_debug/

# directories to ignore
tests/main.py
tests/parse.py
data/
tests/tests.py

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ print("FEEDBACK:\n", feedback_response)


## Installation and Setup
Currently, this repo has been tested for Python 3.11.10
Currently, this repo has been tested for Python 3.11.10 but should be fine to install newer versions.

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.

Expand Down
47 changes: 25 additions & 22 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,34 @@

import os
import sys
sys.path.insert(0, os.path.abspath('..'))

project = 'L2P'
copyright = '2024, Marcus Tantakoun'
author = 'Marcus Tantakoun'
release = '0.1.0'
sys.path.insert(0, os.path.abspath(".."))

project = "L2P"
copyright = "2024, Marcus Tantakoun"
author = "Marcus Tantakoun"
release = "0.1.0"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = ['sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages',
'sphinx.ext.napoleon',
'myst_parser']
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx.ext.coverage",
"sphinx.ext.mathjax",
"sphinx.ext.ifconfig",
"sphinx.ext.viewcode",
"sphinx.ext.githubpages",
"sphinx.ext.napoleon",
"myst_parser",
"sphinx_copybutton",
]

myst_enable_extensions = [
'colon_fence', # Enables Markdown for code block with language
"colon_fence", # Enables Markdown for code block with language
]

# Napoleon settings
Expand All @@ -47,14 +51,13 @@
napoleon_use_param = True
napoleon_use_rtype = True

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'furo'
html_theme = "furo"
html_title = "l2p"
html_static_path = ['_static']
html_static_path = ["_static"]
8 changes: 5 additions & 3 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ Installing
----------
L2P can be installed with pip::

pip install l2p
pip install lang2pddl

**NOT** `pip install l2p`

Using L2P
-------------

First things first, import the L2P library::
First things first, import the whole L2P library, or necessary modules (see :doc:`l2p`)::

from l2p import *

Expand Down Expand Up @@ -73,7 +75,7 @@ Build LLM feedback components using the ``FeedbackBuilder`` class. This is an ex
feedback_type = "llm"
)

Below are actual usage examples. This is the general setup to build domain predicates:
Below are actual runnable usage examples. This is the general setup to build domain predicates:

.. code-block:: python
:linenos:
Expand Down
10 changes: 7 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ Welcome to Language-to-Plan (L2P)!

.. toctree::
:maxdepth: 2
:titlesonly:
:caption: Contents:

getting_started
l2p
paper_recreations
templates
types

What is L2P?
------------
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** which can be found `Here <https://puginarug.com>`_ (currently under review process).
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** (currently under review process).
L2P is an offline, NL to PDDL system that supports domain-agnostic planning. It does this via creating an intermediate PDDL representation of the domain and task, which can then be solved by a classical planner.

Our GitHub can be found `here <https://github.com/MarcusTantakoun/L2P-Library-Kit>`_.
Our GitHub can be found `here <https://github.com/AI-Planning/l2p>`_. L2P PyPI can be found `here <https://pypi.org/project/lang2pddl/>`_.

Features
--------
Expand All @@ -28,7 +30,9 @@ Installation

Install ``l2p`` by running::

pip install l2p
pip install lang2pddl

**NOT** `pip install l2p`

Usage
-----
Expand Down
38 changes: 35 additions & 3 deletions docs/l2p.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ L2P
================
Below are the in-depth usage of L2P. It is **highly** recommended to use the base template found in :doc:`templates` to properly extract LLM output into the designated Python formats from these methods.

PromptBuilder
-------------
.. autoclass:: l2p.PromptBuilder
:members:
:undoc-members:
:inherited-members:

DomainBuilder
-------------
.. autoclass:: l2p.DomainBuilder
Expand All @@ -23,9 +30,34 @@ FeedbackBuilder
:undoc-members:
:inherited-members:

PromptBuilder
-------------
.. autoclass:: l2p.PromptBuilder
Utils
-----
The `utils` package contains several helper modules for working with PDDL and L2P processes.

PDDL Parser
~~~~~~~~~~~
.. automodule:: l2p.utils.pddl_parser
:members:
:undoc-members:
:inherited-members:

PDDL Planner
~~~~~~~~~~~~
.. automodule:: l2p.utils.pddl_planner
:members:
:undoc-members:
:inherited-members:

PDDL Types
~~~~~~~~~~
.. automodule:: l2p.utils.pddl_types
:members:
:undoc-members:
:inherited-members:

PDDL Validator
~~~~~~~~~~~~~~
.. automodule:: l2p.utils.pddl_validator
:members:
:undoc-members:
:inherited-members:
2 changes: 1 addition & 1 deletion docs/paper_recreations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Below is L2P code reconstruction of "action-by-action algorithm" from `"Leveragi
Current Model Construction Works
--------------------------------
This section provides a taxonomy of research within Model Construction. For more detailed overview, visit our `paper <https://puginarug.com>`_.
This section provides a taxonomy of research within Model Construction from the survey paper **Leveraging Large Language Models for Automated Planning and Model Construction: A Survey** (currently under review process).

Task Translation Frameworks
-------------------------------
Expand Down
129 changes: 77 additions & 52 deletions docs/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,98 +2,123 @@ 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 customised prompt. More details of each methods' prompt structure is found in **l2p/data/prompt_templates**
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**.

Domain Extraction Prompts Example
-------------------------------------------------------
This is an example found in `l2p/data/prompt_templates/action_construction/extract_action`
This is an example using `l2p/templates/domain_templates/extract_pddl_action.txt`

**Role**: ::
.. code-block:: python
:linenos:
End your final answers underneath the headers: '### Action Parameters,' '### Action Preconditions,' '### Action Effects,' and '### New Predicates' with ''' ''' comment blocks in PDDL as so:
from l2p.prompt_builder import PromptBuilder
from l2p.utils import load_file
### Action Parameters
```
- ?v - vehicle: The vehicle travelling
```
# LOAD BASE FORMAT TEMPLATE
template_path = "templates/domain_templates/extract_pddl_action.txt"
base_template = load_file(template_path)
### Action Preconditions
```
(and
(at ?v ?from) ; The vehicle is at the starting location
role_desc = (
"You are a PDDL action constructor. Your job is to take the task given in natural language and convert it into the following format:\n\n"
f"{base_template}" # INSERT BASE TEMPLATE
)
```

### Action Effects
```
(and
(not (at ?v ?from)) ; ?v is no longer at ?from
)
```

### New Predicates
```
- (at ?o - object ?l - location): true if the object ?o (a vehicle or a worker) is at the location ?l
```

**Task**: ::

Here is the task:

tech_desc = """
You should follow a Chain of Thought (CoT) process for constructing a PDDL action before outputting the final answer:
1. Construct action parameters and create necessary predicates to produce action preconditions in PDDL
2. Construct necessary predicates to produce action effects in PDDL
3. Check for inconsistencies and/or requirements and state the errors if there are any. If there are errors, generate a suggestion response (i.e. deleting, modifying, adding types)
4. Re-iterate parameters, preconditions, effects, and predicates
"""
task_desc = f"""
## Domain
{domain_desc}
## Types
## Available types
{types}
## Future actions to be used later:
## Future actions to be implemented later
{action_list}
## Action name
## Action name (to implement now)
{action_name}
## Action description
## Action description (corresponding action description)
{action_desc}
# Available predicates
## Available predicates
{predicates}
"""
action_construction_prompt = PromptBuilder(role=role_desc, technique=tech_desc, task=task_desc)
print(action_construction_prompt.generate_prompt())
Task Extraction Prompts Example
---------------------------------------------------
This is an example found in `l2p/data/prompt_templates/task_extraction/extract_task`
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 the following format:

**Role**: ::
End your final answers underneath the headers: '### Action Parameters,' '### Action Preconditions,' '### Action Effects,' and '### New Predicates' with ''' ''' comment blocks in PDDL as so:

Do not, under any circumstance, output the answers in PDDL format. Final answer must be in the following format at the end:
## OBJECTS
### Action Parameters
```
truck1 - truck
- ?t - type: 'parameter_description'
```

## INITIAL
### Action Preconditions
```
(at truck1 chicago_depot): truck1 is at the chicago_depot
(and
(predicate_name ?t1 ?t2) ; COMMENT DESCRIPTION
)
```

## GOAL
### Action Effects
```
(AND ; all the following should be done
(finalised house1) ; house 1 is done
(and
(predicate_name ?t1 ?t2) ; COMMENT DESCRIPTION
)
```

**Task**: ::
### 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.

------------------------------------------------
[TECHNIQUE]:
You should follow a Chain of Thought (CoT) process for constructing a PDDL action before outputting the final answer:

1. Construct action parameters and create necessary predicates to produce action preconditions in PDDL
2. Construct necessary predicates to produce action effects in PDDL
3. Check for inconsistencies and/or requirements and state the errors if there are any. If there are errors, generate a suggestion response (i.e. deleting, modifying, adding types)
4. Re-iterate parameters, preconditions, effects, and predicates

------------------------------------------------
[TASK]:
Here is the task to solve:

## Domain
{domain_desc}

## Types
## Available types
{types}

## Predicates
## 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}

## Problem description
{problem_desc}

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.
Loading

0 comments on commit 49085f2

Please sign in to comment.