Start cookbook and move stuff from use cases (#11636)

This commit is contained in:
Bagatur
2023-10-11 12:27:13 -07:00
committed by GitHub
parent 99adcdb1c9
commit cf86447623
98 changed files with 522 additions and 2126 deletions

View File

@@ -1,70 +0,0 @@
```python
with open("../../state_of_the_union.txt") as f:
state_of_the_union = f.read()
```
## Summarize
Let's take a look at it in action below, using it to summarize a long document.
```python
from langchain.llms import OpenAI
from langchain.chains.summarize import load_summarize_chain
llm = OpenAI(temperature=0)
summary_chain = load_summarize_chain(llm, chain_type="map_reduce")
```
```python
from langchain.chains import AnalyzeDocumentChain
```
```python
summarize_document_chain = AnalyzeDocumentChain(combine_docs_chain=summary_chain)
```
```python
summarize_document_chain.run(state_of_the_union)
```
<CodeOutputBlock lang="python">
```
" In this speech, President Biden addresses the American people and the world, discussing the recent aggression of Russia's Vladimir Putin in Ukraine and the US response. He outlines economic sanctions and other measures taken to hold Putin accountable, and announces the US Department of Justice's task force to go after the crimes of Russian oligarchs. He also announces plans to fight inflation and lower costs for families, invest in American manufacturing, and provide military, economic, and humanitarian assistance to Ukraine. He calls for immigration reform, protecting the rights of women, and advancing the rights of LGBTQ+ Americans, and pays tribute to military families. He concludes with optimism for the future of America."
```
</CodeOutputBlock>
## Question Answering
Let's take a look at this using a question answering chain.
```python
from langchain.chains.question_answering import load_qa_chain
```
```python
qa_chain = load_qa_chain(llm, chain_type="map_reduce")
```
```python
qa_document_chain = AnalyzeDocumentChain(combine_docs_chain=qa_chain)
```
```python
qa_document_chain.run(input_document=state_of_the_union, question="what did the president say about justice breyer?")
```
<CodeOutputBlock lang="python">
```
' The president thanked Justice Breyer for his service.'
```
</CodeOutputBlock>