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="vision") 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}")