mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-20 13:54:48 +00:00
docs: Add async batch case (#19686)
This commit is contained in:
parent
ec4dcfca7f
commit
aba4bd0d13
@ -323,6 +323,58 @@
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "1f282129-99a3-40f4-b67f-2d0718b1bea9",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"</Column>\n",
|
||||
"</ColumnContainer>\n",
|
||||
"\n",
|
||||
"## Async Batch\n",
|
||||
"\n",
|
||||
"<ColumnContainer>\n",
|
||||
"<Column>\n",
|
||||
"\n",
|
||||
"#### Without LCEL\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "1933f39d-7bd7-45fa-a6a5-5fb7be8e31ec",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import openai\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"async def abatch_chain(topics: list) -> list:\n",
|
||||
" coros = map(ainvoke_chain, topics)\n",
|
||||
" return await asyncio.gather(*coros)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "90691048-17ae-479d-83c2-859e33ddf3eb",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"```python\n",
|
||||
"await abatch_chain([\"ice cream\", \"spaghetti\", \"dumplings\"])\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"</Column>\n",
|
||||
"\n",
|
||||
"<Column>\n",
|
||||
"\n",
|
||||
"#### LCEL\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"await chain.abatch([\"ice cream\", \"spaghetti\", \"dumplings\"])\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f6888245-1ebe-4768-a53b-e1fef6a8b379",
|
||||
|
Loading…
Reference in New Issue
Block a user