mirror of
https://github.com/aljazceru/dev-gpt.git
synced 2025-12-21 15:44:19 +01:00
feat: auth
This commit is contained in:
@@ -13,6 +13,7 @@ from hubble.executor.helper import upload_file, archive_package, get_request_hea
|
|||||||
from jcloud.flow import CloudFlow
|
from jcloud.flow import CloudFlow
|
||||||
from jina import Flow
|
from jina import Flow
|
||||||
|
|
||||||
|
from src.constants import DEMO_TOKEN
|
||||||
from src.utils.io import suppress_stdout, is_docker_running
|
from src.utils.io import suppress_stdout, is_docker_running
|
||||||
from src.utils.string_tools import print_colored
|
from src.utils.string_tools import print_colored
|
||||||
|
|
||||||
@@ -75,18 +76,21 @@ def push_executor(dir_path):
|
|||||||
'md5sum': md5_digest,
|
'md5sum': md5_digest,
|
||||||
}
|
}
|
||||||
with suppress_stdout():
|
with suppress_stdout():
|
||||||
req_header = get_request_header()
|
headers = get_request_header()
|
||||||
|
headers['Authorization'] = f'token {DEMO_TOKEN}'
|
||||||
|
|
||||||
resp = upload_file(
|
resp = upload_file(
|
||||||
'https://api.hubble.jina.ai/v2/rpc/executor.push',
|
'https://api.hubble.jina.ai/v2/rpc/executor.push',
|
||||||
'filename',
|
'filename',
|
||||||
content,
|
content,
|
||||||
dict_data=form_data,
|
dict_data=form_data,
|
||||||
headers=req_header,
|
headers=headers,
|
||||||
stream=False,
|
stream=False,
|
||||||
method='post',
|
method='post',
|
||||||
)
|
)
|
||||||
json_lines_str = resp.content.decode('utf-8')
|
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:
|
if 'exited on non-zero code' not in json_lines_str:
|
||||||
return ''
|
return ''
|
||||||
responses = []
|
responses = []
|
||||||
@@ -103,8 +107,8 @@ def push_executor(dir_path):
|
|||||||
return '\n'.join(responses)
|
return '\n'.join(responses)
|
||||||
|
|
||||||
|
|
||||||
def get_user_name():
|
def get_user_name(token=None):
|
||||||
client = hubble.Client(max_retries=None, jsonify=True, token='45372338e04f5a41af949024db929d46')
|
client = hubble.Client(max_retries=None, jsonify=True, token=token)
|
||||||
response = client.get_user_info()
|
response = client.get_user_info()
|
||||||
return response['data']['name']
|
return response['data']['name']
|
||||||
|
|
||||||
@@ -190,7 +194,7 @@ jcloud:
|
|||||||
|
|
||||||
executors:
|
executors:
|
||||||
- name: {executor_name.lower()}
|
- 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"}
|
{"" if use_docker else "install-requirements: True"}
|
||||||
jcloud:
|
jcloud:
|
||||||
resources:
|
resources:
|
||||||
|
|||||||
@@ -29,4 +29,6 @@ PRICING_GPT3_5_TURBO_PROMPT = 0.002
|
|||||||
PRICING_GPT3_5_TURBO_GENERATION = 0.002
|
PRICING_GPT3_5_TURBO_GENERATION = 0.002
|
||||||
|
|
||||||
NUM_IMPLEMENTATION_STRATEGIES = 3
|
NUM_IMPLEMENTATION_STRATEGIES = 3
|
||||||
MAX_DEBUGGING_ITERATIONS = 10
|
MAX_DEBUGGING_ITERATIONS = 10
|
||||||
|
|
||||||
|
DEMO_TOKEN = '45372338e04f5a41af949024db929d46'
|
||||||
@@ -206,6 +206,7 @@ print(response[0].text) # can also be blob in case of image/audio..., this shoul
|
|||||||
error_before = error
|
error_before = error
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
print('Successfully build microservice.')
|
||||||
break
|
break
|
||||||
if i == MAX_DEBUGGING_ITERATIONS - 1:
|
if i == MAX_DEBUGGING_ITERATIONS - 1:
|
||||||
raise self.MaxDebugTimeReachedException('Could not debug the microservice.')
|
raise self.MaxDebugTimeReachedException('Could not debug the microservice.')
|
||||||
|
|||||||
Reference in New Issue
Block a user