diff --git a/.gitignore b/.gitignore index 80e54f9..fb67c78 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /executor_level2/ + +.env \ No newline at end of file diff --git a/README.md b/README.md index b7b9b07..8988274 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ Use natural language interface to create, deploy and update your microservice in # TODO critical -- [ ] auto login for jina +- [x] auto login for jina Nice to have - [ ] verbose mode diff --git a/main.py b/main.py index cd5c586..f3cce91 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ import random import click from src import gpt, jina_cloud -from src.jina_cloud import push_executor, process_error_message +from src.jina_cloud import push_executor, process_error_message, jina_auth_login from src.prompt_tasks import general_guidelines, executor_file_task, chain_of_thought_creation, test_executor_file_task, \ chain_of_thought_optimization, requirements_file_task, docker_file_task, not_allowed from src.utils.io import recreate_folder, persist_file @@ -290,6 +290,9 @@ def main( num_approaches=3, output_path='executor', ): + jina_auth_login() + + generated_name = generate_executor_name(description) executor_name = f'{generated_name}{random.randint(0, 1000_000)}' diff --git a/requirements.txt b/requirements.txt index 32d0471..57552b8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ jina==3.14.1 click==8.1.3 -streamlit==1.20.0 \ No newline at end of file +streamlit==1.20.0 +openai==0.27.4 \ No newline at end of file diff --git a/src/jina_cloud.py b/src/jina_cloud.py index a007561..feb0d9a 100644 --- a/src/jina_cloud.py +++ b/src/jina_cloud.py @@ -1,17 +1,30 @@ import hashlib import json import os -import subprocess import re -from argparse import Namespace +import subprocess +import webbrowser from pathlib import Path import hubble from hubble.executor.helper import upload_file, archive_package, get_request_header from jcloud.flow import CloudFlow -from jina import Flow +def redirect_callback(href): + print( + f'You need login to Jina first to use GPTDeploy\n' + f'Please open this link if it does not open automatically in your browser: {href}' + ) + webbrowser.open(href, new=0, autoraise=True) + + +def jina_auth_login(): + try: + hubble.Client(jsonify=True).get_user_info(log_error=False) + except hubble.AuthenticationRequiredError: + hubble.login(prompt='login', redirect_callback=redirect_callback) + def push_executor(dir_path): dir_path = Path(dir_path) @@ -66,7 +79,6 @@ def deploy_on_jcloud(flow_yaml): return cloud_flow.__enter__().endpoints['gateway'] - def deploy_flow(executor_name, dest_folder): flow = f''' jtype: Flow @@ -90,7 +102,7 @@ executors: capacity: spot ''' full_flow_path = os.path.join(dest_folder, - 'flow.yml') + 'flow.yml') with open(full_flow_path, 'w') as f: f.write(flow) @@ -110,13 +122,13 @@ def replace_client_line(file_content: str, replacement: str) -> str: break return '\n'.join(lines) + def update_client_line_in_file(file_path, host): with open(file_path, 'r') as file: content = file.read() replaced_content = replace_client_line(content, f"client = Client(host='{host}')") - with open(file_path, 'w') as file: file.write(replaced_content) @@ -137,9 +149,8 @@ def process_error_message(error_message): return '\n'.join(relevant_lines[-25:]) + def build_docker(path): - - # The command to build the Docker image cmd = f"docker build -t micromagic {path}" @@ -155,4 +166,3 @@ def build_docker(path): else: print("Docker build completed successfully.") return '' -