mirror of
https://github.com/aljazceru/dev-gpt.git
synced 2025-12-22 16:14:20 +01:00
refactor: use templates
This commit is contained in:
@@ -5,13 +5,13 @@ import re
|
|||||||
from src.apis import gpt
|
from src.apis import gpt
|
||||||
from src.apis.jina_cloud import process_error_message, push_executor
|
from src.apis.jina_cloud import process_error_message, push_executor
|
||||||
from src.constants import FILE_AND_TAG_PAIRS, NUM_IMPLEMENTATION_STRATEGIES, MAX_DEBUGGING_ITERATIONS, \
|
from src.constants import FILE_AND_TAG_PAIRS, NUM_IMPLEMENTATION_STRATEGIES, MAX_DEBUGGING_ITERATIONS, \
|
||||||
PROBLEMATIC_PACKAGES
|
PROBLEMATIC_PACKAGES, EXECUTOR_FILE_NAME, EXECUTOR_FILE_TAG, TEST_EXECUTOR_FILE_NAME, TEST_EXECUTOR_FILE_TAG, \
|
||||||
from src.options.generate.prompt_tasks import general_guidelines, executor_file_task, \
|
REQUIREMENTS_FILE_NAME, REQUIREMENTS_FILE_TAG, DOCKER_FILE_NAME, DOCKER_FILE_TAG
|
||||||
not_allowed_executor, chain_of_thought_optimization, test_executor_file_task, requirements_file_task, \
|
|
||||||
docker_file_task, not_allowed_docker
|
|
||||||
from src.options.generate.templates import template_generate_microservice_name, template_generate_possible_packages, \
|
from src.options.generate.templates import template_generate_microservice_name, template_generate_possible_packages, \
|
||||||
template_solve_code_issue, \
|
template_solve_code_issue, \
|
||||||
template_solve_dependency_issue, template_is_dependency_issue, template_generate_playground
|
template_solve_dependency_issue, template_is_dependency_issue, template_generate_playground, \
|
||||||
|
template_generate_executor, template_generate_test, template_generate_requirements, template_generate_dockerfile, \
|
||||||
|
template_chain_of_thought
|
||||||
from src.utils.io import persist_file, get_all_microservice_files_with_content, get_microservice_path
|
from src.utils.io import persist_file, get_all_microservice_files_with_content, get_microservice_path
|
||||||
from src.utils.string_tools import print_colored
|
from src.utils.string_tools import print_colored
|
||||||
|
|
||||||
@@ -52,9 +52,6 @@ metas:
|
|||||||
all_microservice_files_string += f'**{file_name}**\n```{tag}\n{file_name_to_content[file_name]}\n```\n\n'
|
all_microservice_files_string += f'**{file_name}**\n```{tag}\n{file_name_to_content[file_name]}\n```\n\n'
|
||||||
return all_microservice_files_string
|
return all_microservice_files_string
|
||||||
|
|
||||||
# def wrap_content_in_code_block(self, microservice_content, file_name, tag):
|
|
||||||
# return f'**{file_name}**\n```{tag}\n{microservice_content}\n```\n\n'
|
|
||||||
|
|
||||||
def generate_microservice(
|
def generate_microservice(
|
||||||
self,
|
self,
|
||||||
description,
|
description,
|
||||||
@@ -63,24 +60,26 @@ metas:
|
|||||||
microservice_name,
|
microservice_name,
|
||||||
package,
|
package,
|
||||||
num_approach,
|
num_approach,
|
||||||
is_chain_of_thought=False,
|
|
||||||
):
|
):
|
||||||
MICROSERVICE_FOLDER_v1 = get_microservice_path(path, microservice_name, package, num_approach, 1)
|
MICROSERVICE_FOLDER_v1 = get_microservice_path(path, microservice_name, package, num_approach, 1)
|
||||||
os.makedirs(MICROSERVICE_FOLDER_v1)
|
os.makedirs(MICROSERVICE_FOLDER_v1)
|
||||||
|
|
||||||
print_colored('', '############# Microservice #############', 'blue')
|
print_colored('', '############# Microservice #############', 'blue')
|
||||||
user_query = (
|
|
||||||
general_guidelines()
|
|
||||||
+ executor_file_task(microservice_name, description, test, package)
|
|
||||||
)
|
|
||||||
conversation = self.gpt_session.get_conversation()
|
conversation = self.gpt_session.get_conversation()
|
||||||
microservice_content_raw = conversation.chat(user_query)
|
microservice_content_raw = conversation.chat(
|
||||||
if is_chain_of_thought:
|
template_generate_executor.format(
|
||||||
microservice_content_raw = conversation.chat(
|
microservice_name=microservice_name,
|
||||||
f"General rules: " + not_allowed_executor() + chain_of_thought_optimization('python',
|
microservice_description=description,
|
||||||
'microservice.py'))
|
test=test,
|
||||||
microservice_content = self.extract_content_from_result(microservice_content_raw, 'microservice.py',
|
package=package,
|
||||||
match_single_block=True)
|
file_name_purpose=EXECUTOR_FILE_NAME,
|
||||||
|
tag_name=EXECUTOR_FILE_TAG,
|
||||||
|
file_name=EXECUTOR_FILE_NAME,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
microservice_content = self.extract_content_from_result(
|
||||||
|
microservice_content_raw, 'microservice.py', match_single_block=True
|
||||||
|
)
|
||||||
if microservice_content == '':
|
if microservice_content == '':
|
||||||
microservice_content_raw = conversation.chat('You must add the executor code.')
|
microservice_content_raw = conversation.chat('You must add the executor code.')
|
||||||
microservice_content = self.extract_content_from_result(
|
microservice_content = self.extract_content_from_result(
|
||||||
@@ -89,19 +88,16 @@ metas:
|
|||||||
persist_file(microservice_content, os.path.join(MICROSERVICE_FOLDER_v1, 'microservice.py'))
|
persist_file(microservice_content, os.path.join(MICROSERVICE_FOLDER_v1, 'microservice.py'))
|
||||||
|
|
||||||
print_colored('', '############# Test Microservice #############', 'blue')
|
print_colored('', '############# Test Microservice #############', 'blue')
|
||||||
user_query = (
|
|
||||||
general_guidelines()
|
|
||||||
+ self.wrap_content_in_code_block(microservice_content, 'microservice.py', 'python')
|
|
||||||
+ test_executor_file_task(microservice_name, test)
|
|
||||||
)
|
|
||||||
conversation = self.gpt_session.get_conversation()
|
conversation = self.gpt_session.get_conversation()
|
||||||
test_microservice_content_raw = conversation.chat(user_query)
|
test_microservice_content_raw = conversation.chat(
|
||||||
if is_chain_of_thought:
|
template_generate_test.format(
|
||||||
test_microservice_content_raw = conversation.chat(
|
code_files_wrapped=self.files_to_string({'microservice.py': microservice_content}),
|
||||||
f"General rules: " + not_allowed_executor() +
|
microservice_name=microservice_name,
|
||||||
chain_of_thought_optimization('python', 'test_microservice.py')
|
file_name_purpose=TEST_EXECUTOR_FILE_NAME,
|
||||||
+ "Don't add any additional tests. "
|
tag_name=TEST_EXECUTOR_FILE_TAG,
|
||||||
|
file_name=TEST_EXECUTOR_FILE_NAME,
|
||||||
)
|
)
|
||||||
|
)
|
||||||
test_microservice_content = self.extract_content_from_result(
|
test_microservice_content = self.extract_content_from_result(
|
||||||
test_microservice_content_raw, 'microservice.py', match_single_block=True
|
test_microservice_content_raw, 'microservice.py', match_single_block=True
|
||||||
)
|
)
|
||||||
@@ -109,37 +105,41 @@ metas:
|
|||||||
|
|
||||||
print_colored('', '############# Requirements #############', 'blue')
|
print_colored('', '############# Requirements #############', 'blue')
|
||||||
requirements_path = os.path.join(MICROSERVICE_FOLDER_v1, 'requirements.txt')
|
requirements_path = os.path.join(MICROSERVICE_FOLDER_v1, 'requirements.txt')
|
||||||
user_query = (
|
|
||||||
general_guidelines()
|
|
||||||
+ self.wrap_content_in_code_block(microservice_content, 'microservice.py', 'python')
|
|
||||||
+ self.wrap_content_in_code_block(test_microservice_content, 'test_microservice.py', 'python')
|
|
||||||
+ requirements_file_task()
|
|
||||||
)
|
|
||||||
conversation = self.gpt_session.get_conversation()
|
conversation = self.gpt_session.get_conversation()
|
||||||
requirements_content_raw = conversation.chat(user_query)
|
requirements_content_raw = conversation.chat(
|
||||||
if is_chain_of_thought:
|
template_generate_requirements.format(
|
||||||
requirements_content_raw = conversation.chat(
|
code_files_wrapped=self.files_to_string(
|
||||||
chain_of_thought_optimization('', requirements_path) + "Keep the same version of jina ")
|
{'microservice.py': microservice_content, 'test_microservice.py': test_microservice_content}
|
||||||
|
),
|
||||||
|
file_name_purpose=REQUIREMENTS_FILE_NAME,
|
||||||
|
file_name=REQUIREMENTS_FILE_NAME,
|
||||||
|
tag_name=REQUIREMENTS_FILE_TAG,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
requirements_content = self.extract_content_from_result(requirements_content_raw, 'requirements.txt',
|
requirements_content = self.extract_content_from_result(requirements_content_raw, 'requirements.txt',
|
||||||
match_single_block=True)
|
match_single_block=True)
|
||||||
persist_file(requirements_content, requirements_path)
|
persist_file(requirements_content, requirements_path)
|
||||||
|
|
||||||
print_colored('', '############# Dockerfile #############', 'blue')
|
print_colored('', '############# Dockerfile #############', 'blue')
|
||||||
user_query = (
|
|
||||||
general_guidelines()
|
|
||||||
+ self.wrap_content_in_code_block(microservice_content, 'microservice.py', 'python')
|
|
||||||
+ self.wrap_content_in_code_block(test_microservice_content, 'test_microservice.py', 'python')
|
|
||||||
+ self.wrap_content_in_code_block(requirements_content, 'requirements.txt', '')
|
|
||||||
+ docker_file_task()
|
|
||||||
)
|
|
||||||
conversation = self.gpt_session.get_conversation()
|
conversation = self.gpt_session.get_conversation()
|
||||||
dockerfile_content_raw = conversation.chat(user_query)
|
dockerfile_content_raw = conversation.chat(
|
||||||
if is_chain_of_thought:
|
template_generate_dockerfile.format(
|
||||||
dockerfile_content_raw = conversation.chat(
|
code_files_wrapped=self.files_to_string(
|
||||||
f"General rules: " + not_allowed_executor() + chain_of_thought_optimization('dockerfile', 'Dockerfile'))
|
{
|
||||||
dockerfile_content = self.extract_content_from_result(dockerfile_content_raw, 'Dockerfile',
|
'microservice.py': microservice_content,
|
||||||
match_single_block=True)
|
'test_microservice.py': test_microservice_content,
|
||||||
|
'requirements.txt': requirements_content,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
file_name_purpose=DOCKER_FILE_NAME,
|
||||||
|
file_name=DOCKER_FILE_NAME,
|
||||||
|
tag_name=DOCKER_FILE_TAG,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
dockerfile_content = self.extract_content_from_result(
|
||||||
|
dockerfile_content_raw, 'Dockerfile', match_single_block=True
|
||||||
|
)
|
||||||
persist_file(dockerfile_content, os.path.join(MICROSERVICE_FOLDER_v1, 'Dockerfile'))
|
persist_file(dockerfile_content, os.path.join(MICROSERVICE_FOLDER_v1, 'Dockerfile'))
|
||||||
|
|
||||||
self.write_config_yml(microservice_name, MICROSERVICE_FOLDER_v1)
|
self.write_config_yml(microservice_name, MICROSERVICE_FOLDER_v1)
|
||||||
@@ -152,13 +152,18 @@ metas:
|
|||||||
conversation = self.gpt_session.get_conversation([])
|
conversation = self.gpt_session.get_conversation([])
|
||||||
conversation.chat(
|
conversation.chat(
|
||||||
template_generate_playground.format(
|
template_generate_playground.format(
|
||||||
general_guidelines=general_guidelines(),
|
|
||||||
code_files_wrapped=self.files_to_string(file_name_to_content, ['microservice.py', 'test_microservice.py']),
|
code_files_wrapped=self.files_to_string(file_name_to_content, ['microservice.py', 'test_microservice.py']),
|
||||||
microservice_name=microservice_name,
|
microservice_name=microservice_name,
|
||||||
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
playground_content_raw = conversation.chat(chain_of_thought_optimization('python', 'app.py', 'the playground'))
|
playground_content_raw = conversation.chat(
|
||||||
|
template_chain_of_thought.format(
|
||||||
|
file_name_purpose='app.py/the playground',
|
||||||
|
file_name='app.py',
|
||||||
|
tag_name='python',
|
||||||
|
)
|
||||||
|
)
|
||||||
playground_content = self.extract_content_from_result(playground_content_raw, 'app.py', match_single_block=True)
|
playground_content = self.extract_content_from_result(playground_content_raw, 'app.py', match_single_block=True)
|
||||||
persist_file(playground_content, os.path.join(microservice_path, 'app.py'))
|
persist_file(playground_content, os.path.join(microservice_path, 'app.py'))
|
||||||
|
|
||||||
@@ -195,12 +200,10 @@ metas:
|
|||||||
})
|
})
|
||||||
user_query = template_solve_dependency_issue.format(
|
user_query = template_solve_dependency_issue.format(
|
||||||
description=description, error=error, all_files_string=all_files_string,
|
description=description, error=error, all_files_string=all_files_string,
|
||||||
not_allowed_docker=not_allowed_docker()
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
user_query = template_solve_code_issue.format(
|
user_query = template_solve_code_issue.format(
|
||||||
description=description, error=error, all_files_string=self.files_to_string(file_name_to_content),
|
description=description, error=error, all_files_string=self.files_to_string(file_name_to_content),
|
||||||
not_allowed_executor=not_allowed_executor()
|
|
||||||
)
|
)
|
||||||
conversation = self.gpt_session.get_conversation()
|
conversation = self.gpt_session.get_conversation()
|
||||||
returned_files_raw = conversation.chat(user_query)
|
returned_files_raw = conversation.chat(user_query)
|
||||||
@@ -234,7 +237,7 @@ metas:
|
|||||||
print_colored('', '############# What packages to use? #############', 'blue')
|
print_colored('', '############# What packages to use? #############', 'blue')
|
||||||
conversation = self.gpt_session.get_conversation()
|
conversation = self.gpt_session.get_conversation()
|
||||||
packages_raw = conversation.chat(
|
packages_raw = conversation.chat(
|
||||||
template_generate_possible_packages.format(description=description, not_allowed_executor=not_allowed_executor())
|
template_generate_possible_packages.format(description=description)
|
||||||
)
|
)
|
||||||
packages_csv_string = self.extract_content_from_result(packages_raw, 'packages.csv')
|
packages_csv_string = self.extract_content_from_result(packages_raw, 'packages.csv')
|
||||||
packages = [package.split(',') for package in packages_csv_string.split('\n')]
|
packages = [package.split(',') for package in packages_csv_string.split('\n')]
|
||||||
|
|||||||
@@ -1,151 +0,0 @@
|
|||||||
from src.constants import EXECUTOR_FILE_NAME, REQUIREMENTS_FILE_NAME, TEST_EXECUTOR_FILE_NAME, DOCKER_FILE_NAME, \
|
|
||||||
DOCKER_FILE_TAG, CLIENT_FILE_TAG, CLIENT_FILE_NAME, STREAMLIT_FILE_TAG, STREAMLIT_FILE_NAME, EXECUTOR_FILE_TAG, \
|
|
||||||
REQUIREMENTS_FILE_TAG, TEST_EXECUTOR_FILE_TAG
|
|
||||||
|
|
||||||
|
|
||||||
def general_guidelines():
|
|
||||||
return (
|
|
||||||
"The code you write is production ready. "
|
|
||||||
"Every file starts with comments describing what the code is doing before the first import. "
|
|
||||||
"Comments can only be written within code blocks. "
|
|
||||||
"Then all imports are listed. "
|
|
||||||
"It is important to import all modules that could be needed in the Executor code. "
|
|
||||||
"Always import: "
|
|
||||||
"from jina import Executor, DocumentArray, Document, requests "
|
|
||||||
"Start from top-level and then fully implement all methods. "
|
|
||||||
"\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _task(task, tag_name, file_name, purpose=None):
|
|
||||||
into_string = file_name
|
|
||||||
if purpose:
|
|
||||||
into_string += f"/{purpose}"
|
|
||||||
|
|
||||||
return (
|
|
||||||
task + f"The code will go into {into_string}. Make sure to wrap the code into ``` marks even if you only "
|
|
||||||
f"output code:\n"
|
|
||||||
f"**{file_name}**\n"
|
|
||||||
f"```{tag_name}\n"
|
|
||||||
f"...code...\n"
|
|
||||||
f"```\nYou must provide the complete file with the exact same syntax to wrap the code."
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def executor_file_task(executor_name, executor_description, test_scenario, package):
|
|
||||||
return _task(f'''
|
|
||||||
Write the executor called '{executor_name}'. The name is very important to keep.
|
|
||||||
It matches the following description: '{executor_description}'.
|
|
||||||
It will be tested with the following scenario: '{test_scenario}'.
|
|
||||||
For the implementation use the following package: '{package}'.
|
|
||||||
|
|
||||||
Obey the following rules:
|
|
||||||
Have in mind that d.uri is never a path to a local file. It is always a url.
|
|
||||||
{not_allowed_executor()}
|
|
||||||
Your approach:
|
|
||||||
1. Identify the core challenge when implementing the executor.
|
|
||||||
2. Think about solutions for these challenges.
|
|
||||||
3. Decide for one of the solutions.
|
|
||||||
4. Write the code.
|
|
||||||
''', EXECUTOR_FILE_TAG, EXECUTOR_FILE_NAME)
|
|
||||||
|
|
||||||
|
|
||||||
def test_executor_file_task(executor_name, test_scenario):
|
|
||||||
return _task(
|
|
||||||
"Write a small unit test for the executor. "
|
|
||||||
"Start the test with an extensive comment about the test case. "
|
|
||||||
+ (
|
|
||||||
f"Write a single test case that tests the following scenario: '{test_scenario}'. "
|
|
||||||
f"In case the test scenario is not precise enough, test a general case without any assumptions."
|
|
||||||
if test_scenario else ""
|
|
||||||
)
|
|
||||||
+ "Use the following import to import the executor: "
|
|
||||||
f"```\nfrom microservice import {executor_name}\n```"
|
|
||||||
+ not_allowed_executor()
|
|
||||||
+ "The test must not open local files. "
|
|
||||||
+ "The test must not mock a function of the executor. "
|
|
||||||
+ "The test must not use other data than the one provided in the test scenario. ",
|
|
||||||
TEST_EXECUTOR_FILE_TAG,
|
|
||||||
TEST_EXECUTOR_FILE_NAME
|
|
||||||
)
|
|
||||||
|
|
||||||
def requirements_file_task():
|
|
||||||
return _task(
|
|
||||||
"Write the content of the requirements.txt file. "
|
|
||||||
"Make sure to include pytest. "
|
|
||||||
"Make sure that jina==3.14.1. "
|
|
||||||
"All versions are fixed using ~=, ==, <, >, <=, >=. The package versions should not have conflicts. ",
|
|
||||||
REQUIREMENTS_FILE_TAG,
|
|
||||||
REQUIREMENTS_FILE_NAME
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def docker_file_task():
|
|
||||||
return _task(
|
|
||||||
"Write the Dockerfile that defines the environment with all necessary dependencies that the executor uses. "
|
|
||||||
"It is important to make sure that all libs are installed that are required by the python packages. "
|
|
||||||
"Usually libraries are installed with apt-get. "
|
|
||||||
"Be aware that the machine the docker container is running on does not have a GPU - only CPU. "
|
|
||||||
"Add the config.yml file to the Dockerfile. Note that the Dockerfile only has access to the files: "
|
|
||||||
"microservice.py, requirements.txt, config.yml, test_microservice.py. "
|
|
||||||
"The base image of the Dockerfile is FROM jinaai/jina:3.14.1-py39-standard. "
|
|
||||||
'The entrypoint is ENTRYPOINT ["jina", "executor", "--uses", "config.yml"]. '
|
|
||||||
'Make sure the all files are in the /workdir. '
|
|
||||||
"The Dockerfile runs the test during the build process. " + not_allowed_docker(),
|
|
||||||
DOCKER_FILE_TAG,
|
|
||||||
DOCKER_FILE_NAME
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def client_file_task():
|
|
||||||
return _task(
|
|
||||||
"Write the client file. ",
|
|
||||||
CLIENT_FILE_TAG,
|
|
||||||
CLIENT_FILE_NAME
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def streamlit_file_task():
|
|
||||||
return _task(
|
|
||||||
"Write the streamlit file allowing to make requests . ",
|
|
||||||
STREAMLIT_FILE_TAG,
|
|
||||||
STREAMLIT_FILE_NAME
|
|
||||||
)
|
|
||||||
|
|
||||||
def chain_of_thought_optimization(tag_name, file_name, file_name_function=None):
|
|
||||||
file_name_or_function = file_name
|
|
||||||
if file_name_function:
|
|
||||||
file_name_or_function += f"/{file_name_function}"
|
|
||||||
return _task(
|
|
||||||
f'First, write down an extensive list of obvious and non-obvious observations about {file_name_or_function} that could need an adjustment. Explain why. '
|
|
||||||
f"Think if all the changes are required and finally decide for the changes you want to make, "
|
|
||||||
f"but you are not allowed disregard the instructions in the previous message. "
|
|
||||||
f"Be very hesitant to change the code. Only make a change if you are sure that it is necessary. "
|
|
||||||
|
|
||||||
f"Output only {file_name_or_function} "
|
|
||||||
f"Write the whole content of {file_name_or_function} - even if you decided to change only a small thing or even nothing. ",
|
|
||||||
tag_name,
|
|
||||||
file_name,
|
|
||||||
file_name_function
|
|
||||||
)
|
|
||||||
|
|
||||||
def not_allowed_executor():
|
|
||||||
return '''
|
|
||||||
The executor and the test must not use the GPU.
|
|
||||||
The executor and the test must not access a database.
|
|
||||||
The executor and the test must not access a display.
|
|
||||||
The executor and the test must not access external apis except unless it is explicitly mentioned in the description or test case (e.g. by mentioning the api that should be used or by providing a URL to access the data).
|
|
||||||
The executor and the test must not load data from the local file system unless it was created by the executor itself.
|
|
||||||
The executor and the test must not use a pre-trained model unless it is explicitly mentioned in the description.
|
|
||||||
The executor and the test must not train a model.
|
|
||||||
The executor and the test must not use any attribute of Document accept Document.text.
|
|
||||||
The executor and the test must not contain prototype or placeholder implementations.
|
|
||||||
The executor and the test must run in a docker container based on debian.
|
|
||||||
'''
|
|
||||||
|
|
||||||
def not_allowed_docker():
|
|
||||||
return '''
|
|
||||||
Note that the Dockerfile only has access to the files: microservice.py, requirements.txt, config.yml, test_microservice.py.
|
|
||||||
Note that the Dockerfile runs the test_microservice.py during the build process.
|
|
||||||
The Dockerfile must not attach a virtual display when running test_microservice.py.
|
|
||||||
'''
|
|
||||||
@@ -1,5 +1,28 @@
|
|||||||
from langchain import PromptTemplate
|
from langchain import PromptTemplate
|
||||||
|
|
||||||
|
|
||||||
|
general_guidelines_string = '''The code you write is production ready. Every file starts with comments describing what the code is doing before the first import. Comments can only be written within code blocks.
|
||||||
|
Then all imports are listed. It is important to import all modules that could be needed in the Executor code. Always import: from jina import Executor, DocumentArray, Document, requests
|
||||||
|
Start from top-level and then fully implement all methods.'''
|
||||||
|
|
||||||
|
|
||||||
|
not_allowed_docker_string = '''Note that the Dockerfile only has access to the files: microservice.py, requirements.txt, config.yml, test_microservice.py.
|
||||||
|
Note that the Dockerfile runs the test_microservice.py during the build process.
|
||||||
|
The Dockerfile must not attach a virtual display when running test_microservice.py.'''
|
||||||
|
|
||||||
|
|
||||||
|
not_allowed_executor_string = '''The executor and the test must not use the GPU.
|
||||||
|
The executor and the test must not access a database.
|
||||||
|
The executor and the test must not access a display.
|
||||||
|
The executor and the test must not access external apis except unless it is explicitly mentioned in the description or test case (e.g. by mentioning the api that should be used or by providing a URL to access the data).
|
||||||
|
The executor and the test must not load data from the local file system unless it was created by the executor itself.
|
||||||
|
The executor and the test must not use a pre-trained model unless it is explicitly mentioned in the description.
|
||||||
|
The executor and the test must not train a model.
|
||||||
|
The executor and the test must not use any attribute of Document accept Document.text.
|
||||||
|
The executor and the test must not contain prototype or placeholder implementations.
|
||||||
|
The executor and the test must run in a docker container based on debian.'''
|
||||||
|
|
||||||
|
|
||||||
template_generate_microservice_name = PromptTemplate.from_template(
|
template_generate_microservice_name = PromptTemplate.from_template(
|
||||||
'''Generate a name for the executor matching the description:
|
'''Generate a name for the executor matching the description:
|
||||||
"{description}"
|
"{description}"
|
||||||
@@ -29,7 +52,7 @@ b) has a stable api among different versions
|
|||||||
c) does not have system requirements
|
c) does not have system requirements
|
||||||
d) can solve the task when running in a docker container
|
d) can solve the task when running in a docker container
|
||||||
e) the implementation of the core problem using the package would obey the following rules:
|
e) the implementation of the core problem using the package would obey the following rules:
|
||||||
{not_allowed_executor}
|
''' + not_allowed_executor_string() + '''
|
||||||
When answering, just write "yes" or "no".
|
When answering, just write "yes" or "no".
|
||||||
|
|
||||||
5. Output the most suitable 5 python packages starting with the best one.
|
5. Output the most suitable 5 python packages starting with the best one.
|
||||||
@@ -48,12 +71,131 @@ package5
|
|||||||
''')
|
''')
|
||||||
|
|
||||||
|
|
||||||
|
template_code_wrapping_string = '''The code will go into {file_name_purpose}. Make sure to wrap the code into ``` marks even if you only output code:
|
||||||
|
**{file_name}**
|
||||||
|
```{tag_name}
|
||||||
|
...code...
|
||||||
|
```
|
||||||
|
You must provide the complete file with the exact same syntax to wrap the code.'''
|
||||||
|
|
||||||
|
|
||||||
|
template_generate_executor = PromptTemplate.from_template(
|
||||||
|
general_guidelines_string + '''
|
||||||
|
|
||||||
|
Write the executor called '{microservice_name}'. The name is very important to keep.
|
||||||
|
It matches the following description: '{microservice_description}'.
|
||||||
|
It will be tested with the following scenario: '{test}'.
|
||||||
|
For the implementation use the following package: '{package}'.
|
||||||
|
|
||||||
|
Obey the following rules:
|
||||||
|
Have in mind that d.uri is never a path to a local file. It is always a url.
|
||||||
|
''' + not_allowed_executor_string() + '''
|
||||||
|
|
||||||
|
Your approach:
|
||||||
|
1. Identify the core challenge when implementing the executor.
|
||||||
|
2. Think about solutions for these challenges.
|
||||||
|
3. Decide for one of the solutions.
|
||||||
|
4. Write the code.
|
||||||
|
''' + '\n' + template_code_wrapping_string
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
template_generate_test = PromptTemplate.from_template(
|
||||||
|
general_guidelines_string + '''
|
||||||
|
|
||||||
|
{code_files_wrapped}
|
||||||
|
|
||||||
|
Write a single test case that tests the following scenario: '{test}'. In case the test scenario is not precise enough, test a general case without any assumptions.
|
||||||
|
Start the test with an extensive comment about the test case.
|
||||||
|
|
||||||
|
Use the following import to import the executor:
|
||||||
|
```
|
||||||
|
from microservice import {microservice_name}
|
||||||
|
```
|
||||||
|
|
||||||
|
''' + not_allowed_executor_string() + '''
|
||||||
|
The test must not open local files.
|
||||||
|
The test must not mock a function of the executor.
|
||||||
|
The test must not use other data than the one provided in the test scenario.
|
||||||
|
''' + '\n' + template_code_wrapping_string
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
template_generate_requirements = PromptTemplate.from_template(
|
||||||
|
general_guidelines_string + '''
|
||||||
|
|
||||||
|
{code_files_wrapped}
|
||||||
|
|
||||||
|
Write the content of the requirements.txt file. Make sure to include pytest. Make sure that jina==3.14.1.
|
||||||
|
All versions are fixed using ~=, ==, <, >, <=, >=. The package versions must not have conflicts.
|
||||||
|
''' + '\n' + template_code_wrapping_string
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
template_generate_dockerfile = PromptTemplate.from_template(
|
||||||
|
general_guidelines_string + '''
|
||||||
|
|
||||||
|
{code_files_wrapped}
|
||||||
|
|
||||||
|
Write the Dockerfile that defines the environment with all necessary dependencies that the executor uses.
|
||||||
|
It is important to make sure that all libs are installed that are required by the python packages.
|
||||||
|
Usually libraries are installed with apt-get.
|
||||||
|
Be aware that the machine the docker container is running on does not have a GPU - only CPU.
|
||||||
|
Add the config.yml file to the Dockerfile.
|
||||||
|
Note that the Dockerfile only has access to the files: microservice.py, requirements.txt, config.yml, test_microservice.py.
|
||||||
|
The base image of the Dockerfile is FROM jinaai/jina:3.14.1-py39-standard.
|
||||||
|
The entrypoint is ENTRYPOINT ["jina", "executor", "--uses", "config.yml"].
|
||||||
|
Make sure the all files are in the /workdir.
|
||||||
|
The Dockerfile runs the test during the build process.
|
||||||
|
''' + not_allowed_docker_string() + '\n' + template_code_wrapping_string
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
template_is_dependency_issue = PromptTemplate.from_template(
|
||||||
|
'''Your task is to assist in identifying the root cause of a Docker build error for a python application.
|
||||||
|
The error message is as follows:
|
||||||
|
|
||||||
|
{error}
|
||||||
|
|
||||||
|
The docker file is as follows:
|
||||||
|
|
||||||
|
{docker_file}
|
||||||
|
|
||||||
|
Is this a dependency installation failure? Answer with "yes" or "no".'''
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
template_solve_dependency_issue = PromptTemplate.from_template(
|
||||||
|
'''Your task is to provide guidance on how to solve an error that occurred during the Docker build process.
|
||||||
|
The error message is:
|
||||||
|
**microservice.log**
|
||||||
|
```
|
||||||
|
{error}
|
||||||
|
```
|
||||||
|
To solve this error, you should:
|
||||||
|
1. Identify the type of error by examining the stack trace.
|
||||||
|
2. Suggest how to solve it.
|
||||||
|
3. Your suggestion must include the files that need to be changed, but not files that don't need to be changed.
|
||||||
|
For files that need to be changed, you must provide the complete file with the exact same syntax to wrap the code.
|
||||||
|
Obey the following rules:
|
||||||
|
''' + not_allowed_docker_string() + '''
|
||||||
|
|
||||||
|
You are given the following files:
|
||||||
|
|
||||||
|
{all_files_string}
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
template_solve_code_issue = PromptTemplate.from_template(
|
template_solve_code_issue = PromptTemplate.from_template(
|
||||||
'''General rules: {not_allowed_executor}
|
'''General rules:
|
||||||
|
''' + not_allowed_executor_string() + '''
|
||||||
|
|
||||||
Here is the description of the task the executor must solve:
|
Here is the description of the task the executor must solve:
|
||||||
{description}
|
{description}
|
||||||
|
|
||||||
Here is the test scenario the executor must pass:\n{test}
|
Here is the test scenario the executor must pass:
|
||||||
|
{test}
|
||||||
Here are all the files I use:
|
Here are all the files I use:
|
||||||
{all_files_string}
|
{all_files_string}
|
||||||
|
|
||||||
@@ -74,43 +216,8 @@ complete file. Use the exact same syntax to wrap the code:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
template_solve_dependency_issue = PromptTemplate.from_template(
|
|
||||||
'''Your task is to provide guidance on how to solve an error that occurred during the Docker build process.
|
|
||||||
The error message is:
|
|
||||||
**microservice.log**
|
|
||||||
```
|
|
||||||
{error}
|
|
||||||
```
|
|
||||||
To solve this error, you should:
|
|
||||||
1. Identify the type of error by examining the stack trace.
|
|
||||||
2. Suggest how to solve it.
|
|
||||||
3. Your suggestion must include the files that need to be changed, but not files that don't need to be changed.
|
|
||||||
For files that need to be changed, you must provide the complete file with the exact same syntax to wrap the code.
|
|
||||||
Obey the following rules: {not_allowed_docker}
|
|
||||||
|
|
||||||
You are given the following files:
|
|
||||||
|
|
||||||
{all_files_string}
|
|
||||||
'''
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
template_is_dependency_issue = PromptTemplate.from_template(
|
|
||||||
'''Your task is to assist in identifying the root cause of a Docker build error for a python application.
|
|
||||||
The error message is as follows:
|
|
||||||
|
|
||||||
{error}
|
|
||||||
|
|
||||||
The docker file is as follows:
|
|
||||||
|
|
||||||
{docker_file}
|
|
||||||
|
|
||||||
Is this a dependency installation failure? Answer with "yes" or "no".'''
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
template_generate_playground = PromptTemplate.from_template(
|
template_generate_playground = PromptTemplate.from_template(
|
||||||
'''{general_guidelines}
|
general_guidelines_string + '''
|
||||||
|
|
||||||
{code_files_wrapped}
|
{code_files_wrapped}
|
||||||
|
|
||||||
@@ -130,3 +237,14 @@ The playground (app.py) must read the host from sys.argv because it will be star
|
|||||||
The playground (app.py) must not let the user configure the host on the ui.
|
The playground (app.py) must not let the user configure the host on the ui.
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
template_chain_of_thought = PromptTemplate.from_template(
|
||||||
|
'''First, write down an extensive list of obvious and non-obvious observations about {file_name_purpose} that could need an adjustment. Explain why.
|
||||||
|
Think if all the changes are required and finally decide for the changes you want to make, but you are not allowed disregard the instructions in the previous message.
|
||||||
|
Be very hesitant to change the code. Only make a change if you are sure that it is necessary.
|
||||||
|
|
||||||
|
Output only {file_name_purpose}
|
||||||
|
Write the whole content of {file_name_purpose} - even if you decided to change only a small thing or even nothing.
|
||||||
|
''' + '\n' + template_code_wrapping_string
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user