|
|
@ -300,7 +300,10 @@
|
|
|
|
"async def ainvoke_chain(topic: str) -> str:\n",
|
|
|
|
"async def ainvoke_chain(topic: str) -> str:\n",
|
|
|
|
" prompt_value = prompt_template.format(topic=topic)\n",
|
|
|
|
" prompt_value = prompt_template.format(topic=topic)\n",
|
|
|
|
" messages = [{\"role\": \"user\", \"content\": prompt_value}]\n",
|
|
|
|
" messages = [{\"role\": \"user\", \"content\": prompt_value}]\n",
|
|
|
|
" return await acall_chat_model(messages)"
|
|
|
|
" return await acall_chat_model(messages)\n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
"await ainvoke_chain(\"ice cream\")"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -308,19 +311,22 @@
|
|
|
|
"id": "2f209290-498c-4c17-839e-ee9002919846",
|
|
|
|
"id": "2f209290-498c-4c17-839e-ee9002919846",
|
|
|
|
"metadata": {},
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"source": [
|
|
|
|
"```python\n",
|
|
|
|
|
|
|
|
"await ainvoke_chain(\"ice cream\")\n",
|
|
|
|
|
|
|
|
"```\n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
"</Column>\n",
|
|
|
|
"</Column>\n",
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"<Column>\n",
|
|
|
|
"<Column>\n",
|
|
|
|
"\n",
|
|
|
|
" \n",
|
|
|
|
"#### LCEL\n",
|
|
|
|
"#### LCEL\n",
|
|
|
|
"\n",
|
|
|
|
"\n"
|
|
|
|
"```python\n",
|
|
|
|
]
|
|
|
|
"await chain.ainvoke(\"ice cream\")\n",
|
|
|
|
},
|
|
|
|
"```"
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
|
|
|
"id": "4d009781-7307-48a4-8439-f9d3dd015560",
|
|
|
|
|
|
|
|
"metadata": {},
|
|
|
|
|
|
|
|
"outputs": [],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"await chain.ainvoke(\"ice cream\")"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -347,12 +353,16 @@
|
|
|
|
"metadata": {},
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"import asyncio\n",
|
|
|
|
"import openai\n",
|
|
|
|
"import openai\n",
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"async def abatch_chain(topics: list) -> list:\n",
|
|
|
|
"async def abatch_chain(topics: list) -> list:\n",
|
|
|
|
" coros = map(ainvoke_chain, topics)\n",
|
|
|
|
" coros = map(ainvoke_chain, topics)\n",
|
|
|
|
" return await asyncio.gather(*coros)\n"
|
|
|
|
" return await asyncio.gather(*coros)\n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
"await abatch_chain([\"ice cream\", \"spaghetti\", \"dumplings\"])"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -360,19 +370,22 @@
|
|
|
|
"id": "90691048-17ae-479d-83c2-859e33ddf3eb",
|
|
|
|
"id": "90691048-17ae-479d-83c2-859e33ddf3eb",
|
|
|
|
"metadata": {},
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"source": [
|
|
|
|
"```python\n",
|
|
|
|
|
|
|
|
"await abatch_chain([\"ice cream\", \"spaghetti\", \"dumplings\"])\n",
|
|
|
|
|
|
|
|
"```\n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
"</Column>\n",
|
|
|
|
"</Column>\n",
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"<Column>\n",
|
|
|
|
"<Column>\n",
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"#### LCEL\n",
|
|
|
|
"#### LCEL\n",
|
|
|
|
"\n",
|
|
|
|
"\n"
|
|
|
|
"```python\n",
|
|
|
|
]
|
|
|
|
"await chain.abatch([\"ice cream\", \"spaghetti\", \"dumplings\"])\n",
|
|
|
|
},
|
|
|
|
"```"
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
|
|
|
"id": "947dad23-3443-40eb-a03b-7840c261e261",
|
|
|
|
|
|
|
|
"metadata": {},
|
|
|
|
|
|
|
|
"outputs": [],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"await chain.abatch([\"ice cream\", \"spaghetti\", \"dumplings\"])"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|