Merge branch 'main' into patch-1

pull/35/head
nervousapps 2023-04-26 01:04:40 +02:00 zatwierdzone przez GitHub
commit 5fafe7c1fb
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 11 dodań i 6 usunięć

Wyświetl plik

@ -4,11 +4,13 @@ import os
import shutil import shutil
import subprocess import subprocess
import sys import sys
import openai import openai
from typing import List, Dict from typing import List, Dict
from termcolor import cprint from termcolor import cprint
from dotenv import load_dotenv from dotenv import load_dotenv
from termcolor import cprint
# Set up the OpenAI API # Set up the OpenAI API
load_dotenv() load_dotenv()
@ -26,11 +28,11 @@ with open(os.path.join(os.path.dirname(__file__), "..", "prompt.txt"), 'r') as f
def run_script(script_name: str, script_args: List) -> str: def run_script(script_name: str, script_args: List) -> str:
script_args = [str(arg) for arg in script_args]
""" """
If script_name.endswith(".py") then run with python If script_name.endswith(".py") then run with python
else run with node else run with node
""" """
script_args = [str(arg) for arg in script_args]
subprocess_args = ( subprocess_args = (
[sys.executable, script_name, *script_args] [sys.executable, script_name, *script_args]
if script_name.endswith(".py") if script_name.endswith(".py")
@ -38,9 +40,12 @@ def run_script(script_name: str, script_args: List) -> str:
) )
try: try:
result = subprocess.check_output(subprocess_args, stderr=subprocess.STDOUT) result = subprocess.check_output(
except subprocess.CalledProcessError as e: subprocess_args,
return e.output.decode("utf-8"), e.returncode stderr=subprocess.STDOUT
)
except subprocess.CalledProcessError as error:
return error.output.decode("utf-8"), error.returncode
return result.decode("utf-8"), 0 return result.decode("utf-8"), 0
@ -130,7 +135,7 @@ def apply_changes(file_path: str, changes: List, confirm: bool = False):
""" """
Pass changes as loaded json (list of dicts) Pass changes as loaded json (list of dicts)
""" """
with open(file_path, "r") as f: with open(file_path) as f:
original_file_lines = f.readlines() original_file_lines = f.readlines()
# Filter out explanation elements # Filter out explanation elements