Refine¶
如果你在 Colab 上打开这个 Notebook,你可能需要安装 LlamaIndex 🦙。
In [ ]
已复制!
%pip install llama-index-llms-openai
%pip install llama-index-llms-openai
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.llms.openai import OpenAI
llm = OpenAI(model="gpt-3.5-turbo")
from llama_index.llms.openai import OpenAI llm = OpenAI(model="gpt-3.5-turbo")
In [ ]
已复制!
from llama_index.core.response_synthesizers import Refine
summarizer = Refine(llm=llm, verbose=True)
from llama_index.core.response_synthesizers import Refine summarizer = Refine(llm=llm, verbose=True)
In [ ]
已复制!
response = summarizer.get_response("who is Paul Graham?", [text])
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...
In [ ]
已复制!
print(response)
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.