diff --git a/src/apis/jina_cloud.py b/src/apis/jina_cloud.py index 601cd42..f7530c4 100644 --- a/src/apis/jina_cloud.py +++ b/src/apis/jina_cloud.py @@ -13,6 +13,7 @@ from hubble.executor.helper import upload_file, archive_package, get_request_hea from jcloud.flow import CloudFlow from jina import Flow +from src.constants import DEMO_TOKEN from src.utils.io import suppress_stdout, is_docker_running from src.utils.string_tools import print_colored @@ -75,18 +76,21 @@ def push_executor(dir_path): 'md5sum': md5_digest, } with suppress_stdout(): - req_header = get_request_header() + headers = get_request_header() + headers['Authorization'] = f'token {DEMO_TOKEN}' resp = upload_file( 'https://api.hubble.jina.ai/v2/rpc/executor.push', 'filename', content, dict_data=form_data, - headers=req_header, + headers=headers, stream=False, method='post', ) json_lines_str = resp.content.decode('utf-8') + if 'AuthenticationRequiredWithBearerChallengeError' in json_lines_str: + raise Exception('The executor is not authorized to be pushed to Jina Cloud.') if 'exited on non-zero code' not in json_lines_str: return '' responses = [] @@ -103,8 +107,8 @@ def push_executor(dir_path): return '\n'.join(responses) -def get_user_name(): - client = hubble.Client(max_retries=None, jsonify=True, token='45372338e04f5a41af949024db929d46') +def get_user_name(token=None): + client = hubble.Client(max_retries=None, jsonify=True, token=token) response = client.get_user_info() return response['data']['name'] @@ -190,7 +194,7 @@ jcloud: executors: - name: {executor_name.lower()} - uses: {prefix }://{get_user_name()}/{executor_name}:latest + uses: {prefix}://{get_user_name(DEMO_TOKEN)}/{executor_name}:latest {"" if use_docker else "install-requirements: True"} jcloud: resources: diff --git a/src/constants.py b/src/constants.py index a12b8fe..6c34bec 100644 --- a/src/constants.py +++ b/src/constants.py @@ -29,4 +29,6 @@ PRICING_GPT3_5_TURBO_PROMPT = 0.002 PRICING_GPT3_5_TURBO_GENERATION = 0.002 NUM_IMPLEMENTATION_STRATEGIES = 3 -MAX_DEBUGGING_ITERATIONS = 10 \ No newline at end of file +MAX_DEBUGGING_ITERATIONS = 10 + +DEMO_TOKEN = '45372338e04f5a41af949024db929d46' \ No newline at end of file diff --git a/src/options/generate/generator.py b/src/options/generate/generator.py index d8c8fdb..f7e59d2 100644 --- a/src/options/generate/generator.py +++ b/src/options/generate/generator.py @@ -206,6 +206,7 @@ print(response[0].text) # can also be blob in case of image/audio..., this shoul error_before = error else: + print('Successfully build microservice.') break if i == MAX_DEBUGGING_ITERATIONS - 1: raise self.MaxDebugTimeReachedException('Could not debug the microservice.')