diff --git a/setup.py b/setup.py index 1a5b057..d08f241 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ def read_requirements(): setup( name='gptdeploy', - version='0.18.3', + version='0.18.4', description='Use natural language interface to create, deploy and update your microservice infrastructure.', long_description=open('README.md', 'r', encoding='utf-8').read(), long_description_content_type='text/markdown', diff --git a/src/__init__.py b/src/__init__.py index 25bac85..9fc8f12 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.18.3' +__version__ = '0.18.4' from src.main import main \ No newline at end of file diff --git a/src/utils/__init__.py b/src/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/utils/io.py b/src/utils/io.py new file mode 100644 index 0000000..510a75f --- /dev/null +++ b/src/utils/io.py @@ -0,0 +1,37 @@ +import os +import shutil +import concurrent.futures +import concurrent.futures +from typing import Generator + +def recreate_folder(folder_path): + if os.path.exists(folder_path) and os.path.isdir(folder_path): + shutil.rmtree(folder_path) + os.makedirs(folder_path) + +def persist_file(file_content, file_name): + with open(f'{file_name}', 'w') as f: + f.write(file_content) + + +class GenerationTimeoutError(Exception): + pass + +def timeout_generator_wrapper(generator, timeout): + def generator_func(): + for item in generator: + yield item + + def wrapper() -> Generator: + gen = generator_func() + while True: + try: + with concurrent.futures.ThreadPoolExecutor() as executor: + future = executor.submit(next, gen) + yield future.result(timeout=timeout) + except StopIteration: + break + except concurrent.futures.TimeoutError: + raise GenerationTimeoutError(f"Generation took longer than {timeout} seconds") + + return wrapper() \ No newline at end of file diff --git a/src/utils/string_tools.py b/src/utils/string_tools.py new file mode 100644 index 0000000..c7a5ad1 --- /dev/null +++ b/src/utils/string_tools.py @@ -0,0 +1,53 @@ +import difflib + + +def find_between(input_string, start, end): + try: + start_index = input_string.index(start) + len(start) + end_index = input_string.index(end, start_index) + return input_string[start_index:end_index] + except ValueError: + raise ValueError(f'Could not find {start} and {end} in {input_string}') + + +def clean_content(content): + return content.replace('```', '').strip() + +def print_colored(headline, text, color_code, end='\n'): + if color_code == 'black': + color_code = '30' + elif color_code == 'red': + color_code = '31' + elif color_code == 'green': + color_code = '32' + elif color_code == 'yellow': + color_code = '33' + elif color_code == 'blue': + color_code = '34' + elif color_code == 'magenta': + color_code = '35' + elif color_code == 'cyan': + color_code = '36' + elif color_code == 'white': + color_code = '37' + color_start = f"\033[{color_code}m" + reset = "\033[0m" + bold_start = "\033[1m" + if headline: + print(f"{bold_start}{color_start}{headline}{reset}") + print(f"{color_start}{text}{reset}", end=end) + + +def find_differences(a, b): + matcher = difflib.SequenceMatcher(None, a, b) + differences = set() + + for tag, i1, i2, j1, j2 in matcher.get_opcodes(): + if tag == 'replace': + diff_a = a[i1:i2] + diff_b = b[j1:j2] + # Check for mirrored results and only add non-mirrored ones + if (diff_b, diff_a) not in differences: + differences.add((diff_a, diff_b)) + + return differences