Skip to content

Commit

Permalink
Merge pull request #801 from TheoMcCabe/bug/758-unicode-decode-error
Browse files Browse the repository at this point in the history
bug: Unicode decode error
  • Loading branch information
ATheorell authored Oct 16, 2023
2 parents 7020fea + 7779d25 commit a436d0f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions gpt_engineer/core/chat_to_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,10 @@ def overwrite_files(chat: str, dbs: DBs) -> None:
def get_code_strings(workspace: DB, metadata_db: DB) -> dict[str, str]:
"""
Read file_list.txt and return file names and their content.
Parameters
----------
input : dict
A dictionary containing the file_list.txt.
Returns
-------
dict[str, str]
Expand All @@ -170,13 +168,25 @@ def get_all_files_in_dir(directory):
files.append(full_file_path)

files_dict = {}

for path in files:
assert os.path.commonpath([full_file_path, workspace.path]) == str(
workspace.path
), "Trying to edit files outside of the workspace"

file_name = os.path.relpath(path, workspace.path)

if file_name in workspace:
files_dict[file_name] = workspace[file_name]
try:
with open(path, "r", encoding="utf-8") as f:
file_content = f.read()
except UnicodeDecodeError:
raise ValueError(
f"Non-text file detected: {file_name}, gpt-engineer currently only supports utf-8 decodable text files."
)

files_dict[file_name] = file_content

return files_dict


Expand Down

0 comments on commit a436d0f

Please sign in to comment.