Merge pull request #3 from jina-ai/feat-auto-login-jina

Feat auto login jina
This commit is contained in:
Florian Hönicke
2023-04-07 01:07:35 +02:00
committed by GitHub
5 changed files with 28 additions and 12 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
/executor_level2/
.env

View File

@@ -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

View File

@@ -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)}'

View File

@@ -1,3 +1,4 @@
jina==3.14.1
click==8.1.3
streamlit==1.20.0
openai==0.27.4

View File

@@ -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
@@ -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 ''