Jerry Liu e97bb81915
swap out gpt_index imports for llama_index imports (#49)
* cr

* cr

* cr

---------

Co-authored-by: Jerry Liu <jerry@robustintelligence.com>
Co-authored-by: Jesse Zhang <jessetanzhang@gmail.com>
2023-02-20 21:46:58 -08:00

33 lines
969 B
Python

"""Simple reader that turns an iterable of strings into a list of Documents."""
from typing import List
from llama_index.readers.base import BaseReader
from llama_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 llama_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