mirror of
https://github.com/aljazceru/dev-gpt.git
synced 2025-12-24 00:54:19 +01:00
Merge pull request #3 from jina-ai/feat-auto-login-jina
Feat auto login jina
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
|||||||
/executor_level2/
|
/executor_level2/
|
||||||
|
|
||||||
|
.env
|
||||||
@@ -78,7 +78,7 @@ Use natural language interface to create, deploy and update your microservice in
|
|||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
critical
|
critical
|
||||||
- [ ] auto login for jina
|
- [x] auto login for jina
|
||||||
|
|
||||||
Nice to have
|
Nice to have
|
||||||
- [ ] verbose mode
|
- [ ] verbose mode
|
||||||
|
|||||||
5
main.py
5
main.py
@@ -3,7 +3,7 @@ import random
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
from src import gpt, jina_cloud
|
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, \
|
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
|
chain_of_thought_optimization, requirements_file_task, docker_file_task, not_allowed
|
||||||
from src.utils.io import recreate_folder, persist_file
|
from src.utils.io import recreate_folder, persist_file
|
||||||
@@ -290,6 +290,9 @@ def main(
|
|||||||
num_approaches=3,
|
num_approaches=3,
|
||||||
output_path='executor',
|
output_path='executor',
|
||||||
):
|
):
|
||||||
|
jina_auth_login()
|
||||||
|
|
||||||
|
|
||||||
generated_name = generate_executor_name(description)
|
generated_name = generate_executor_name(description)
|
||||||
executor_name = f'{generated_name}{random.randint(0, 1000_000)}'
|
executor_name = f'{generated_name}{random.randint(0, 1000_000)}'
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
jina==3.14.1
|
jina==3.14.1
|
||||||
click==8.1.3
|
click==8.1.3
|
||||||
streamlit==1.20.0
|
streamlit==1.20.0
|
||||||
|
openai==0.27.4
|
||||||
@@ -1,17 +1,30 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
import re
|
import re
|
||||||
from argparse import Namespace
|
import subprocess
|
||||||
|
import webbrowser
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import hubble
|
import hubble
|
||||||
from hubble.executor.helper import upload_file, archive_package, get_request_header
|
from hubble.executor.helper import upload_file, archive_package, get_request_header
|
||||||
from jcloud.flow import CloudFlow
|
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):
|
def push_executor(dir_path):
|
||||||
dir_path = Path(dir_path)
|
dir_path = Path(dir_path)
|
||||||
@@ -66,7 +79,6 @@ def deploy_on_jcloud(flow_yaml):
|
|||||||
return cloud_flow.__enter__().endpoints['gateway']
|
return cloud_flow.__enter__().endpoints['gateway']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def deploy_flow(executor_name, dest_folder):
|
def deploy_flow(executor_name, dest_folder):
|
||||||
flow = f'''
|
flow = f'''
|
||||||
jtype: Flow
|
jtype: Flow
|
||||||
@@ -110,13 +122,13 @@ def replace_client_line(file_content: str, replacement: str) -> str:
|
|||||||
break
|
break
|
||||||
return '\n'.join(lines)
|
return '\n'.join(lines)
|
||||||
|
|
||||||
|
|
||||||
def update_client_line_in_file(file_path, host):
|
def update_client_line_in_file(file_path, host):
|
||||||
with open(file_path, 'r') as file:
|
with open(file_path, 'r') as file:
|
||||||
content = file.read()
|
content = file.read()
|
||||||
|
|
||||||
replaced_content = replace_client_line(content, f"client = Client(host='{host}')")
|
replaced_content = replace_client_line(content, f"client = Client(host='{host}')")
|
||||||
|
|
||||||
|
|
||||||
with open(file_path, 'w') as file:
|
with open(file_path, 'w') as file:
|
||||||
file.write(replaced_content)
|
file.write(replaced_content)
|
||||||
|
|
||||||
@@ -137,9 +149,8 @@ def process_error_message(error_message):
|
|||||||
|
|
||||||
return '\n'.join(relevant_lines[-25:])
|
return '\n'.join(relevant_lines[-25:])
|
||||||
|
|
||||||
|
|
||||||
def build_docker(path):
|
def build_docker(path):
|
||||||
|
|
||||||
|
|
||||||
# The command to build the Docker image
|
# The command to build the Docker image
|
||||||
cmd = f"docker build -t micromagic {path}"
|
cmd = f"docker build -t micromagic {path}"
|
||||||
|
|
||||||
@@ -155,4 +166,3 @@ def build_docker(path):
|
|||||||
else:
|
else:
|
||||||
print("Docker build completed successfully.")
|
print("Docker build completed successfully.")
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user