From fc0cfd7d1f0d08de474cf6616abb16a7663aba67 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Thu, 2 Feb 2023 11:35:36 -0800 Subject: [PATCH] docs (#848) --- docs/modules/chains/generic/llm_chain.ipynb | 43 ++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/docs/modules/chains/generic/llm_chain.ipynb b/docs/modules/chains/generic/llm_chain.ipynb index 97dffa4a70..c9485d4716 100644 --- a/docs/modules/chains/generic/llm_chain.ipynb +++ b/docs/modules/chains/generic/llm_chain.ipynb @@ -121,10 +121,51 @@ "llm_chain.predict(adjective=\"sad\", subject=\"ducks\")" ] }, + { + "cell_type": "markdown", + "id": "672f59d4", + "metadata": {}, + "source": [ + "## From string\n", + "You can also construct an LLMChain from a string template directly." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "f8bc262e", + "metadata": {}, + "outputs": [], + "source": [ + "template = \"\"\"Write a {adjective} poem about {subject}.\"\"\"\n", + "llm_chain = LLMChain.from_string(llm=OpenAI(temperature=0), template=template)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "cb164a76", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"\\n\\nThe ducks swim in the pond,\\nTheir feathers so soft and warm,\\nBut they can't help but feel so forlorn.\\n\\nTheir quacks echo in the air,\\nBut no one is there to hear,\\nFor they have no one to share.\\n\\nThe ducks paddle around in circles,\\nTheir heads hung low in despair,\\nFor they have no one to care.\\n\\nThe ducks look up to the sky,\\nBut no one is there to see,\\nFor they have no one to be.\\n\\nThe ducks drift away in the night,\\nTheir hearts filled with sorrow and pain,\\nFor they have no one to gain.\"" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "llm_chain.predict(adjective=\"sad\", subject=\"ducks\")" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "8310cdaa", + "id": "9f0adbc7", "metadata": {}, "outputs": [], "source": []