collect telemetry and ask user for feedback

This commit is contained in:
LeonOstrez
2023-09-07 13:01:44 +02:00
parent 3e957b9bd8
commit 44a05b49b5
3 changed files with 71 additions and 5 deletions

View File

@@ -1,12 +1,15 @@
# main.py
from __future__ import print_function, unicode_literals
import sys
from dotenv import load_dotenv
load_dotenv()
from helpers.Project import Project
from utils.arguments import get_arguments
from utils.exit import exit_gpt_pilot
from logger.logger import logger
from database.database import database_exists, create_database, tables_exist, create_tables
@@ -28,8 +31,13 @@ def init():
if __name__ == "__main__":
args = init()
# TODO get checkpoint from database and fill the project with it
project = Project(args)
project.start()
try:
args = init()
project = Project(args)
project.start()
except KeyboardInterrupt:
exit_gpt_pilot()
except Exception as e:
exit_gpt_pilot()
finally:
sys.exit(0)

51
pilot/utils/exit.py Normal file
View File

@@ -0,0 +1,51 @@
# exit.py
import os
import hashlib
import requests
from utils.questionary import get_user_feedback
def send_telemetry(path_id):
# Prepare the telemetry data
telemetry_data = {
"pathId": path_id,
"event": "pilot-exit"
}
try:
response = requests.post("https://api.pythagora.io/telemetry", json=telemetry_data)
response.raise_for_status()
except requests.RequestException as err:
print(f"Failed to send telemetry data: {err}")
def send_feedback(feedback, path_id):
"""Send the collected feedback to the endpoint."""
# Prepare the feedback data (you can adjust the structure as per your backend needs)
feedback_data = {
"pathId": path_id,
"data": feedback,
"event": "pilot-feedback"
}
try:
response = requests.post("https://api.pythagora.io/telemetry", json=feedback_data)
response.raise_for_status()
except requests.RequestException as err:
print(f"Failed to send feedback data: {err}")
def get_path_id():
# Calculate the SHA-256 hash of the installation directory
installation_directory = os.path.abspath(os.path.join(os.getcwd(), ".."))
return hashlib.sha256(installation_directory.encode()).hexdigest()
def exit_gpt_pilot():
path_id = get_path_id()
send_telemetry(path_id)
feedback = get_user_feedback()
if feedback: # only send if user provided feedback
send_feedback(feedback, path_id)

View File

@@ -37,3 +37,10 @@ def styled_text(project, question):
print('\n\n', end='')
return response
def get_user_feedback():
config = {
'style': custom_style,
}
return questionary.text("Thank you for trying GPT-Pilot. Please give us your feedback or just press ENTER to exit: ", **config).unsafe_ask()