Spaces:
Runtime error
Runtime error
File size: 885 Bytes
c71f981 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
from openai import OpenAI
from openai.types.file_object import FileObject
import structlog
class FileHandler:
def __init__(self) -> None:
self.client = OpenAI()
self.log = structlog.get_logger()
def add(self, file_path: str)->FileObject:
"""
Adds the file to vectorstore and returns a file_id
"""
# read file
self.log.info(f"File Handler: Reading File with {file_path}")
file_obj = open(file_path, "rb")
self.log.info("File Handler: Adding file")
file: FileObject = self.client.files.create(file=file_obj, purpose="assistants")
self.log.info(f"File Handler: Created file object with id: {file.id}")
return file
def remove(self, file_id: str):
self.client.files.delete(file_id=file_id)
self.log.info(f"File Handler: Deleted file object with id: {file_id}")
|