Back to Llama Index

Refine

docs/examples/response_synthesizers/refine.ipynb

0.14.211.2 KB
Original Source

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

Refine

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

python
%pip install llama-index-llms-openai
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.llms.openai import OpenAI

llm = OpenAI(model="gpt-3.5-turbo")
python
from llama_index.core.response_synthesizers import Refine

summarizer = Refine(llm=llm, verbose=True)
python
response = summarizer.get_response("who is Paul Graham?", [text])
python
print(response)