Merge pull request #1 from LopeKinz/sourcery/main

Sourcery refactored main branch
pull/50/head
LopeKinz 2023-05-22 07:46:51 +02:00 zatwierdzone przez GitHub
commit db947e5845
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 6 dodań i 7 usunięć

Wyświetl plik

@ -71,8 +71,7 @@ def json_validated_response(
json_data = content[ json_data = content[
json_start_index: json_start_index:
] # extract the JSON data from the response string ] # extract the JSON data from the response string
json_response = json.loads(json_data) return json.loads(json_data)
return json_response
except (json.decoder.JSONDecodeError, ValueError) as e: except (json.decoder.JSONDecodeError, ValueError) as e:
cprint(f"{e}. Re-running the query.", "red") cprint(f"{e}. Re-running the query.", "red")
# debug # debug
@ -106,9 +105,9 @@ def send_error_to_gpt(
with open(file_path, "r") as f: with open(file_path, "r") as f:
file_lines = f.readlines() file_lines = f.readlines()
file_with_lines = [] file_with_lines = [
for i, line in enumerate(file_lines): f"{str(i + 1)}: {line}" for i, line in enumerate(file_lines)
file_with_lines.append(str(i + 1) + ": " + line) ]
file_with_lines = "".join(file_with_lines) file_with_lines = "".join(file_with_lines)
prompt = ( prompt = (
@ -207,7 +206,7 @@ def check_model_availability(model):
def main(script_name, *script_args, revert=False, model=DEFAULT_MODEL, confirm=False): def main(script_name, *script_args, revert=False, model=DEFAULT_MODEL, confirm=False):
if revert: if revert:
backup_file = script_name + ".bak" backup_file = f"{script_name}.bak"
if os.path.exists(backup_file): if os.path.exists(backup_file):
shutil.copy(backup_file, script_name) shutil.copy(backup_file, script_name)
print(f"Reverted changes to {script_name}") print(f"Reverted changes to {script_name}")
@ -220,7 +219,7 @@ def main(script_name, *script_args, revert=False, model=DEFAULT_MODEL, confirm=F
check_model_availability(model) check_model_availability(model)
# Make a backup of the original script # Make a backup of the original script
shutil.copy(script_name, script_name + ".bak") shutil.copy(script_name, f"{script_name}.bak")
while True: while True:
output, returncode = run_script(script_name, script_args) output, returncode = run_script(script_name, script_args)