mirror of
https://github.com/OMGeeky/gpt-pilot.git
synced 2026-02-23 15:49:50 +01:00
#131 if process_name is specified to execute_command() keep the process alive
This commit is contained in:
40
pilot/utils/custom_print.py
Normal file
40
pilot/utils/custom_print.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import builtins
|
||||
from helpers.ipc import IPCClient
|
||||
from const.ipc import MESSAGE_TYPE
|
||||
|
||||
|
||||
def get_custom_print(args):
|
||||
built_in_print = builtins.print
|
||||
|
||||
def print_to_external_process(*args, **kwargs):
|
||||
# message = " ".join(map(str, args))
|
||||
message = args[0]
|
||||
|
||||
if 'type' not in kwargs:
|
||||
kwargs['type'] = 'verbose'
|
||||
elif kwargs['type'] == MESSAGE_TYPE['local']:
|
||||
local_print(*args, **kwargs)
|
||||
return
|
||||
|
||||
ipc_client_instance.send({
|
||||
'type': MESSAGE_TYPE[kwargs['type']],
|
||||
'content': message,
|
||||
})
|
||||
if kwargs['type'] == MESSAGE_TYPE['user_input_request']:
|
||||
return ipc_client_instance.listen()
|
||||
|
||||
def local_print(*args, **kwargs):
|
||||
message = " ".join(map(str, args))
|
||||
if 'type' in kwargs:
|
||||
if kwargs['type'] == MESSAGE_TYPE['info']:
|
||||
return
|
||||
del kwargs['type']
|
||||
|
||||
built_in_print(message, **kwargs)
|
||||
|
||||
ipc_client_instance = None
|
||||
if '--external-log-process-port' in args:
|
||||
ipc_client_instance = IPCClient(args['--external-log-process-port'])
|
||||
return print_to_external_process, ipc_client_instance
|
||||
else:
|
||||
return local_print, ipc_client_instance
|
||||
@@ -3,6 +3,7 @@ import os
|
||||
import hashlib
|
||||
import requests
|
||||
|
||||
from helpers.cli import terminate_running_processes
|
||||
from utils.questionary import get_user_feedback
|
||||
|
||||
|
||||
@@ -43,6 +44,7 @@ def get_path_id():
|
||||
|
||||
|
||||
def exit_gpt_pilot(ask_feedback=True):
|
||||
terminate_running_processes()
|
||||
path_id = get_path_id()
|
||||
send_telemetry(path_id)
|
||||
|
||||
|
||||
@@ -262,7 +262,8 @@ def stream_gpt_completion(data, req_type, project):
|
||||
model = os.getenv('MODEL_NAME', 'gpt-4')
|
||||
endpoint = os.getenv('ENDPOINT')
|
||||
|
||||
logger.info(f'> Request model: {model} ({data["model"]}) messages: {data["messages"]}')
|
||||
logger.info(f'> Request model: {model} ({data["model"]})\n'
|
||||
+ '\n'.join([f"{message['role']}: {message['content']}" for message in data['messages']]))
|
||||
|
||||
if endpoint == 'AZURE':
|
||||
# If yes, get the AZURE_ENDPOINT from .ENV file
|
||||
|
||||
Reference in New Issue
Block a user