mirror of
https://github.com/aljazceru/dev-gpt.git
synced 2025-12-23 16:44:20 +01:00
⏪ fix: self healing response parser
This commit is contained in:
@@ -28,19 +28,11 @@ Your task:
|
||||
You must return the fixed {content_type}.
|
||||
Most importantly, you are not allowed to return something else - only the fixed {content_type}.
|
||||
|
||||
Positive example:
|
||||
**solution.json**
|
||||
```json
|
||||
{
|
||||
Example:
|
||||
{{
|
||||
"key1": "value1",
|
||||
"key2": "value2"
|
||||
}
|
||||
Negative example:
|
||||
{
|
||||
"key1": "value1",
|
||||
"key2": "value2"
|
||||
}
|
||||
'''
|
||||
}}'''
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -440,10 +440,11 @@ pytest
|
||||
self.previous_solutions.append(suggested_solution)
|
||||
|
||||
def generate_solution_suggestion(self, summarized_error, all_files_string):
|
||||
json_string = self.generate_and_persist_file(
|
||||
suggested_solutions = self.generate_and_persist_file(
|
||||
section_title='Suggest solution for code issue',
|
||||
template=template_suggest_solutions_code_issue,
|
||||
file_name_s=['solutions.json'],
|
||||
file_name_s=['not_needed'],
|
||||
parse_result_fn=self_healing_json_parser,
|
||||
summarized_error=summarized_error,
|
||||
task_description=self.microservice_specification.task,
|
||||
test_description=self.microservice_specification.test,
|
||||
@@ -451,8 +452,6 @@ pytest
|
||||
response_format_example=response_format_suggest_solutions,
|
||||
)
|
||||
|
||||
suggested_solutions = self_healing_json_parser(json_string)['solutions.json']
|
||||
|
||||
if len(self.previous_errors) > 0:
|
||||
was_error_seen_before = json.loads(
|
||||
self.generate_and_persist_file(
|
||||
|
||||
@@ -18,8 +18,8 @@ def boolean_parser(x):
|
||||
|
||||
def json_parser(x):
|
||||
if '```' in x:
|
||||
pattern = r'```(json)?(.+)```'
|
||||
x = re.findall(pattern, x, re.DOTALL)[-1][-1]
|
||||
pattern = r'([\[\{].+[\]\}])'
|
||||
x = re.findall(pattern, x, re.DOTALL)[-1]
|
||||
return json.loads(x)
|
||||
|
||||
def self_healing_json_parser(original_json_string):
|
||||
|
||||
@@ -332,7 +332,7 @@ Note: the first line you output must be: **apt-get-packages.json**
|
||||
)
|
||||
|
||||
|
||||
response_format_suggest_solutions = '''**solutions.json**
|
||||
response_format_suggest_solutions = '''\
|
||||
```json
|
||||
{{
|
||||
"1": "<best solution>",
|
||||
@@ -369,7 +369,7 @@ Note that any changes needed to make the test pass must be written under the con
|
||||
After thinking about the possible solutions, output them as JSON ranked from best to worst.
|
||||
You must use the following format:
|
||||
''' + response_format_suggest_solutions + '''
|
||||
Ensure the response starts with **solutions.json** and can be parsed by Python json.loads'''
|
||||
Ensure the response can be parsed by Python json.loads'''
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user