Spaces:
Runtime error
Runtime error
File size: 963 Bytes
35b22df |
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 28 29 30 31 32 33 |
"""Simple reader that turns an iterable of strings into a list of Documents."""
from typing import List
from gpt_index.readers.base import BaseReader
from gpt_index.readers.schema.base import Document
class StringIterableReader(BaseReader):
"""String Iterable Reader.
Gets a list of documents, given an iterable (e.g. list) of strings.
Example:
.. code-block:: python
from gpt_index import StringIterableReader, GPTTreeIndex
documents = StringIterableReader().load_data(
texts=["I went to the store", "I bought an apple"])
index = GPTTreeIndex(documents)
index.query("what did I buy?")
# response should be something like "You bought an apple."
"""
def load_data(self, texts: List[str]) -> List[Document]:
"""Load the data."""
results = []
for text in texts:
results.append(Document(text))
return results
|