remove inquirer completely and fix saving app to db

This commit is contained in:
LeonOstrez
2023-07-28 14:38:13 +02:00
parent 32e988db24
commit 02dc329933
5 changed files with 55 additions and 36 deletions

View File

@@ -93,15 +93,20 @@ def save_app(user_id, app_id, app_type):
cursor.execute("INSERT INTO users (id, username, email, password) VALUES (%s, 'username', 'email', 'password')",
(str(user_id),))
# Now save the app
cursor.execute("INSERT INTO apps (user_id, app_id, app_type, status) VALUES (%s, %s, %s, 'started') RETURNING id",
(str(user_id), (str(app_id)), app_type))
# Now save or update the app
cursor.execute("""
INSERT INTO apps (user_id, app_id, app_type, status)
VALUES (%s, %s, %s, 'started')
ON CONFLICT (app_id) DO UPDATE SET
user_id = EXCLUDED.user_id, app_type = EXCLUDED.app_type, status = EXCLUDED.status
RETURNING id
""", (str(user_id), str(app_id), app_type))
conn.commit()
cursor.close()
conn.close()
logger.info('User saved')
logger.info('App saved')
return

View File

@@ -1,6 +1,5 @@
# prompts/prompts.py
import inquirer
from inquirer.themes import GreenPassion
from termcolor import colored
import questionary
@@ -8,58 +7,55 @@ from const import common
from const.llm import MAX_QUESTIONS, END_RESPONSE
from utils.llm_connection import create_gpt_chat_completion, get_prompt
from utils.utils import capitalize_first_word_with_underscores, get_sys_message, find_role_from_step
from utils.questionary import styled_select, styled_text
from logger.logger import logger
def ask_for_app_type():
questions = [
inquirer.List('type',
message="What type of app do you want to build?",
choices=common.APP_TYPES,
)
]
answer = styled_select(
"What type of app do you want to build?",
choices=common.APP_TYPES
)
answers = inquirer.prompt(questions, theme=GreenPassion())
if answers is None:
if answer is None:
print("Exiting application.")
exit(0)
while 'unavailable' in answers['type']:
while 'unavailable' in answer:
print("Sorry, that option is not available.")
answers = inquirer.prompt(questions, theme=GreenPassion())
if answers is None:
answer = styled_select(
"What type of app do you want to build?",
choices=common.APP_TYPES
)
if answer is None:
print("Exiting application.")
exit(0)
print("You chose: " + answers['type'])
logger.info(f"You chose: {answers['type']}")
return answers['type']
print("You chose: " + answer)
logger.info(f"You chose: {answer}")
return answer
def ask_for_main_app_definition():
questions = [
inquirer.Text('description', message="Describe your app in as many details as possible.")
]
description = styled_text(
"Describe your app in as many details as possible."
)
answers = inquirer.prompt(questions, theme=GreenPassion())
if answers is None:
if description is None:
print("No input provided!")
return
description = answers['description']
while True:
questions = [
inquirer.Text('confirmation', message="Do you want to add anything else? If not, just press ENTER.")
]
confirmation = styled_text(
"Do you want to add anything else? If not, just press ENTER."
)
answers = inquirer.prompt(questions, theme=GreenPassion())
if answers is None or answers['confirmation'] == '':
if confirmation is None or confirmation == '':
break
elif description[-1] not in ['.', '!', '?', ';']:
description += '.'
description += ' ' + answers['confirmation']
description += ' ' + confirmation
logger.info(f"Initial App description done: {description}")
@@ -68,7 +64,7 @@ def ask_for_main_app_definition():
def ask_user(question):
while True:
answer = questionary.text(question).ask()
answer = styled_text(question)
if answer is None:
print("Exiting application.")

View File

@@ -77,7 +77,7 @@ def create_gpt_chat_completion(messages: List[dict], req_type, min_tokens=MIN_TO
def stream_gpt_completion(data, req_type):
print(colored("Waiting for OpenAI API response...", 'yellow'))
print(colored("Waiting for OpenAI API response...", 'light_magenta'))
api_key = os.getenv("OPENAI_API_KEY")
logger.info(f'Request data: {data}')

View File

@@ -0,0 +1,19 @@
from prompt_toolkit.styles import Style
import questionary
custom_style = Style.from_dict({
'question': '#ff9d00 bold', # the color and style of the question
'answer': '#7CFC00 bold', # the color and style of the answer
'pointer': '#FF4500 bold', # the color and style of the selection pointer
'highlighted': '#800080 bold' # the color and style of the highlighted choice
})
def styled_select(*args, **kwargs):
kwargs["style"] = custom_style # Set style here
return questionary.select(*args, **kwargs).ask() # .ask() is included here
def styled_text(*args, **kwargs):
kwargs["style"] = custom_style # Set style here
return questionary.text(*args, **kwargs).ask() # .ask() is included here

View File

@@ -3,7 +3,6 @@ certifi==2023.5.7
charset-normalizer==3.2.0
distro==1.8.0
idna==3.4
inquirer==3.1.3
Jinja2==3.1.2
MarkupSafe==2.1.3
prompt-toolkit==3.0.39