Skip to content

Commit

Permalink
Only accept file names as input in OPEN mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
yaph committed Jul 15, 2024
1 parent c8a6f59 commit 3885458
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
14 changes: 4 additions & 10 deletions charla/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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')
Expand Down
1 change: 0 additions & 1 deletion charla/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3885458

Please sign in to comment.