feat: avoid loops

This commit is contained in:
Joschka Braun
2023-05-02 15:17:11 +02:00
parent ce8f1e7c5a
commit 811acc4436
3 changed files with 51 additions and 14 deletions

View File

@@ -21,12 +21,12 @@ from src.constants import FILE_AND_TAG_PAIRS, NUM_IMPLEMENTATION_STRATEGIES, MAX
from src.options.generate.templates_system import system_task_iteration, system_task_introduction, system_test_iteration
from src.options.generate.templates_user import template_generate_microservice_name, \
template_generate_possible_packages, \
template_solve_code_issue, \
template_implement_solution_code_issue, \
template_solve_pip_dependency_issue, template_is_dependency_issue, template_generate_playground, \
template_generate_function, template_generate_test, template_generate_requirements, \
template_chain_of_thought, template_summarize_error, \
template_generate_apt_get_install, template_solve_apt_get_dependency_issue, template_pm_task_iteration, \
template_pm_test_iteration
template_pm_test_iteration, template_suggest_solutions_code_issue
from src.options.generate.ui import get_random_employee
from src.utils.io import persist_file, get_all_microservice_files_with_content, get_microservice_path
@@ -201,7 +201,6 @@ metas:
# })
# )
with open(os.path.join(os.path.dirname(__file__), 'static_files', 'microservice', 'Dockerfile'), 'r', encoding='utf-8') as f:
docker_file_template_lines = f.readlines()
docker_file_template_lines = [line for line in docker_file_template_lines if not line.startswith('RUN apt-get update')]
@@ -348,15 +347,32 @@ pytest
all_files_string=dock_req_string,
)
else:
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,
destination_folder=next_microservice_path,
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']
)
self.generate_and_persist_file(
section_title='Debugging code issue',
template=template_solve_code_issue,
section_title='Implementing suggestion solution for code issue',
template=template_implement_solution_code_issue,
destination_folder=next_microservice_path,
file_name_s=[IMPLEMENTATION_FILE_NAME, TEST_EXECUTOR_FILE_NAME, REQUIREMENTS_FILE_NAME],
summarized_error=summarized_error,
task_description=self.microservice_specification.task,
test_description=self.microservice_specification.test,
all_files_string=self.files_to_string({key: val for key, val in file_name_to_content.items() if key != EXECUTOR_FILE_NAME}),
all_files_string=all_files_string,
suggested_solution=suggested_solutions["1"],
)
class MaxDebugTimeReachedException(BaseException):

View File

@@ -1,4 +1,4 @@
FROM jinaai/jina:3.14.1-py39-standard
FROM jinaai/jina:3.15.1-dev14-py39-standard
# update pip
RUN pip install --upgrade pip

View File

@@ -272,7 +272,7 @@ Output them as a white space separated list:'''
)
template_solve_code_issue = PromptTemplate.from_template(
template_suggest_solutions_code_issue = PromptTemplate.from_template(
'''General rules:
''' + not_allowed_function_string + '''
@@ -288,14 +288,35 @@ Here are all the files I use:
Here is the summary of the error that occurred:
{summarized_error}
To solve this error, you should:
1. Suggest 3 to 5 possible solutions on how to solve it. You have no access to the documentation of the package.
2. Decide for the best solution and explain it in detail.
3. Write down the files that need to be changed, but not files that don't need to be changed.
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.
You should suggest 3 to 5 possible solutions on how to solve it.
Obey the following rules:
You have no access to the documentation of the package.
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.
''' + f'{not_allowed_function_string}\n{not_allowed_docker_string}\n{gpt_35_turbo_usage_string}' + '''
After thinking about the possible solutions, output them as JSON ranked from best to worst. Like this:
**solutions.json**
```json
{{
"1": "<best solution>",
"2": "<2nd best solution>"
}}
```'''
)
template_implement_solution_code_issue = PromptTemplate.from_template(
'''Here is the description of the task the function must solve:
{task_description}
Here is the test scenario the function must pass:
{test_description}
Here are all the files I use:
{all_files_string}
Implemented the suggested solution: {suggested_solution}
Output all the files that need change. You must not change the Dockerfile.
Don't output files that don't need change. If you output a file, then write the complete file.
Use the exact following syntax to wrap the code:
@@ -307,7 +328,7 @@ Use the exact following syntax to wrap the code:
Example:
**microservice.py**
**implementation.py**
```python
print('hello world')
```'''