From 9859720cc59572199bd10a543262cc613cfb1c16 Mon Sep 17 00:00:00 2001 From: Emma Pearce Date: Thu, 19 Dec 2024 09:52:04 +0000 Subject: [PATCH] Address comment in openai file --- backend/src/llm/openai.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/backend/src/llm/openai.py b/backend/src/llm/openai.py index cd4fc147..a98c30ea 100644 --- a/backend/src/llm/openai.py +++ b/backend/src/llm/openai.py @@ -88,17 +88,8 @@ async def __upload_files(self, files: list[LLMFile]) -> list[str]: file_ids = [] for file in files: logger.info(f"Uploading file '{file.file_name}' to OpenAI") - if isinstance(file.file, (PathLike, str)): - file_path = Path(file.file) - with file_path.open("rb") as f: - file_bytes = f.read() - elif isinstance(file.file, bytes): - file_bytes = file.file - else: - logger.error(f"Unsupported file type for '{file.file_name}'") - continue - file = await client.files.create(file=(file.file_name, file_bytes), purpose="assistants") - # file = await client.files.create(file=(file.file_name, file.file), purpose="assistants") - file_ids.append(file.id) + file = (file.file_name, file.file) if isinstance(file.file, bytes) else file.file + response = await client.files.create(file=file, purpose="assistants") + file_ids.append(response.id) return file_ids