Refine#
If you’re opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.
!pip install llama-index
Download Data#
!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#
from llama_index import SimpleDirectoryReader
reader = SimpleDirectoryReader(
input_files=["./data/paul_graham/paul_graham_essay.txt"]
)
docs = reader.load_data()
text = docs[0].text
Summarize#
from llama_index.llms import OpenAI
llm = OpenAI(model="gpt-3.5-turbo")
from llama_index import ServiceContext
service_context = ServiceContext.from_defaults(llm=llm)
from llama_index.response_synthesizers import Refine
summarizer = Refine(service_context=service_context, verbose=True)
response = summarizer.get_response("who is Paul Graham?", [text])
> Refine context: making fakes for a local antique dealer. She'd ...
> Refine context: look legit, and the key to looking legit is hig...
> Refine context: me 8 years to realize it. Even then it took me ...
> Refine context: was one thing rarer than Rtm offering advice, i...
print(response)
Paul Graham is an individual who has played a crucial role in shaping the internet infrastructure and has also pursued a career as a writer. At one point, he received advice from a friend that urged him not to let Y Combinator be his final noteworthy achievement. This advice prompted him to reflect on his future with Y Combinator and ultimately led him to pass on the responsibility to others. He approached Jessica and Sam Altman to assume leadership positions in Y Combinator, aiming to secure its continued success.