response_mode="tree_summarize"
https://gpt-index.readthedocs.io/en/latest/guides/use_cases.html#use-case-summarization-over-documents.def file_to_index(file_path): """ :param file_path: str path to file to be indexed :return: GPTSimpleVectorIndex """ # from gpt_index.readers.schema.base import Document # convert file path to a Document, then to a GPTSimpleVectorIndex document = FileDocument(file_path) index = GPTListIndex([document]) return index
class FileDocument(gpt_index_document): """ A document that is stored in a file. """ def __init__(self, filepath: str, summary: str = None, *args, **kwargs): self.filepath = filepath self.name = filepath.split('/')[-1] self.text = utils.read_file(filepath) self.summary = summary kwargs['text'] = self.text kwargs['extra_info'] = { 'filepath': filepath, 'file_hash': generate_file_hash(filepath), 'name': self.name, 'summary': self.summary } super().__init__(*args, **kwargs)
def read_file(filepath): with open(filepath, 'r') as f: data = f.read() return data