Skip to content

Commit

Permalink
Merge pull request #747 from RiptideStar/docs-changes-kyle
Browse files Browse the repository at this point in the history
docs: JSON mode right below Response Models
  • Loading branch information
willbakst authored Dec 17, 2024
2 parents caa009e + 35d6a4d commit 334d3f1
Showing 1 changed file with 69 additions and 69 deletions.
138 changes: 69 additions & 69 deletions docs/tutorials/getting_started/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -207,75 +207,6 @@
"For more details on response models, including advanced validation techniques, check our [documentation on Response Models](../../../learn/response_models)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Asynchronous Processing\n",
"\n",
"Mirascope supports asynchronous processing, allowing for efficient parallel execution of multiple LLM calls. This is particularly useful when you need to make many LLM calls concurrently or when working with asynchronous web frameworks."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-07T01:11:57.536376Z",
"start_time": "2024-09-07T01:11:56.163833Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The capital of France is Paris\n",
"The capital of Japan is Tokyo\n",
"The capital of Brazil is Brasília\n"
]
}
],
"source": [
"import asyncio\n",
"\n",
"\n",
"@openai.call(\"gpt-4o-mini\", response_model=Capital)\n",
"async def get_capital_async(country: str) -> str:\n",
" return f\"What is the capital of {country}?\"\n",
"\n",
"\n",
"async def main():\n",
" countries = [\"France\", \"Japan\", \"Brazil\"]\n",
" tasks = [get_capital_async(country) for country in countries]\n",
" capitals = await asyncio.gather(*tasks)\n",
" for capital in capitals:\n",
" print(f\"The capital of {capital.country} is {capital.city}\")\n",
"\n",
"\n",
"# await main() when running in a Jupyter notebook\n",
"await main()\n",
"\n",
"# asyncio.run(main()) when running in a Python script"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This asynchronous example demonstrates:\n",
"1. An async version of our `get_capital` function, defined with `async def`.\n",
"2. Use of `asyncio.gather()` to run multiple async tasks concurrently.\n",
"3. Processing of results as they become available.\n",
"\n",
"Asynchronous processing offers several advantages:\n",
"- Improved performance when making multiple LLM calls\n",
"- Better resource utilization\n",
"- Compatibility with async web frameworks like FastAPI or aiohttp\n",
"\n",
"For more advanced asynchronous techniques, including error handling and async streaming, refer to our [documentation on Async](../../../learn/async)."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -422,6 +353,75 @@
"For more information on JSON mode and its limitations with different providers, refer to our [documentation on JSON Mode](../../../learn/json_mode)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Asynchronous Processing\n",
"\n",
"Mirascope supports asynchronous processing, allowing for efficient parallel execution of multiple LLM calls. This is particularly useful when you need to make many LLM calls concurrently or when working with asynchronous web frameworks."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-07T01:11:57.536376Z",
"start_time": "2024-09-07T01:11:56.163833Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The capital of France is Paris\n",
"The capital of Japan is Tokyo\n",
"The capital of Brazil is Brasília\n"
]
}
],
"source": [
"import asyncio\n",
"\n",
"\n",
"@openai.call(\"gpt-4o-mini\", response_model=Capital)\n",
"async def get_capital_async(country: str) -> str:\n",
" return f\"What is the capital of {country}?\"\n",
"\n",
"\n",
"async def main():\n",
" countries = [\"France\", \"Japan\", \"Brazil\"]\n",
" tasks = [get_capital_async(country) for country in countries]\n",
" capitals = await asyncio.gather(*tasks)\n",
" for capital in capitals:\n",
" print(f\"The capital of {capital.country} is {capital.city}\")\n",
"\n",
"\n",
"# await main() when running in a Jupyter notebook\n",
"await main()\n",
"\n",
"# asyncio.run(main()) when running in a Python script"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This asynchronous example demonstrates:\n",
"1. An async version of our `get_capital` function, defined with `async def`.\n",
"2. Use of `asyncio.gather()` to run multiple async tasks concurrently.\n",
"3. Processing of results as they become available.\n",
"\n",
"Asynchronous processing offers several advantages:\n",
"- Improved performance when making multiple LLM calls\n",
"- Better resource utilization\n",
"- Compatibility with async web frameworks like FastAPI or aiohttp\n",
"\n",
"For more advanced asynchronous techniques, including error handling and async streaming, refer to our [documentation on Async](../../../learn/async)."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down

0 comments on commit 334d3f1

Please sign in to comment.