mirror of
https://github.com/OMGeeky/gpt-pilot.git
synced 2025-12-29 07:35:44 +01:00
Enabled getting user input from the external process
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
from fabulous.color import bold, green, yellow
|
||||
from termcolor import colored
|
||||
from const.common import IGNORE_FOLDERS
|
||||
from database.models.app import App
|
||||
@@ -57,11 +58,10 @@ class Project:
|
||||
if '--external-log-process' in args:
|
||||
self.ipc_client_instance = IPCClient()
|
||||
|
||||
print('..'*20)
|
||||
self.log('\n------------------ STARTING NEW PROJECT ----------------------', 'verbose')
|
||||
self.log(green(bold('\n------------------ STARTING NEW PROJECT ----------------------')), 'verbose')
|
||||
self.log(f"If you wish to continue with this project in future run:", 'verbose')
|
||||
self.log(f'python main.py app_id={args["app_id"]}', 'verbose')
|
||||
self.log('--------------------------------------------------------------\n', 'verbose')
|
||||
self.log(green(bold(f'python main.py app_id={args["app_id"]}')), 'verbose')
|
||||
self.log(green(bold('--------------------------------------------------------------\n')), 'verbose')
|
||||
|
||||
def start(self):
|
||||
self.project_manager = ProductOwner(self)
|
||||
@@ -193,9 +193,9 @@ class Project:
|
||||
delete_unconnected_steps_from(self.checkpoints['last_user_input'], 'previous_step')
|
||||
|
||||
def ask_for_human_intervention(self, message, description=None, cbs={}):
|
||||
print(colored(message, "yellow", attrs=['bold']))
|
||||
self.log(yellow(bold(message)))
|
||||
if description is not None:
|
||||
print(description)
|
||||
self.log(description)
|
||||
answer = ''
|
||||
while answer != 'continue':
|
||||
answer = styled_text(
|
||||
@@ -208,7 +208,7 @@ class Project:
|
||||
elif answer != '':
|
||||
return answer
|
||||
|
||||
def log(self, text, message_type, cb=None):
|
||||
def log(self, text, message_type):
|
||||
if self.ipc_client_instance is None or self.ipc_client_instance.client is None:
|
||||
print(text)
|
||||
else:
|
||||
@@ -216,5 +216,5 @@ class Project:
|
||||
'type': MESSAGE_TYPE[message_type],
|
||||
'content': str(text),
|
||||
})
|
||||
if cb is not None:
|
||||
self.ipc_client_instance.listen(lambda response: cb(response['content']))
|
||||
if message_type == MESSAGE_TYPE['user_input_request']:
|
||||
return self.ipc_client_instance.listen()
|
||||
@@ -1,4 +1,5 @@
|
||||
from termcolor import colored
|
||||
from fabulous.color import bold, green, yellow
|
||||
|
||||
from helpers.AgentConvo import AgentConvo
|
||||
from helpers.Agent import Agent
|
||||
@@ -43,7 +44,7 @@ class ProductOwner(Agent):
|
||||
self.project,
|
||||
generate_messages_from_description(main_prompt, self.project.args['app_type'], self.project.args['name']))
|
||||
|
||||
print(colored('Project Summary:\n', 'green', attrs=['bold']))
|
||||
self.project.log(green(bold('Project Summary:\n')))
|
||||
high_level_summary = convo_project_description.send_message('utils/summary.prompt',
|
||||
{'conversation': '\n'.join([f"{msg['role']}: {msg['content']}" for msg in high_level_messages])})
|
||||
|
||||
@@ -73,7 +74,7 @@ class ProductOwner(Agent):
|
||||
|
||||
# USER STORIES
|
||||
msg = f"User Stories:\n"
|
||||
print(colored(msg, "green", attrs=['bold']))
|
||||
self.project.log(green(bold(msg)))
|
||||
logger.info(msg)
|
||||
|
||||
self.project.user_stories = self.convo_user_stories.continuous_conversation('user_stories/specs.prompt', {
|
||||
@@ -107,7 +108,7 @@ class ProductOwner(Agent):
|
||||
|
||||
# USER TASKS
|
||||
msg = f"User Tasks:\n"
|
||||
print(colored(msg, "green", attrs=['bold']))
|
||||
self.project.log(green(bold(msg)))
|
||||
logger.info(msg)
|
||||
|
||||
self.project.user_tasks = self.convo_user_stories.continuous_conversation('user_stories/user_tasks.prompt',
|
||||
|
||||
@@ -20,31 +20,18 @@ class IPCClient:
|
||||
print(f"Received request from the external process: {message_content}")
|
||||
return message_content # For demonstration, we're just echoing back the content
|
||||
|
||||
def listen(self, cb):
|
||||
def listen(self):
|
||||
if self.client is None:
|
||||
print("Not connected to the external process!")
|
||||
return
|
||||
try:
|
||||
while True:
|
||||
data = self.client.recv(4096)
|
||||
message = json.loads(data)
|
||||
|
||||
if message['type'] == 'request':
|
||||
cb(message['content'])
|
||||
if message['type'] == 'request':
|
||||
response_content = self.handle_request(message['content'])
|
||||
response = {
|
||||
'type': 'response',
|
||||
'content': response_content
|
||||
}
|
||||
self.client.sendall(json.dumps(response).encode('utf-8'))
|
||||
time.sleep(0.1)
|
||||
while True:
|
||||
data = self.client.recv(4096)
|
||||
message = json.loads(data)
|
||||
|
||||
serialized_data = json.dumps(data)
|
||||
self.client.sendall(serialized_data.encode('utf-8'))
|
||||
|
||||
finally:
|
||||
self.client.close()
|
||||
if message['type'] == 'response':
|
||||
# self.client.close()
|
||||
return message['content']
|
||||
|
||||
def send(self, data):
|
||||
serialized_data = json.dumps(data)
|
||||
|
||||
@@ -3,6 +3,7 @@ import questionary
|
||||
from termcolor import colored
|
||||
|
||||
from database.database import save_user_input, get_user_input_from_hash_id
|
||||
from const.ipc import MESSAGE_TYPE
|
||||
|
||||
custom_style = Style.from_dict({
|
||||
'question': '#FFFFFF bold', # the color and style of the question
|
||||
@@ -28,10 +29,15 @@ def styled_text(project, question):
|
||||
print(colored(f'{user_input.user_input}', 'yellow', attrs=['bold']))
|
||||
return user_input.user_input
|
||||
|
||||
config = {
|
||||
'style': custom_style,
|
||||
}
|
||||
response = questionary.text(question, **config).unsafe_ask() # .ask() is included here
|
||||
if project.ipc_client_instance is None or project.ipc_client_instance.client is None:
|
||||
config = {
|
||||
'style': custom_style,
|
||||
}
|
||||
response = questionary.text(question, **config).unsafe_ask() # .ask() is included here
|
||||
else:
|
||||
response = project.log(question, MESSAGE_TYPE['user_input_request'])
|
||||
project.log(response, MESSAGE_TYPE['verbose'])
|
||||
|
||||
user_input = save_user_input(project, question, response)
|
||||
|
||||
print('\n\n', end='')
|
||||
|
||||
Reference in New Issue
Block a user