mirror of
https://github.com/run-llama/llama-hub.git
synced 2025-08-15 04:01:32 +00:00

* cr * cr * cr --------- Co-authored-by: Jerry Liu <jerry@robustintelligence.com> Co-authored-by: Jesse Zhang <jessetanzhang@gmail.com>
33 lines
969 B
Python
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
|