Skip to content

Commit

Permalink
Address comment in openai file
Browse files Browse the repository at this point in the history
  • Loading branch information
evpearce committed Dec 19, 2024
1 parent 103e029 commit 9859720
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions backend/src/llm/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9859720

Please sign in to comment.