Skip to content

Commit 0d52002

Browse files
authored
fix: Windows 11 failing to auto-delete tmp file (#1260)
1 parent 4197ada commit 0d52002

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

private_gpt/server/ingest/ingest_service.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,17 @@ def ingest(self, file_name: str, file_data: AnyStr | Path) -> list[IngestedDoc]:
112112
else:
113113
# llama-index mainly supports reading from files, so
114114
# we have to create a tmp file to read for it to work
115-
with tempfile.NamedTemporaryFile() as tmp:
116-
path_to_tmp = Path(tmp.name)
117-
if isinstance(file_data, bytes):
118-
path_to_tmp.write_bytes(file_data)
119-
else:
120-
path_to_tmp.write_text(str(file_data))
121-
documents = reader.load_data(path_to_tmp)
115+
# delete=False to avoid a Windows 11 permission error.
116+
with tempfile.NamedTemporaryFile(delete=False) as tmp:
117+
try:
118+
path_to_tmp = Path(tmp.name)
119+
if isinstance(file_data, bytes):
120+
path_to_tmp.write_bytes(file_data)
121+
else:
122+
path_to_tmp.write_text(str(file_data))
123+
documents = reader.load_data(path_to_tmp)
124+
finally:
125+
path_to_tmp.unlink()
122126
logger.info(
123127
"Transformed file=%s into count=%s documents", file_name, len(documents)
124128
)

0 commit comments

Comments
 (0)