mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
84 lines
2.2 KiB
Plaintext
84 lines
2.2 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "e9db25f3",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from langchain import OpenAI, Prompt, LLMChain\n",
|
|
"from langchain.text_splitter import CharacterTextSplitter\n",
|
|
"from langchain.chains.mapreduce import MapReduceChain\n",
|
|
"\n",
|
|
"llm = OpenAI(temperature=0)\n",
|
|
"\n",
|
|
"_prompt = \"\"\"Write a concise summary of the following:\n",
|
|
"\n",
|
|
"\n",
|
|
"{text}\n",
|
|
"\n",
|
|
"\n",
|
|
"CONCISE SUMMARY:\"\"\"\n",
|
|
"prompt = Prompt(template=_prompt, input_variables=[\"text\"])\n",
|
|
"\n",
|
|
"text_splitter = CharacterTextSplitter()\n",
|
|
"\n",
|
|
"mp_chain = MapReduceChain.from_params(llm, prompt, text_splitter)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "99bbe19b",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"\"\\n\\nThe President discusses the recent aggression by Russia, and the response by the United States and its allies. He announces new sanctions against Russia, and says that the free world is united in holding Putin accountable. The President also discusses the American Rescue Plan, the Bipartisan Infrastructure Law, and the Bipartisan Innovation Act. Finally, the President addresses the need for women's rights and equality for LGBTQ+ Americans.\""
|
|
]
|
|
},
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"with open('state_of_the_union.txt') as f:\n",
|
|
" state_of_the_union = f.read()\n",
|
|
"mp_chain.run(state_of_the_union)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "b581501e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.7.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|