mirror of
https://github.com/imartinez/privateGPT.git
synced 2025-04-29 12:03:31 +00:00
fix: Windows 11 failing to auto-delete tmp file (#1260)
This commit is contained in:
parent
4197ada626
commit
0d520026a3
@ -112,13 +112,17 @@ class IngestService:
|
|||||||
else:
|
else:
|
||||||
# llama-index mainly supports reading from files, so
|
# llama-index mainly supports reading from files, so
|
||||||
# we have to create a tmp file to read for it to work
|
# we have to create a tmp file to read for it to work
|
||||||
with tempfile.NamedTemporaryFile() as tmp:
|
# delete=False to avoid a Windows 11 permission error.
|
||||||
|
with tempfile.NamedTemporaryFile(delete=False) as tmp:
|
||||||
|
try:
|
||||||
path_to_tmp = Path(tmp.name)
|
path_to_tmp = Path(tmp.name)
|
||||||
if isinstance(file_data, bytes):
|
if isinstance(file_data, bytes):
|
||||||
path_to_tmp.write_bytes(file_data)
|
path_to_tmp.write_bytes(file_data)
|
||||||
else:
|
else:
|
||||||
path_to_tmp.write_text(str(file_data))
|
path_to_tmp.write_text(str(file_data))
|
||||||
documents = reader.load_data(path_to_tmp)
|
documents = reader.load_data(path_to_tmp)
|
||||||
|
finally:
|
||||||
|
path_to_tmp.unlink()
|
||||||
logger.info(
|
logger.info(
|
||||||
"Transformed file=%s into count=%s documents", file_name, len(documents)
|
"Transformed file=%s into count=%s documents", file_name, len(documents)
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user