feat: frontend

This commit is contained in:
Florian Hönicke
2023-03-20 00:34:25 +01:00
parent 45b709ed15
commit 0116449082
12 changed files with 414 additions and 198 deletions

View File

@@ -1,3 +1,4 @@
import asyncio
import os
from multiprocessing.connection import Client
@@ -18,7 +19,15 @@ def get_user_name():
return response['data']['name']
def deploy_flow(executor_name):
async def deploy_on_jcloud(flow_yaml):
cloud_flow = CloudFlow(path=flow_yaml)
await cloud_flow.__aenter__()
return cloud_flow.endpoints['gateway']
async def deploy_flow(executor_name, do_validation):
flow = f'''
jtype: Flow
with:
@@ -44,12 +53,14 @@ executors:
with open(full_flow_path, 'w') as f:
f.write(flow)
# try local first
flow = Flow.load_config(full_flow_path)
with flow:
pass
if do_validation:
print('try local execution')
flow = Flow.load_config(full_flow_path)
with flow:
pass
print('deploy flow on jcloud')
return await deploy_on_jcloud(flow_yaml=full_flow_path)
return CloudFlow(path=full_flow_path).__enter__().endpoints['gateway']
def replace_client_line(file_content: str, replacement: str) -> str:
lines = file_content.split('\n')
@@ -59,7 +70,7 @@ def replace_client_line(file_content: str, replacement: str) -> str:
break
return '\n'.join(lines)
def run_client_file(file_path, host):
def run_client_file(file_path, host, do_validation):
with open(file_path, 'r') as file:
content = file.read()
@@ -69,4 +80,5 @@ def run_client_file(file_path, host):
with open(file_path, 'w') as file:
file.write(replaced_content)
import executor.client # runs the client script for validation
if do_validation:
import executor.client # runs the client script for validation

View File

@@ -39,7 +39,7 @@ message DocumentProto {
string text = 4;
}
// a uri of the document could be: a local file path, a remote url starts with http or https or data URI scheme
// a uri of the document is a remote url starts with http or https or data URI scheme
string uri = 5;
// list of the sub-documents of this document (recursive structure)
@@ -65,11 +65,12 @@ d1 = Document(text='hello')
d2 = Document(blob=b'\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR\\x00\\x00\\x03L\\x00\\x00\\x01\\x18\\x08\\x06\\x00\\x00\\x00o...')
d3 = Document(tensor=numpy.array([1, 2, 3]), chunks=[Document(uri=/local/path/to/file)]
d4 = Document(
uri='https://docs.docarray.org',
uri='https://docs.docarray.org/img/logo.png',
tags={'foo': 'bar'},
)
d5 = Document()
d5.tensor = np.ones((2,4))
d5.uri = 'https://audio.com/audio.mp3'
d6 = Document()
d6.blob = b'RIFF\\x00\\x00\\x00\\x00WAVEfmt \\x10\\x00...'
docs = DocumentArray([

View File

@@ -7,7 +7,9 @@ def general_guidelines():
"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."
"Then all imports are listed. "
"It is important to import all modules that could be needed in the executor code. "
"Always import BytesIO from io. "
"Comments can only be written between tags. "
"Start from top-level and then fully implement all methods. "
"\n"
@@ -18,13 +20,14 @@ 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}$$$ \n\n"
def executor_file_task(executor_name, input_executor_description, input_modality, input_doc_field,
def executor_file_task(executor_name, 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 matches the following description: '{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}. ",
f"It returns a DocumentArray as output where each document has the output modality '{output_modality}' that is stored in document.{output_doc_field}. "
f"Have in mind that d.uri is never a path to a local file. It is always a url.",
'executor',
EXECUTOR_FILE_NAME
)
@@ -37,13 +40,13 @@ def requirements_file_task():
REQUIREMENTS_FILE_NAME)
def test_executor_file_task(executor_name, input_test_in, input_test_out):
def test_executor_file_task(executor_name, test_in, test_out):
return _task(
"Write a small unit test for the executor. "
"Start the test with an extensive comment about the test case. "
+ (
"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 ""
"Test that the executor converts the input '" + test_in + "' to the output '" + test_out + "'. "
) if test_in and test_out else ""
"Use the following import to import the executor: "
f"from executor import {executor_name} ",
'test_executor',