mirror of
https://github.com/aljazceru/dev-gpt.git
synced 2025-12-25 09:24:23 +01:00
🚀 feat: generate novel solution suggestions
This commit is contained in:
@@ -13,7 +13,7 @@ from pydantic.dataclasses import dataclass
|
||||
from src.apis import gpt
|
||||
from src.apis.gpt import _GPTConversation
|
||||
from src.apis.jina_cloud import process_error_message, push_executor, is_executor_in_hub
|
||||
from src.apis.pypi import is_package_on_pypi, get_latest_package_version, clean_requirements_txt
|
||||
from src.apis.pypi import is_package_on_pypi, clean_requirements_txt
|
||||
from src.constants import FILE_AND_TAG_PAIRS, NUM_IMPLEMENTATION_STRATEGIES, MAX_DEBUGGING_ITERATIONS, \
|
||||
BLACKLISTED_PACKAGES, EXECUTOR_FILE_NAME, TEST_EXECUTOR_FILE_NAME, TEST_EXECUTOR_FILE_TAG, \
|
||||
REQUIREMENTS_FILE_NAME, REQUIREMENTS_FILE_TAG, DOCKER_FILE_NAME, IMPLEMENTATION_FILE_NAME, \
|
||||
@@ -48,6 +48,8 @@ class Generator:
|
||||
self.microservice_name = None
|
||||
self.previous_microservice_path = None
|
||||
self.cur_microservice_path = None
|
||||
self.previous_errors = []
|
||||
self.previous_solutions = []
|
||||
|
||||
def extract_content_from_result(self, plain_text, file_name, match_single_block=False, can_contain_code_block=True):
|
||||
optional_line_break = '\n' if can_contain_code_block else '' # the \n at the end makes sure that ``` within the generated code is not matched because it is not right before a line break
|
||||
@@ -352,49 +354,8 @@ pytest
|
||||
all_files_string = self.files_to_string(
|
||||
{key: val for key, val in file_name_to_content.items() if key != EXECUTOR_FILE_NAME}
|
||||
)
|
||||
suggested_solutions = json.loads(
|
||||
self.generate_and_persist_file(
|
||||
section_title='Suggest solution for code issue',
|
||||
template=template_suggest_solutions_code_issue,
|
||||
file_name_s=['solutions.json'],
|
||||
summarized_error=summarized_error,
|
||||
task_description=self.microservice_specification.task,
|
||||
test_description=self.microservice_specification.test,
|
||||
all_files_string=all_files_string,
|
||||
)['solutions.json']
|
||||
)
|
||||
|
||||
was_error_seen_before = json.loads(
|
||||
self.generate_and_persist_file(
|
||||
section_title='Check if error was seen before',
|
||||
template=template_was_error_seen_before,
|
||||
file_name_s=['response.json'],
|
||||
summarized_error=summarized_error,
|
||||
previous_errors=None, # todo: fill-in mapping from previous errors to suggested solutions
|
||||
system_definition_examples=None,
|
||||
)['response.json']
|
||||
)['was_error_seen_before'].lower() == 'yes'
|
||||
|
||||
suggested_solution = None
|
||||
if was_error_seen_before:
|
||||
for _num_solution in range(len(suggested_solutions)):
|
||||
_suggested_solution = suggested_solutions[str(_num_solution)]
|
||||
was_solution_tried_before = json.loads(
|
||||
self.generate_and_persist_file(
|
||||
section_title='Check if solution was tried before',
|
||||
template=template_was_solution_tried_before,
|
||||
file_name_s=['response.json'],
|
||||
tried_solutions=None, # todo: fill-in mapping from tried solutions to suggested solutions
|
||||
suggested_solution=_suggested_solution,
|
||||
system_definition_examples=None,
|
||||
)['response.json']
|
||||
)['will_lead_to_different_actions'].lower() == 'no'
|
||||
if not was_solution_tried_before:
|
||||
suggested_solution = _suggested_solution
|
||||
break
|
||||
|
||||
if suggested_solution is None:
|
||||
suggested_solution = f"solve error: {summarized_error}"
|
||||
suggested_solution = self.generate_solution_suggestion(summarized_error, all_files_string)
|
||||
|
||||
self.generate_and_persist_file(
|
||||
section_title='Implementing suggestion solution for code issue',
|
||||
@@ -407,6 +368,58 @@ pytest
|
||||
suggested_solution=suggested_solution,
|
||||
)
|
||||
|
||||
def generate_solution_suggestion(self, summarized_error, all_files_string):
|
||||
suggested_solutions = json.loads(
|
||||
self.generate_and_persist_file(
|
||||
section_title='Suggest solution for code issue',
|
||||
template=template_suggest_solutions_code_issue,
|
||||
file_name_s=['solutions.json'],
|
||||
summarized_error=summarized_error,
|
||||
task_description=self.microservice_specification.task,
|
||||
test_description=self.microservice_specification.test,
|
||||
all_files_string=all_files_string,
|
||||
)['solutions.json']
|
||||
)
|
||||
|
||||
if len(self.previous_errors) > 0:
|
||||
was_error_seen_before = json.loads(
|
||||
self.generate_and_persist_file(
|
||||
section_title='Check if error was seen before',
|
||||
template=template_was_error_seen_before,
|
||||
file_name_s=['response.json'],
|
||||
summarized_error=summarized_error,
|
||||
previous_errors=f'- "{os.linesep}"'.join(self.previous_errors),
|
||||
system_definition_examples=None,
|
||||
)['response.json']
|
||||
)['was_error_seen_before'].lower() == 'yes'
|
||||
|
||||
suggested_solution = None
|
||||
if was_error_seen_before:
|
||||
for _num_solution in range(1, len(suggested_solutions) + 1):
|
||||
_suggested_solution = suggested_solutions[str(_num_solution)]
|
||||
was_solution_tried_before = json.loads(
|
||||
self.generate_and_persist_file(
|
||||
section_title='Check if solution was tried before',
|
||||
template=template_was_solution_tried_before,
|
||||
file_name_s=['response.json'],
|
||||
tried_solutions=f'- "{os.linesep}"'.join(self.previous_solutions),
|
||||
suggested_solution=_suggested_solution,
|
||||
system_definition_examples=None,
|
||||
)['response.json']
|
||||
)['will_lead_to_different_actions'].lower() == 'no'
|
||||
if not was_solution_tried_before:
|
||||
suggested_solution = _suggested_solution
|
||||
break
|
||||
else:
|
||||
suggested_solution = suggested_solutions['1']
|
||||
|
||||
if suggested_solution is None:
|
||||
suggested_solution = f"solve error: {summarized_error}"
|
||||
else:
|
||||
suggested_solution = suggested_solutions['1']
|
||||
|
||||
return suggested_solution
|
||||
|
||||
class MaxDebugTimeReachedException(BaseException):
|
||||
pass
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ e) the implementation of the core problem using the package would obey the follo
|
||||
When answering, just write "yes" or "no".
|
||||
|
||||
4. For each approach, list the required python package combinations as discibed in the following.
|
||||
You must output the package combinations as json wrapped into tripple backticks ``` and name it **strategies.json**. \
|
||||
You must output the package combinations as json wrapped into triple backticks ``` and name it **strategies.json**. \
|
||||
Note that you can also leave a list empty to indicate that one of the strategies does not require any package and can be done in plain python.
|
||||
Write the output using double asterisks and triple backticks like this:
|
||||
**strategies.json**
|
||||
@@ -78,7 +78,7 @@ Write the output using double asterisks and triple backticks like this:
|
||||
|
||||
|
||||
template_code_wrapping_string = '''The code will go into {file_name_purpose}.
|
||||
Note that you must obey the double asterisk and tripple backtick syntax from like this:
|
||||
Note that you must obey the double asterisk and triple backtick syntax from like this:
|
||||
**{file_name}**
|
||||
```{tag_name}
|
||||
...code...
|
||||
@@ -228,7 +228,7 @@ Is this error happening because a PACKAGE_MANAGER package is missing or failed t
|
||||
```json
|
||||
{{"dependency_installation_failure": "<yes/no>"}}
|
||||
```
|
||||
Note that you must obey the double asterisk and tripple backtick syntax from above.
|
||||
Note that you must obey the double asterisk and triple backtick syntax from above.
|
||||
'''
|
||||
)
|
||||
|
||||
@@ -313,8 +313,9 @@ Here are all the files I use:
|
||||
Here is the summary of the error that occurred:
|
||||
{summarized_error}
|
||||
|
||||
You should suggest 3 to 5 possible solutions on how to solve it.
|
||||
You should suggest 3 to 5 possible solution approaches on how to solve it.
|
||||
Obey the following rules:
|
||||
Do not implement the solution.
|
||||
You have no access to the documentation of the package.
|
||||
You must not change the Dockerfile.
|
||||
Note that any changes needed to make the test pass must be written under the constraint that ''' + IMPLEMENTATION_FILE_NAME + ''' will be used in a different file as well.
|
||||
@@ -332,6 +333,40 @@ After thinking about the possible solutions, output them as JSON ranked from bes
|
||||
)
|
||||
|
||||
|
||||
template_was_error_seen_before = PromptTemplate.from_template(
|
||||
'''Previously encountered error messages:
|
||||
{previous_errors}
|
||||
|
||||
Now encountered error message: "{summarized_error}"
|
||||
Was this error message encountered before?
|
||||
|
||||
Write down your final answer as json in the following format:
|
||||
**response.json**
|
||||
```json
|
||||
{{"was_error_seen_before": "<yes/no>"}}
|
||||
```
|
||||
Note that you must obey the double asterisk and triple backtick syntax from above.
|
||||
'''
|
||||
)
|
||||
|
||||
|
||||
template_was_solution_tried_before = PromptTemplate.from_template(
|
||||
'''Previously tried solutions:
|
||||
{tried_solutions}
|
||||
|
||||
Suggested solution: "{suggested_solution}"
|
||||
|
||||
Will the suggested solution lead to different actions than the previously tried solutions?
|
||||
|
||||
Write down your final answer as json in the following format:
|
||||
**response.json**
|
||||
```json
|
||||
{{"will_lead_to_different_actions": "<yes/no>"}}
|
||||
```
|
||||
Note that you must obey the double asterisk and triple backtick syntax from above.'''
|
||||
)
|
||||
|
||||
|
||||
template_implement_solution_code_issue = PromptTemplate.from_template(
|
||||
'''Here is the description of the task the function must solve:
|
||||
{task_description}
|
||||
@@ -442,7 +477,7 @@ Or write the detailed microservice description all mentioned code samples, docum
|
||||
}}
|
||||
```
|
||||
Note that your response must be either prompt.json or final.json. You must not write both.
|
||||
Note that you must obey the double asterisk and tripple backtick syntax from above.
|
||||
Note that you must obey the double asterisk and triple backtick syntax from above.
|
||||
Note that the last sequence of characters in your response must be ``` (triple backtick).
|
||||
Note that prompt.json must not only contain one question.
|
||||
Note that if urls, secrets, database names, etc. are mentioned, they must be part of the summary.
|
||||
@@ -486,7 +521,7 @@ Example for the case where the example is already mentioned in the refined descr
|
||||
}}
|
||||
```
|
||||
Note that your response must be either prompt.json or final.json. You must not write both.
|
||||
Note that you must obey the double asterisk and tripple backtick syntax from above.
|
||||
Note that you must obey the double asterisk and triple backtick syntax from above.
|
||||
Note that the last sequence of characters in your response must be ``` (triple backtick).
|
||||
Note that your response must start with the character sequence ** (double asterisk).
|
||||
Note that prompt.json must only contain one question.
|
||||
|
||||
Reference in New Issue
Block a user