fix: prompts

This commit is contained in:
Florian Hönicke
2023-03-17 15:50:48 +01:00
parent c96d85166f
commit bd125365c0

41
main.py
View File

@@ -1,4 +1,5 @@
import os
import shutil
import openai
from docarray import DocumentArray, Document
@@ -22,8 +23,11 @@ response = openai.ChatCompletion.create(
"role": "system",
"content": "You are a principal engineer working at Jina - an open source company."
"Using the Jina framework, users can define executors."
"Here is an example of how an executor can be defined:"
"Here is an example of how an executor can be defined. It always starts with a comment:"
'''
# this executor takes ... as input and returns ... as output
# it processes each document in the following way: ...
from jina import Executor, requests, DocumentArray, Document, Deployment
class MyExecutor(Executor):
def __init__(self, **kwargs):
super().__init__()
@@ -34,10 +38,6 @@ response = openai.ChatCompletion.create(
d.text = 'hello world'"
return docs
'''
"these imports are needed:"
'''
from jina import Executor, requests, DocumentArray, Document, Deployment
'''
"An executor gets a DocumentArray as input and returns a DocumentArray as output."
"Here is an example of how a DocumentArray can be defined:"
'''
@@ -65,15 +65,18 @@ response = openai.ChatCompletion.create(
executor_description
+ "The code you write is production ready. Every file starts with a 5 sentence comment of what the code is doing before the first import. Start from top-level and then fully implement all methods."
"First, write the executor name. (wrap the code in the string $$$start_executor_name$$$...$$$end_executor_name$$$) "
"The executor name only consists of lower case and upper case letters. "
"Then, write the executor code. (wrap the code in the string $$$start_executor$$$ ... $$$end_executor$$$)"
"In addition write the content of the requirements.txt file. Make sure to include pytest. (wrap the code in the string $$$start_requirements$$$ ... $$$end_requirements$$$)"
"Then write a small unit test for the executor. (wrap the code in the string $$$start_test_executor$$$ ... $$$end_test_executor$$$)"
"Then write a small unit test for the executor. Start the test with an extensive comment about the test case (wrap the code in the string $$$start_test_executor$$$ ... $$$end_test_executor$$$)"
# "the snipped should take the local file wolf.obj as input and save the output as png files. "
+ test_description
+ "Finally write the Dockerfile that defines the environment with all necessary dependencies which the executor uses. "
+ "Finally 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. "
"The base image of the Dockerfile is FROM jinaai/jina:3.14.2-dev18-py310-standard. "
"The Dockerfile runs the test during the build process (wrap the code in the string $$$start_dockerfile$$$ ... $$$end_dockerfile$$$)"
'The entrypoint is ENTRYPOINT ["jina", "executor", "--uses", "config.yml"]'
# "The Dockerfile runs the test during the build process. "
"(wrap the code in the string $$$start_dockerfile$$$ ... $$$end_dockerfile$$$)"
},
]
@@ -94,14 +97,27 @@ def find_between(input_string, start, end):
def clean_content(content):
return content.replace('```', '').strip()
executor_name = find_between(plain_text, f'$$$start_executor_name$$$', f'$$$end_executor_name$$$').strip()
executor_name = find_between(plain_text, f'$$$start_executor_name$$$', f'$$$end_executor_name$$$').replace('#', '').strip()
# delete folder and recreate it
def recreate_folder(folder_path):
# Check if the folder exists
if os.path.exists(folder_path) and os.path.isdir(folder_path):
# Delete the folder if it exists
shutil.rmtree(folder_path)
# Create the folder
os.makedirs(folder_path)
folder = 'executor'
recreate_folder(folder)
for tag, file_name in [['executor', f'{executor_name}.py'], ['requirements', 'requirements.txt'], ['test_executor', 'test_OCRDetectorExecutor.py'], ['dockerfile', 'Dockerfile']]:
content = find_between(plain_text, f'$$$start_{tag}$$$', f'$$$end_{tag}$$$')
clean = clean_content(content)
folder = 'executor'
full_path = os.path.join(folder, file_name)
os.makedirs(folder, exist_ok=True)
with open(full_path, 'w') as f:
f.write(clean)
@@ -147,11 +163,12 @@ full_flow_path = os.path.join('executor', 'flow.yml')
with open(full_flow_path, 'w') as f:
f.write(flow)
exit(0)
cloud_flow = CloudFlow(path=full_flow_path).__enter__()
host = cloud_flow.endpoints['gateway']
client = Client(host=host)
d = Document(uri='https://double-rhyme.com/logo_en_white2.png')
d = Document(uri='data/txt.png')
d.load_uri_to_blob()
response = client.post('/index', inputs=DocumentArray([d]))
response[0].summary()