|
|
@ -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,
|
|
|
|