Skip to content

Commit b081299

Browse files
authored
Merge pull request #12 from MarcusTantakoun/main
Fixed type absence case
2 parents c7ea412 + 66b3be0 commit b081299

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

l2p/domain_builder.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -289,32 +289,28 @@ def extract_pddl_action(
289289
llm_response, syntax_validator.unsupported_keywords
290290
)
291291
)
292-
elif e == "invalid_param_types":
292+
elif e == "invalid_param_types" and types:
293293
validation_info = syntax_validator.validate_params(
294294
action["params"], types
295295
)
296-
elif e == "invalid_predicate_name":
296+
elif e == "invalid_predicate_name" and types:
297297
validation_info = (
298298
syntax_validator.validate_types_predicates(
299299
new_predicates, types
300300
)
301301
)
302-
elif e == "invalid_predicate_format":
302+
elif e == "invalid_predicate_format" and types:
303303
validation_info = (
304304
syntax_validator.validate_format_predicates(
305305
predicates, types
306306
)
307307
)
308-
elif e == "invalid_predicate_usage":
308+
elif e == "invalid_predicate_usage" and types:
309309
validation_info = (
310310
syntax_validator.validate_usage_predicates(
311311
llm_response, predicates, types
312312
)
313313
)
314-
else:
315-
raise NotImplementedError(
316-
f"Validation type '{e}' is not implemented."
317-
)
318314

319315
if not validation_info[0]:
320316
return action, new_predicates, llm_response, validation_info
@@ -759,7 +755,7 @@ def get_predicates(self):
759755
def generate_domain(
760756
self,
761757
domain: str,
762-
types: str,
758+
types: str | None,
763759
predicates: str,
764760
actions: list[Action],
765761
requirements: list[str],
@@ -783,7 +779,8 @@ def generate_domain(
783779
indent(string=f"(:requirements\n {' '.join(requirements)})", level=1)
784780
+ "\n\n"
785781
)
786-
desc += f" (:types \n{indent(string=types, level=2)}\n )\n\n"
782+
if types: # Only add types if not None or empty string
783+
desc += f" (:types \n{indent(string=types, level=2)}\n )\n\n"
787784
desc += f" (:predicates \n{indent(string=predicates, level=2)}\n )"
788785
desc += self.action_descs(actions)
789786
desc += "\n)"

l2p/llm_builder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ def valid_models(self) -> list[str]:
258258
"gpt-4-32k",
259259
"gpt-4o",
260260
"gpt-4o-mini",
261+
"o1",
262+
"o3-mini"
261263
]
262264

263265

l2p/utils/pddl_validator.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,27 @@ def __init__(self, error_types=None, unsupported_keywords=None):
3737
# PARAMETER CHECKS
3838

3939
def validate_params(
40-
self, parameters: OrderedDict, types: dict[str, str]
40+
self, parameters: OrderedDict, types: dict[str, str] | None
4141
) -> tuple[bool, str]:
4242
"""Checks whether a PDDL action parameter contains types found in object types."""
43+
44+
types = types or {}
45+
46+
# If no types are defined, inform the user and check for parameter types
47+
if not types:
48+
for param_name, param_type in parameters.items():
49+
if param_type is not None and param_type != "":
50+
feedback_msg = (
51+
f'The parameter `{param_name}` has an object type `{param_type}` '
52+
'while no types are defined. Please remove the object type from this parameter.'
53+
)
54+
return False, feedback_msg
55+
56+
# if all parameter names do not contain a type
57+
return True, "PASS: All parameters are valid."
4358

44-
for param_name in parameters:
45-
param_type = parameters[param_name]
59+
# Otherwise, check that parameter types are valid in the given types
60+
for param_name, param_type in parameters.items():
4661

4762
if not any(param_type in t for t in types.keys()):
4863
feedback_msg = f'There is an invalid object type `{param_type}` for the parameter {param_name} not found in the types {types.keys()}. If you need to use a new type, you can emulate it with an "is_{{type}} ?o - object" precondition. Please revise the PDDL model to fix this error.'
@@ -54,9 +69,16 @@ def validate_params(
5469
# PREDICATE CHECKS
5570

5671
def validate_types_predicates(
57-
self, predicates: list[dict], types: dict[str, str]
72+
self, predicates: list[dict], types: dict[str, str] | None
5873
) -> tuple[bool, str]:
5974
"""Check if predicate name is found within any type definitions"""
75+
76+
# Handle the case where types is None or empty
77+
types = types or {}
78+
79+
if not types:
80+
feedback_msg = "PASS: All predicate names are unique to object type names"
81+
return True, feedback_msg
6082

6183
invalid_predicates = list()
6284
for pred in predicates:

0 commit comments

Comments
 (0)