diff --git a/.devcontainer/requirements-dev.txt b/.devcontainer/requirements-dev.txt index d1ae8c0..54f8f2d 100644 --- a/.devcontainer/requirements-dev.txt +++ b/.devcontainer/requirements-dev.txt @@ -7,3 +7,4 @@ pyfakefs iterfzf hugchat mistralai +binaryornot diff --git a/pyproject.toml b/pyproject.toml index 3164805..6bf89af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ dependencies = [ "iterfzf==1.4.0.51.0", "hugchat==0.4.8", "mistralai==0.4.2", + "binaryornot==0.4.4", ] [project.urls] diff --git a/src/fish_ai/codify.py b/src/fish_ai/codify.py index 819bdb3..e6aff9a 100644 --- a/src/fish_ai/codify.py +++ b/src/fish_ai/codify.py @@ -5,6 +5,7 @@ from re import match from fish_ai import engine import textwrap +from binaryornot.check import is_binary def get_instructions(commandline): @@ -47,13 +48,12 @@ def get_instructions(commandline): ] (filename, file_contents) = get_file_info(commandline) if filename: - instructions.append({ - 'role': 'user', - 'content': textwrap.dedent('''\ + instructions[-1]['content'] = instructions[-1]['content'] + \ + textwrap.dedent('''\ + The content of the file {} is' - {}''').format(filename, '\n'.join(file_contents)) - }) + {}''').format(filename, file_contents) return instructions @@ -70,9 +70,11 @@ def get_file_info(commandline): continue if not access(filename, R_OK): continue + if is_binary(filename): + continue with open(filename, 'r') as file: engine.get_logger().debug('Loading file: ' + filename) - return filename, file.readlines(3072) + return filename, file.read(3072) return None, None