Skip to content

Commit

Permalink
Update parser.py
Browse files Browse the repository at this point in the history
  • Loading branch information
monk1337 authored Jul 29, 2023
1 parent d8b4728 commit aaf8d96
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions promptify/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def complete_json_object(self, json_str: str, completion_str: str) -> Any:
return python_obj

def get_possible_completions(
self, json_str: str, max_completion_length: int = 5
self, json_str: str, json_depth_limit: int = 5
) -> Union[Dict[str, Any], List[Any]]:
"""
Returns a list of possible completions for a JSON object string.
Expand All @@ -171,7 +171,7 @@ def get_possible_completions(
----------
json_str : str
The JSON object string
max_completion_length : int, optional
json_depth_limit : int, optional
The maximum length of the completion strings to try (default is 5)
Returns
Expand All @@ -190,7 +190,7 @@ def get_possible_completions(
should_end_mark = "]" if json_str.strip()[0] == "[" else "}"
completions = []
for completion_str in self.get_combinations(
candidate_marks, max_completion_length, should_end_mark=should_end_mark
candidate_marks, json_depth_limit, should_end_mark=should_end_mark
):
try:
completed_obj = self.complete_json_object(json_str, completion_str)
Expand All @@ -199,15 +199,15 @@ def get_possible_completions(
pass
return self.find_max_length(completions)

def fit(self, json_str: str, max_completion_length: int = 5) -> Dict[str, Any]:
def fit(self, json_str: str, json_depth_limit: int = 5) -> Dict[str, Any]:
"""
Tries to parse the input JSON string and complete it if it is incomplete.
Parameters
----------
json_str : str
The input JSON string
max_completion_length : int, optional
json_depth_limit : int, optional
The maximum length of the completion strings to try (default is 5)
Returns
Expand All @@ -230,7 +230,7 @@ def fit(self, json_str: str, max_completion_length: int = 5) -> Dict[str, Any]:
json_str = re.sub(r"[\[\]\{\}\s]+$", "", json_str)
try:
output = self.get_possible_completions(
json_str, max_completion_length=max_completion_length
json_str, json_depth_limit=json_depth_limit
)
return {
"status": "completed",
Expand Down

0 comments on commit aaf8d96

Please sign in to comment.