feat: server

This commit is contained in:
Florian Hönicke
2023-03-19 21:02:07 +01:00
parent 61ef41f073
commit 45b709ed15
8 changed files with 198 additions and 51 deletions

View File

@@ -1,36 +1,51 @@
from src.constants import EXECUTOR_FILE_NAME, REQUIREMENTS_FILE_NAME, TEST_EXECUTOR_FILE_NAME, DOCKER_FILE_NAME, \
DOCKER_FILE_TAG
DOCKER_FILE_TAG, CLIENT_FILE_TAG, CLIENT_FILE_NAME
general_guidelines = (
"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 between tags. "
"Start from top-level and then fully implement all methods."
)
def general_guidelines():
return (
"General guidelines: "
"The code you write is production ready. "
"Every file starts with comments describing what the code is doing before the first import. "
"Then all imports are listed. It is important to import all modules that could be needed in the executor code."
"Comments can only be written between tags. "
"Start from top-level and then fully implement all methods. "
"\n"
)
def _task(task, tag_name, file_name):
return task + f"The code will go into {file_name}. Wrap the code in the string $$$start_{tag_name}$$$...$$$end_{tag_name}$$$ "
return task + f"The code will go into {file_name}. Wrap the code in the string $$$start_{tag_name}$$$...$$$end_{tag_name}$$$ \n\n"
def executor_file_task():
return _task("Write the executor code. ", 'executor', EXECUTOR_FILE_NAME)
def executor_file_task(executor_name, input_executor_description, input_modality, input_doc_field,
output_modality, output_doc_field):
return _task(
f"Write the executor called '{executor_name}'. "
f"It matches the following description: '{input_executor_description}'. "
f"It gets a DocumentArray as input where each document has the input modality '{input_modality}' that is stored in document.{input_doc_field}. "
f"It returns a DocumentArray as output where each document has the output modality '{output_modality}' that is stored in document.{output_doc_field}. ",
'executor',
EXECUTOR_FILE_NAME
)
def requirements_file_task():
return _task("Write the content of the requirements.txt file. "
"Make sure to include pytest. "
"All versions are fixed. " , 'requirements',
"All versions are fixed. ", 'requirements',
REQUIREMENTS_FILE_NAME)
def test_executor_file_task(executor_name):
def test_executor_file_task(executor_name, input_test_in, input_test_out):
return _task(
"Write a small unit test for the executor. "
"Start the test with an extensive comment about the test case. "
"Use the following import to import the executor: "
f"from executor import {executor_name}",
+ (
"Test that the executor converts the input '" + input_test_in + "' to the output '" + input_test_out + "'. "
) if input_test_in and input_test_out else ""
"Use the following import to import the executor: "
f"from executor import {executor_name} ",
'test_executor',
TEST_EXECUTOR_FILE_NAME
)
@@ -48,3 +63,9 @@ def docker_file_task():
"The Dockerfile runs the test during the build process. "
, DOCKER_FILE_TAG, DOCKER_FILE_NAME)
def client_file_task():
return _task(
"Write the client file. "
, CLIENT_FILE_TAG, CLIENT_FILE_NAME
)