树状摘要¶
如果您在 colab 上打开此 Notebook,您可能需要安装 LlamaIndex 🦙。
In [ ]
已复制!
!pip install llama-index
!pip install llama-index
下载数据¶
In [ ]
已复制!
!mkdir -p 'data/paul_graham/'
!wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'
!mkdir -p 'data/paul_graham/' !wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'
加载数据¶
In [ ]
已复制!
from llama_index.core import SimpleDirectoryReader
from llama_index.core import SimpleDirectoryReader
In [ ]
已复制!
reader = SimpleDirectoryReader(
input_files=["./data/paul_graham/paul_graham_essay.txt"]
)
reader = SimpleDirectoryReader( input_files=["./data/paul_graham/paul_graham_essay.txt"] )
In [ ]
已复制!
docs = reader.load_data()
docs = reader.load_data()
In [ ]
已复制!
text = docs[0].text
text = docs[0].text
摘要¶
In [ ]
已复制!
from llama_index.core.response_synthesizers import TreeSummarize
from llama_index.core.response_synthesizers import TreeSummarize
In [ ]
已复制!
summarizer = TreeSummarize(verbose=True)
summarizer = TreeSummarize(verbose=True)
In [ ]
已复制!
response = await summarizer.aget_response("who is Paul Graham?", [text])
response = await summarizer.aget_response("who is Paul Graham?", [text])
6 text chunks after repacking 1 text chunks after repacking
In [ ]
已复制!
print(response)
print(response)
Paul Graham is a computer scientist, writer, artist, entrepreneur, investor, and essayist. He is best known for his work in artificial intelligence, Lisp programming, and writing the book On Lisp, as well as for co-founding the startup accelerator Y Combinator and for his essays on technology, business, and start-ups. He is also the creator of the programming language Arc and the Lisp dialect Bel.