From 38854581136c96bf2b8b4444954a31435d8ba71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ramiro=20G=C3=B3mez?= Date: Tue, 16 Jul 2024 00:50:40 +0200 Subject: [PATCH] Only accept file names as input in OPEN mode. --- charla/chat.py | 14 ++++---------- charla/config.py | 1 - 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/charla/chat.py b/charla/chat.py index 8ca6ac2..8f279f1 100644 --- a/charla/chat.py +++ b/charla/chat.py @@ -84,10 +84,6 @@ def run(argv: argparse.Namespace) -> None: context: list[int] = [] # Store conversation history to make the model context aware output = [f'# Chat with: {argv.model}\n'] # List to store output text - # Regex for extracting file names from prompts - extensions = '|'.join(config.text_file_extensions) - re_filename = re.compile(rf'\S+\.(?:{extensions})\b', re.IGNORECASE) - history = Path(argv.prompt_history) config.mkdir(history.parent, exist_ok=True, parents=True) @@ -107,15 +103,13 @@ def run(argv: argparse.Namespace) -> None: output.append(f'{session.message}{user_input}\n') if session.message == t_open: - filename = user_input - if match := re.search(re_filename, user_input): - filename = match.group(0) + filename = user_input.strip() try: - user_input = user_input.replace(filename, Path(filename).read_text()) + user_input = Path(filename).read_text() session.message = t_prompt_ml if session.multiline else t_prompt session.completer = None - except FileNotFoundError as err: - print(err) + except Exception as err: + print(f'Enter name of an existing file.\n{err}\n') continue print(f'\n{t_response}\n') diff --git a/charla/config.py b/charla/config.py index 5d8aad9..19d1577 100644 --- a/charla/config.py +++ b/charla/config.py @@ -14,7 +14,6 @@ 'multiline': False } path_settings = user_config_path(NAME).joinpath('settings.json') -text_file_extensions = ['htm', 'html', 'md', 'markdown', 'txt'] def load() -> dict: