Back to Llama Index

Tree Summarize

docs/examples/response_synthesizers/tree_summarize.ipynb

0.14.211.1 KB
Original Source

<a href="https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/response_synthesizers/tree_summarize.ipynb" target="_parent"></a>

Tree Summarize

If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.

python
!pip install llama-index

Download Data

python
!mkdir -p 'data/paul_graham/'
!wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'

Load Data

python
from llama_index.core import SimpleDirectoryReader
python
reader = SimpleDirectoryReader(
    input_files=["./data/paul_graham/paul_graham_essay.txt"]
)
python
docs = reader.load_data()
python
text = docs[0].text

Summarize

python
from llama_index.core.response_synthesizers import TreeSummarize
python
summarizer = TreeSummarize(verbose=True)
python
response = await summarizer.aget_response("who is Paul Graham?", [text])
python
print(response)