mirror of
https://github.com/OMGeeky/gpt-pilot.git
synced 2026-02-23 15:49:50 +01:00
setup storing steps to db and init user stories implementation
This commit is contained in:
@@ -1,48 +1,151 @@
|
||||
# utils/utils.py
|
||||
import inquirer
|
||||
from inquirer.themes import GreenPassion
|
||||
|
||||
import sys
|
||||
import os
|
||||
import platform
|
||||
import distro
|
||||
import uuid
|
||||
import re
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
from const.llm import MAX_QUESTIONS, END_RESPONSE
|
||||
from const.common import ROLES, STEPS
|
||||
|
||||
|
||||
def break_down_user_flows(description):
|
||||
return 'false'
|
||||
user_flows = parse_description_into_user_flows(description)
|
||||
for flow_index, user_flow in enumerate(user_flows):
|
||||
is_correct = False
|
||||
while not is_correct:
|
||||
print(f"User Flow {flow_index + 1}: {user_flow}")
|
||||
is_correct = ask_for_user_flow_confirmation(flow_index)
|
||||
save_progress(app_id, f'user_flow_{flow_index + 1}', user_flow)
|
||||
def get_arguments():
|
||||
# The first element in sys.argv is the name of the script itself.
|
||||
# Any additional elements are the arguments passed from the command line.
|
||||
args = sys.argv[1:]
|
||||
|
||||
# Create an empty dictionary to store the key-value pairs.
|
||||
arguments = {}
|
||||
|
||||
# Loop through the arguments and parse them as key-value pairs.
|
||||
for arg in args:
|
||||
if '=' in arg:
|
||||
key, value = arg.split('=', 1)
|
||||
arguments[key] = value
|
||||
else:
|
||||
# Handle arguments without '=' (e.g., positional arguments).
|
||||
pass
|
||||
|
||||
if 'user_id' not in arguments:
|
||||
arguments['user_id'] = str(uuid.uuid4())
|
||||
|
||||
if 'app_id' not in arguments:
|
||||
arguments['app_id'] = str(uuid.uuid4())
|
||||
|
||||
if 'step' not in arguments:
|
||||
arguments['step'] = None
|
||||
|
||||
print(f"If you wish to continue with this project in future run 'python main.py app_id={arguments['app_id']}")
|
||||
return arguments
|
||||
|
||||
|
||||
def ask_for_user_flow_confirmation(flow_index):
|
||||
questions = [
|
||||
inquirer.List('confirmation',
|
||||
message=f"Does user flow {flow_index + 1} meet your requirements? (Yes/No)",
|
||||
choices=['Yes', 'No'],
|
||||
)
|
||||
]
|
||||
def capitalize_first_word_with_underscores(s):
|
||||
# Split the string into words based on underscores.
|
||||
words = s.split('_')
|
||||
|
||||
answers = inquirer.prompt(questions, theme=GreenPassion())
|
||||
# Capitalize the first word and leave the rest unchanged.
|
||||
words[0] = words[0].capitalize()
|
||||
|
||||
if answers is None:
|
||||
print("No input provided!")
|
||||
return
|
||||
# Join the words back into a string with underscores.
|
||||
capitalized_string = '_'.join(words)
|
||||
|
||||
if answers['confirmation'] == 'Yes':
|
||||
return True
|
||||
else:
|
||||
return modify_user_flow(flow_index)
|
||||
return capitalized_string
|
||||
|
||||
|
||||
def modify_user_flow(flow_index):
|
||||
questions = [
|
||||
inquirer.Text('correction', message=f"Please provide corrections for user flow {flow_index + 1}.")
|
||||
]
|
||||
def get_prompt_components():
|
||||
# This function reads and renders all prompts inside /prompts/components and returns them in dictionary
|
||||
|
||||
answers = inquirer.prompt(questions, theme=GreenPassion())
|
||||
if answers is None:
|
||||
print("No input provided!")
|
||||
return False
|
||||
# Create an empty dictionary to store the file contents.
|
||||
prompts_components = {}
|
||||
data = {
|
||||
'MAX_QUESTIONS': MAX_QUESTIONS,
|
||||
'END_RESPONSE': END_RESPONSE
|
||||
}
|
||||
|
||||
user_flows[flow_index] = answers['correction']
|
||||
return False
|
||||
# Create a FileSystemLoader
|
||||
file_loader = FileSystemLoader('prompts/components')
|
||||
|
||||
# Create the Jinja2 environment
|
||||
env = Environment(loader=file_loader)
|
||||
|
||||
# Get the list of template names
|
||||
template_names = env.list_templates()
|
||||
|
||||
# For each template, load and store its content
|
||||
for template_name in template_names:
|
||||
# Get the filename without extension as the dictionary key.
|
||||
file_key = os.path.splitext(template_name)[0]
|
||||
|
||||
# Load the template and render it with no variables
|
||||
file_content = env.get_template(template_name).render(data)
|
||||
|
||||
# Store the file content in the dictionary
|
||||
prompts_components[file_key] = file_content
|
||||
|
||||
return prompts_components
|
||||
|
||||
|
||||
def get_sys_message(role):
|
||||
# Create a FileSystemLoader
|
||||
file_loader = FileSystemLoader('prompts/system_messages')
|
||||
|
||||
# Create the Jinja2 environment
|
||||
env = Environment(loader=file_loader)
|
||||
|
||||
# Load the template
|
||||
template = env.get_template(f'{role}.prompt')
|
||||
|
||||
# Render the template with no variables
|
||||
content = template.render()
|
||||
|
||||
return {
|
||||
"role": "system",
|
||||
"content": content
|
||||
}
|
||||
|
||||
|
||||
def find_role_from_step(target):
|
||||
for role, values in ROLES.items():
|
||||
if target in values:
|
||||
return role
|
||||
|
||||
return 'product_owner'
|
||||
|
||||
|
||||
def get_os_info():
|
||||
os_info = {
|
||||
"OS": platform.system(),
|
||||
"OS Version": platform.version(),
|
||||
"Architecture": platform.architecture()[0],
|
||||
"Machine": platform.machine(),
|
||||
"Node": platform.node(),
|
||||
"Release": platform.release(),
|
||||
}
|
||||
|
||||
if os_info["OS"] == "Linux":
|
||||
os_info["Distribution"] = ' '.join(distro.linux_distribution(full_distribution_name=True))
|
||||
elif os_info["OS"] == "Windows":
|
||||
os_info["Win32 Version"] = ' '.join(platform.win32_ver())
|
||||
elif os_info["OS"] == "Mac":
|
||||
os_info["Mac Version"] = platform.mac_ver()[0]
|
||||
|
||||
# Convert the dictionary to a readable text format
|
||||
output = "\n".join(f"{key}: {value}" for key, value in os_info.items())
|
||||
return output
|
||||
|
||||
|
||||
def execute_step(matching_step, current_step):
|
||||
matching_step_index = STEPS.index(matching_step) if matching_step in STEPS else None
|
||||
current_step_index = STEPS.index(current_step) if current_step in STEPS else None
|
||||
|
||||
return matching_step_index is not None and current_step_index is not None and current_step_index >= matching_step_index
|
||||
|
||||
|
||||
def split_into_bullets(text):
|
||||
pattern = re.compile(r'\n*\d+\.\s\*\*')
|
||||
split_text = re.split(pattern, text)
|
||||
split_text = [bullet for bullet in split_text if bullet] # Remove any empty strings from the list
|
||||
return split_text
|
||||
|
||||
Reference in New Issue
Block a user