fix-lcel-notebooks (#11111)

fix some missing imports/naming
pull/11120/head
Harrison Chase 1 year ago committed by GitHub
parent 865a21938c
commit 6b4928ad96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -277,7 +277,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.9.1" "version": "3.10.1"
} }
}, },
"nbformat": 4, "nbformat": 4,

@ -14,12 +14,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 77, "execution_count": 4,
"id": "6bb221b3", "id": "6bb221b3",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain.schema.runnable import RunnableLambda\n", "from langchain.schema.runnable import RunnableLambda\n",
"from langchain.prompts import ChatPromptTemplate\n",
"from langchain.chat_models import ChatOpenAI\n",
"from operator import itemgetter\n",
"\n", "\n",
"def length_function(text):\n", "def length_function(text):\n",
" return len(text)\n", " return len(text)\n",
@ -31,6 +34,7 @@
" return _multiple_length_function(_dict[\"text1\"], _dict[\"text2\"])\n", " return _multiple_length_function(_dict[\"text1\"], _dict[\"text2\"])\n",
"\n", "\n",
"prompt = ChatPromptTemplate.from_template(\"what is {a} + {b}\")\n", "prompt = ChatPromptTemplate.from_template(\"what is {a} + {b}\")\n",
"model = ChatOpenAI()\n",
"\n", "\n",
"chain1 = prompt | model\n", "chain1 = prompt | model\n",
"\n", "\n",
@ -42,7 +46,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 78, "execution_count": 5,
"id": "5488ec85", "id": "5488ec85",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -52,7 +56,7 @@
"AIMessage(content='3 + 9 equals 12.', additional_kwargs={}, example=False)" "AIMessage(content='3 + 9 equals 12.', additional_kwargs={}, example=False)"
] ]
}, },
"execution_count": 78, "execution_count": 5,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -73,17 +77,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 139, "execution_count": 9,
"id": "80b3b5f6-5d58-44b9-807e-cce9a46bf49f", "id": "80b3b5f6-5d58-44b9-807e-cce9a46bf49f",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain.schema.runnable import RunnableConfig" "from langchain.schema.runnable import RunnableConfig\n",
"from langchain.schema.output_parser import StrOutputParser"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 149, "execution_count": 10,
"id": "ff0daf0c-49dd-4d21-9772-e5fa133c5f36", "id": "ff0daf0c-49dd-4d21-9772-e5fa133c5f36",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -109,7 +114,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 152, "execution_count": 12,
"id": "1a5e709e-9d75-48c7-bb9c-503251990505", "id": "1a5e709e-9d75-48c7-bb9c-503251990505",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -132,6 +137,14 @@
" RunnableLambda(parse_or_fix).invoke(\"{foo: bar}\", {\"tags\": [\"my-tag\"], \"callbacks\": [cb]})\n", " RunnableLambda(parse_or_fix).invoke(\"{foo: bar}\", {\"tags\": [\"my-tag\"], \"callbacks\": [cb]})\n",
" print(cb)" " print(cb)"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"id": "29f55c38",
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {
@ -150,7 +163,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.9.1" "version": "3.10.1"
} }
}, },
"nbformat": 4, "nbformat": 4,

@ -12,18 +12,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 2,
"id": "7e1873d6-d4b6-43ac-96a1-edcf178201e0", "id": "7e1873d6-d4b6-43ac-96a1-edcf178201e0",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"{'joke': AIMessage(content=\"Why don't bears wear shoes? \\nBecause they have bear feet!\", additional_kwargs={}, example=False),\n", "{'joke': AIMessage(content=\"Why don't bears wear shoes? \\n\\nBecause they have bear feet!\", additional_kwargs={}, example=False),\n",
" 'poem': AIMessage(content=\"In twilight's embrace, a bear's gentle lumber,\\nSilent strength, nature's awe, a humble slumber.\", additional_kwargs={}, example=False)}" " 'poem': AIMessage(content=\"In woodland depths, bear prowls with might,\\nSilent strength, nature's sovereign, day and night.\", additional_kwargs={}, example=False)}"
] ]
}, },
"execution_count": 5, "execution_count": 2,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -38,7 +38,7 @@
"joke_chain = ChatPromptTemplate.from_template(\"tell me a joke about {topic}\") | model\n", "joke_chain = ChatPromptTemplate.from_template(\"tell me a joke about {topic}\") | model\n",
"poem_chain = ChatPromptTemplate.from_template(\"write a 2-line poem about {topic}\") | model\n", "poem_chain = ChatPromptTemplate.from_template(\"write a 2-line poem about {topic}\") | model\n",
"\n", "\n",
"map_chain = RunnableMap({\"joke\": chain1, \"poem\": chain2,})\n", "map_chain = RunnableMap({\"joke\": joke_chain, \"poem\": poem_chain,})\n",
"\n", "\n",
"map_chain.invoke({\"topic\": \"bear\"})" "map_chain.invoke({\"topic\": \"bear\"})"
] ]
@ -54,7 +54,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 3,
"id": "267d1460-53c1-4fdb-b2c3-b6a1eb7fccff", "id": "267d1460-53c1-4fdb-b2c3-b6a1eb7fccff",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -64,7 +64,7 @@
"'Harrison worked at Kensho.'" "'Harrison worked at Kensho.'"
] ]
}, },
"execution_count": 4, "execution_count": 3,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -191,7 +191,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.9.1" "version": "3.10.1"
} }
}, },
"nbformat": 4, "nbformat": 4,

Loading…
Cancel
Save