{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
╭──────────────────────────────────────────────────── New run ────────────────────────────────────────────────────╮\n", "│ │\n", "│ How many oscasrs did Precious win? │\n", "│ │\n", "╰─ HfApiModel - Qwen/Qwen2.5-Coder-32B-Instruct ──────────────────────────────────────────────────────────────────╯\n", "\n" ], "text/plain": [ "\u001b[38;2;212;183;2m╭─\u001b[0m\u001b[38;2;212;183;2m───────────────────────────────────────────────────\u001b[0m\u001b[38;2;212;183;2m \u001b[0m\u001b[1;38;2;212;183;2mNew run\u001b[0m\u001b[38;2;212;183;2m \u001b[0m\u001b[38;2;212;183;2m───────────────────────────────────────────────────\u001b[0m\u001b[38;2;212;183;2m─╮\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1mHow many oscasrs did Precious win?\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m╰─\u001b[0m\u001b[38;2;212;183;2m HfApiModel - Qwen/Qwen2.5-Coder-32B-Instruct \u001b[0m\u001b[38;2;212;183;2m─────────────────────────────────────────────────────────────────\u001b[0m\u001b[38;2;212;183;2m─╯\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 1 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n", "\n" ], "text/plain": [ "\u001b[38;2;212;183;2m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ \u001b[0m\u001b[1mStep \u001b[0m\u001b[1;36m1\u001b[0m\u001b[38;2;212;183;2m ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
─ Executing parsed code: ──────────────────────────────────────────────────────────────────────────────────────── \n", " oscars_info = web_search(query=\"Precious oscars\") \n", " print(oscars_info) \n", " ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── \n", "\n" ], "text/plain": [ " ─ \u001b[1mExecuting parsed code:\u001b[0m ──────────────────────────────────────────────────────────────────────────────────────── \n", " \u001b[38;2;248;248;242;48;2;39;40;34moscars_info\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mweb_search\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mquery\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mPrecious oscars\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34mprint\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34moscars_info\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Execution logs:\n",
"## Search Results\n",
"\n",
"[List of accolades received by Precious - \n",
"Wikipedia](https://en.wikipedia.org/wiki/List_of_accolades_received_by_Precious)\n",
"Precious: Based on the Novel Push by Sapphire (usually shortened to Precious) is an American drama film directed by\n",
"Lee Daniels that was released in 2009. Precious is an adaptation by Geoffrey S. Fletcher of the 1996 novel Push by \n",
"Sapphire.The film was released by Lions Gate Entertainment on November 6, 2009, in the United States and Canada, \n",
"grossing over $1.8 million in its opening weekend in ...\n",
"\n",
"[Precious (film) - Wikipedia](https://en.wikipedia.org/wiki/Precious_(film))\n",
"Precious: Based on the Novel \"Push\" by Sapphire, [2] or simply Precious, is a 2009 American drama film, directed \n",
"and co-produced by Lee Daniels.Its script was written by Geoffrey S. Fletcher, adapted from the 1996 novel Push by \n",
"Sapphire.The film stars Gabourey Sidibe and Mo'Nique, alongside Paula Patton, Mariah Carey, Sherri Shepherd, and \n",
"Lenny Kravitz.\n",
"\n",
"[Preciosa (2009) - Awards - IMDb](https://www.imdb.com/title/tt0929632/awards/)\n",
"Oscars Black History Month Sundance Film Festival SXSW Film Festival STARmeter Awards Awards Central Festival \n",
"Central All Events. Celebs. Born Today Most Popular Celebs Celebrity News. ... PRECIOUS: BASED ON THE NOVEL 'PUSH' \n",
"BY SAPPHIRE is the celebration of a life lived against all odds. Director Lee Daniels and writer Geoffrey Fletcher \n",
"bring ...\n",
"\n",
"[List of awards and nominations received by \n",
"Mo'Nique](https://en.wikipedia.org/wiki/List_of_awards_and_nominations_received_by_Mo'Nique)\n",
"Mo'Nique is an American actress and comedian. Over the course of her career, she has been the recipient of a number\n",
"of award wins and nominations, including a 2001 Grammy Award nomination for Best Comedy Album, and for her \n",
"critically acclaimed role as Mary Lee Johnston in the 2009 film Precious, for which she received more than 60 \n",
"nominations; in particular, winning the Academy Award for Best ...\n",
"\n",
"[The 82nd Academy Awards | 2010 - Oscars.org](https://www.oscars.org/oscars/ceremonies/2010)\n",
"The 82nd Academy Awards | 2010. The 82nd Academy Awards | 2010. Honoring movies released in 2009, Kodak Theatre at \n",
"Hollywood & Highland Center ... Precious: Based on the Novel 'Push' by Sapphire. Nominees. Penélope Cruz. Nine. \n",
"Nominees. Vera Farmiga. Up in the Air. Nominees. Maggie Gyllenhaal. Crazy Heart.\n",
"\n",
"[Precious: Based on the Novel Push by Sapphire - Oscars \n",
"Wiki](https://oscars.fandom.com/wiki/Precious:_Based_on_the_Novel_Push_by_Sapphire)\n",
"Precious: Based on the Novel Push by Sapphire, often shortened to Precious, was nominated for six Academy Awards \n",
"and took home two. The film, directed by Lee Daniels, is an adaptation by Geoffrey Fletcher of the 1996 novel Push \n",
"by Sapphire, and stars Gabourey Sidibe, Mo'Nique, Paula Patton, and Mariah Carey. The film marked Sidibe's acting \n",
"debut, and earned her a Best Actress Oscar nomination ...\n",
"\n",
"[Mo'Nique Wins Best Supporting Actress | 82nd Oscars (2010)](https://www.youtube.com/watch?v=dxxqA4NhQM4)\n",
"Robin Williams presenting Mo'Nique with the Oscar® for Best Supporting Actress for her performance in \"Precious\" at\n",
"the 82nd Annual Academy Awards®.Subscrib...\n",
"\n",
"[Mo'Nique Oscar Worthy Performance Precious (2009) - YouTube](https://www.youtube.com/watch?v=GvTGR4FwOPM)\n",
"Mo'Nique's Oscar-worthy performance in the 2009 film \"Precious\".\n",
"\n",
"[Precious (2009) - IMDb](https://www.imdb.com/title/tt0929632/)\n",
"Precious: Directed by Lee Daniels. With Gabourey Sidibe, Mo'Nique, Paula Patton, Mariah Carey. In New York City's \n",
"Harlem circa 1987, an overweight, abused, illiterate teen who is pregnant with her second child is invited to \n",
"enroll in an alternative school in hopes that she can re-route her life in a better direction.\n",
"\n",
"[Precious Wins Adapted Screenplay: 2010 Oscars - YouTube](https://www.youtube.com/watch?v=kc5a3nPWihw)\n",
"Jake Gyllenhaal and Rachel McAdams present Geoffrey Fletcher with the Oscar for Adapted Screenplay for Precious: \n",
"Based on the Novel 'Push' by Sapphire at the...\n",
"\n",
"Out: None\n",
"\n"
],
"text/plain": [
"\u001b[1mExecution logs:\u001b[0m\n",
"## Search Results\n",
"\n",
"[List of accolades received by Precious - \n",
"Wikipedia](https://en.wikipedia.org/wiki/List_of_accolades_received_by_Precious)\n",
"Precious: Based on the Novel Push by Sapphire (usually shortened to Precious) is an American drama film directed by\n",
"Lee Daniels that was released in 2009. Precious is an adaptation by Geoffrey S. Fletcher of the 1996 novel Push by \n",
"Sapphire.The film was released by Lions Gate Entertainment on November 6, 2009, in the United States and Canada, \n",
"grossing over $1.8 million in its opening weekend in ...\n",
"\n",
"[Precious (film) - Wikipedia](https://en.wikipedia.org/wiki/Precious_(film))\n",
"Precious: Based on the Novel \"Push\" by Sapphire, [2] or simply Precious, is a 2009 American drama film, directed \n",
"and co-produced by Lee Daniels.Its script was written by Geoffrey S. Fletcher, adapted from the 1996 novel Push by \n",
"Sapphire.The film stars Gabourey Sidibe and Mo'Nique, alongside Paula Patton, Mariah Carey, Sherri Shepherd, and \n",
"Lenny Kravitz.\n",
"\n",
"[Preciosa (2009) - Awards - IMDb](https://www.imdb.com/title/tt0929632/awards/)\n",
"Oscars Black History Month Sundance Film Festival SXSW Film Festival STARmeter Awards Awards Central Festival \n",
"Central All Events. Celebs. Born Today Most Popular Celebs Celebrity News. ... PRECIOUS: BASED ON THE NOVEL 'PUSH' \n",
"BY SAPPHIRE is the celebration of a life lived against all odds. Director Lee Daniels and writer Geoffrey Fletcher \n",
"bring ...\n",
"\n",
"[List of awards and nominations received by \n",
"Mo'Nique](https://en.wikipedia.org/wiki/List_of_awards_and_nominations_received_by_Mo'Nique)\n",
"Mo'Nique is an American actress and comedian. Over the course of her career, she has been the recipient of a number\n",
"of award wins and nominations, including a 2001 Grammy Award nomination for Best Comedy Album, and for her \n",
"critically acclaimed role as Mary Lee Johnston in the 2009 film Precious, for which she received more than 60 \n",
"nominations; in particular, winning the Academy Award for Best ...\n",
"\n",
"[The 82nd Academy Awards | 2010 - Oscars.org](https://www.oscars.org/oscars/ceremonies/2010)\n",
"The 82nd Academy Awards | 2010. The 82nd Academy Awards | 2010. Honoring movies released in 2009, Kodak Theatre at \n",
"Hollywood & Highland Center ... Precious: Based on the Novel 'Push' by Sapphire. Nominees. Penélope Cruz. Nine. \n",
"Nominees. Vera Farmiga. Up in the Air. Nominees. Maggie Gyllenhaal. Crazy Heart.\n",
"\n",
"[Precious: Based on the Novel Push by Sapphire - Oscars \n",
"Wiki](https://oscars.fandom.com/wiki/Precious:_Based_on_the_Novel_Push_by_Sapphire)\n",
"Precious: Based on the Novel Push by Sapphire, often shortened to Precious, was nominated for six Academy Awards \n",
"and took home two. The film, directed by Lee Daniels, is an adaptation by Geoffrey Fletcher of the 1996 novel Push \n",
"by Sapphire, and stars Gabourey Sidibe, Mo'Nique, Paula Patton, and Mariah Carey. The film marked Sidibe's acting \n",
"debut, and earned her a Best Actress Oscar nomination ...\n",
"\n",
"[Mo'Nique Wins Best Supporting Actress | 82nd Oscars (2010)](https://www.youtube.com/watch?v=dxxqA4NhQM4)\n",
"Robin Williams presenting Mo'Nique with the Oscar® for Best Supporting Actress for her performance in \"Precious\" at\n",
"the 82nd Annual Academy Awards®.Subscrib...\n",
"\n",
"[Mo'Nique Oscar Worthy Performance Precious (2009) - YouTube](https://www.youtube.com/watch?v=GvTGR4FwOPM)\n",
"Mo'Nique's Oscar-worthy performance in the 2009 film \"Precious\".\n",
"\n",
"[Precious (2009) - IMDb](https://www.imdb.com/title/tt0929632/)\n",
"Precious: Directed by Lee Daniels. With Gabourey Sidibe, Mo'Nique, Paula Patton, Mariah Carey. In New York City's \n",
"Harlem circa 1987, an overweight, abused, illiterate teen who is pregnant with her second child is invited to \n",
"enroll in an alternative school in hopes that she can re-route her life in a better direction.\n",
"\n",
"[Precious Wins Adapted Screenplay: 2010 Oscars - YouTube](https://www.youtube.com/watch?v=kc5a3nPWihw)\n",
"Jake Gyllenhaal and Rachel McAdams present Geoffrey Fletcher with the Oscar for Adapted Screenplay for Precious: \n",
"Based on the Novel 'Push' by Sapphire at the...\n",
"\n",
"Out: None\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"[Step 1: Duration 5.40 seconds| Input tokens: 2,080 | Output tokens: 72]\n",
"\n"
],
"text/plain": [
"\u001b[2m[Step 1: Duration 5.40 seconds| Input tokens: 2,080 | Output tokens: 72]\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 2 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n", "\n" ], "text/plain": [ "\u001b[38;2;212;183;2m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ \u001b[0m\u001b[1mStep \u001b[0m\u001b[1;36m2\u001b[0m\u001b[38;2;212;183;2m ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
─ Executing parsed code: ──────────────────────────────────────────────────────────────────────────────────────── \n", " final_answer(2) \n", " ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── \n", "\n" ], "text/plain": [ " ─ \u001b[1mExecuting parsed code:\u001b[0m ──────────────────────────────────────────────────────────────────────────────────────── \n", " \u001b[38;2;248;248;242;48;2;39;40;34mfinal_answer\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;174;129;255;48;2;39;40;34m2\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Out - Final answer: 2\n",
"\n"
],
"text/plain": [
"\u001b[1;38;2;212;183;2mOut - Final answer: 2\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"[Step 2: Duration 5.08 seconds| Input tokens: 5,371 | Output tokens: 141]\n",
"\n"
],
"text/plain": [
"\u001b[2m[Step 2: Duration 5.08 seconds| Input tokens: 5,371 | Output tokens: 141]\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel\n",
"\n",
"agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel())\n",
"\n",
"agent.run(\"How many oscasrs did Precious win?\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"╭──────────────────────────────────────────────────── New run ────────────────────────────────────────────────────╮\n", "│ │\n", "│ Prepare a formal menu for the party. │\n", "│ │\n", "╰─ HfApiModel - Qwen/Qwen2.5-Coder-32B-Instruct ──────────────────────────────────────────────────────────────────╯\n", "\n" ], "text/plain": [ "\u001b[38;2;212;183;2m╭─\u001b[0m\u001b[38;2;212;183;2m───────────────────────────────────────────────────\u001b[0m\u001b[38;2;212;183;2m \u001b[0m\u001b[1;38;2;212;183;2mNew run\u001b[0m\u001b[38;2;212;183;2m \u001b[0m\u001b[38;2;212;183;2m───────────────────────────────────────────────────\u001b[0m\u001b[38;2;212;183;2m─╮\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1mPrepare a formal menu for the party.\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m╰─\u001b[0m\u001b[38;2;212;183;2m HfApiModel - Qwen/Qwen2.5-Coder-32B-Instruct \u001b[0m\u001b[38;2;212;183;2m─────────────────────────────────────────────────────────────────\u001b[0m\u001b[38;2;212;183;2m─╯\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 1 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n", "\n" ], "text/plain": [ "\u001b[38;2;212;183;2m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ \u001b[0m\u001b[1mStep \u001b[0m\u001b[1;36m1\u001b[0m\u001b[38;2;212;183;2m ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Error in generating model output:\n", "502 Server Error: Bad Gateway for url: \n", "https://router.huggingface.co/hf-inference/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions\n", "\n" ], "text/plain": [ "\u001b[1;31mError in generating model output:\u001b[0m\n", "\u001b[1;36m502\u001b[0m\u001b[1;31m Server Error: Bad Gateway for url: \u001b[0m\n", "\u001b[4;94mhttps://router.huggingface.co/hf-inference/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
[Step 1: Duration 0.71 seconds]\n",
"\n"
],
"text/plain": [
"\u001b[2m[Step 1: Duration 0.71 seconds]\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 2 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n", "\n" ], "text/plain": [ "\u001b[38;2;212;183;2m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ \u001b[0m\u001b[1mStep \u001b[0m\u001b[1;36m2\u001b[0m\u001b[38;2;212;183;2m ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
─ Executing parsed code: ──────────────────────────────────────────────────────────────────────────────────────── \n", " formal_menu = suggest_menu(occasion=\"formal\") \n", " print(formal_menu) \n", " ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── \n", "\n" ], "text/plain": [ " ─ \u001b[1mExecuting parsed code:\u001b[0m ──────────────────────────────────────────────────────────────────────────────────────── \n", " \u001b[38;2;248;248;242;48;2;39;40;34mformal_menu\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34msuggest_menu\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34moccasion\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mformal\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34mprint\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mformal_menu\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Execution logs:\n",
"3-course dinner with wine and dessert.\n",
"\n",
"Out: None\n",
"\n"
],
"text/plain": [
"\u001b[1mExecution logs:\u001b[0m\n",
"3-course dinner with wine and dessert.\n",
"\n",
"Out: None\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"[Step 2: Duration 3.69 seconds| Input tokens: 2,186 | Output tokens: 72]\n",
"\n"
],
"text/plain": [
"\u001b[2m[Step 2: Duration 3.69 seconds| Input tokens: 2,186 | Output tokens: 72]\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 3 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n", "\n" ], "text/plain": [ "\u001b[38;2;212;183;2m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ \u001b[0m\u001b[1mStep \u001b[0m\u001b[1;36m3\u001b[0m\u001b[38;2;212;183;2m ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
─ Executing parsed code: ──────────────────────────────────────────────────────────────────────────────────────── \n", " formal_menu = suggest_menu(occasion=\"formal\") \n", " if formal_menu: \n", " print(formal_menu) \n", " else: \n", " print(\"No menu suggestion provided.\") \n", " ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── \n", "\n" ], "text/plain": [ " ─ \u001b[1mExecuting parsed code:\u001b[0m ──────────────────────────────────────────────────────────────────────────────────────── \n", " \u001b[38;2;248;248;242;48;2;39;40;34mformal_menu\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34msuggest_menu\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34moccasion\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mformal\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;102;217;239;48;2;39;40;34mif\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mformal_menu\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m:\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mprint\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mformal_menu\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;102;217;239;48;2;39;40;34melse\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m:\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mprint\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mNo menu suggestion provided.\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Execution logs:\n",
"3-course dinner with wine and dessert.\n",
"\n",
"Out: None\n",
"\n"
],
"text/plain": [
"\u001b[1mExecution logs:\u001b[0m\n",
"3-course dinner with wine and dessert.\n",
"\n",
"Out: None\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"[Step 3: Duration 4.57 seconds| Input tokens: 4,536 | Output tokens: 156]\n",
"\n"
],
"text/plain": [
"\u001b[2m[Step 3: Duration 4.57 seconds| Input tokens: 4,536 | Output tokens: 156]\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 4 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n", "\n" ], "text/plain": [ "\u001b[38;2;212;183;2m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ \u001b[0m\u001b[1mStep \u001b[0m\u001b[1;36m4\u001b[0m\u001b[38;2;212;183;2m ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
─ Executing parsed code: ──────────────────────────────────────────────────────────────────────────────────────── \n", " formal_menu = { \n", " \"Appetizer\": \"Smoked Salmon and Asparagus Tart\", \n", " \"Main Course\": \"Osso Buco with Parmesan Polenta\", \n", " \"Dessert\": \"Chocolate Lava Cake with Vanilla Ice Cream\", \n", " \"Wine Pairings\": { \n", " \"Appetizer\": \"Pinot Grigio\", \n", " \"Main Course\": \"Barolo\", \n", " \"Dessert\": \"Dolcetto D'Alba\" \n", " } \n", " } \n", " print(formal_menu) \n", " ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── \n", "\n" ], "text/plain": [ " ─ \u001b[1mExecuting parsed code:\u001b[0m ──────────────────────────────────────────────────────────────────────────────────────── \n", " \u001b[38;2;248;248;242;48;2;39;40;34mformal_menu\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m{\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mAppetizer\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m:\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mSmoked Salmon and Asparagus Tart\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mMain Course\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m:\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mOsso Buco with Parmesan Polenta\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mDessert\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m:\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mChocolate Lava Cake with Vanilla Ice Cream\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mWine Pairings\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m:\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m{\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mAppetizer\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m:\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mPinot Grigio\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mMain Course\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m:\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mBarolo\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mDessert\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m:\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mDolcetto D\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m'\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mAlba\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m}\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34m}\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34mprint\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mformal_menu\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Execution logs:\n",
"{'Appetizer': 'Smoked Salmon and Asparagus Tart', 'Main Course': 'Osso Buco with Parmesan Polenta', 'Dessert': \n",
"'Chocolate Lava Cake with Vanilla Ice Cream', 'Wine Pairings': {'Appetizer': 'Pinot Grigio', 'Main Course': \n",
"'Barolo', 'Dessert': \"Dolcetto D'Alba\"}}\n",
"\n",
"Out: None\n",
"\n"
],
"text/plain": [
"\u001b[1mExecution logs:\u001b[0m\n",
"{'Appetizer': 'Smoked Salmon and Asparagus Tart', 'Main Course': 'Osso Buco with Parmesan Polenta', 'Dessert': \n",
"'Chocolate Lava Cake with Vanilla Ice Cream', 'Wine Pairings': {'Appetizer': 'Pinot Grigio', 'Main Course': \n",
"'Barolo', 'Dessert': \"Dolcetto D'Alba\"}}\n",
"\n",
"Out: None\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"[Step 4: Duration 15.03 seconds| Input tokens: 7,080 | Output tokens: 314]\n",
"\n"
],
"text/plain": [
"\u001b[2m[Step 4: Duration 15.03 seconds| Input tokens: 7,080 | Output tokens: 314]\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 5 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n", "\n" ], "text/plain": [ "\u001b[38;2;212;183;2m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ \u001b[0m\u001b[1mStep \u001b[0m\u001b[1;36m5\u001b[0m\u001b[38;2;212;183;2m ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
─ Executing parsed code: ──────────────────────────────────────────────────────────────────────────────────────── \n", " final_answer(formal_menu) \n", " ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── \n", "\n" ], "text/plain": [ " ─ \u001b[1mExecuting parsed code:\u001b[0m ──────────────────────────────────────────────────────────────────────────────────────── \n", " \u001b[38;2;248;248;242;48;2;39;40;34mfinal_answer\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mformal_menu\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Out - Final answer: {'Appetizer': 'Smoked Salmon and Asparagus Tart', 'Main Course': 'Osso Buco with Parmesan \n", "Polenta', 'Dessert': 'Chocolate Lava Cake with Vanilla Ice Cream', 'Wine Pairings': {'Appetizer': 'Pinot Grigio', \n", "'Main Course': 'Barolo', 'Dessert': \"Dolcetto D'Alba\"}}\n", "\n" ], "text/plain": [ "\u001b[1;38;2;212;183;2mOut - Final answer: {'Appetizer': 'Smoked Salmon and Asparagus Tart', 'Main Course': 'Osso Buco with Parmesan \u001b[0m\n", "\u001b[1;38;2;212;183;2mPolenta', 'Dessert': 'Chocolate Lava Cake with Vanilla Ice Cream', 'Wine Pairings': {'Appetizer': 'Pinot Grigio', \u001b[0m\n", "\u001b[1;38;2;212;183;2m'Main Course': 'Barolo', 'Dessert': \"Dolcetto D'Alba\"}}\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
[Step 5: Duration 3.52 seconds| Input tokens: 10,053 | Output tokens: 361]\n",
"\n"
],
"text/plain": [
"\u001b[2m[Step 5: Duration 3.52 seconds| Input tokens: 10,053 | Output tokens: 361]\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"{'Appetizer': 'Smoked Salmon and Asparagus Tart',\n",
" 'Main Course': 'Osso Buco with Parmesan Polenta',\n",
" 'Dessert': 'Chocolate Lava Cake with Vanilla Ice Cream',\n",
" 'Wine Pairings': {'Appetizer': 'Pinot Grigio',\n",
" 'Main Course': 'Barolo',\n",
" 'Dessert': \"Dolcetto D'Alba\"}}"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from smolagents import CodeAgent, tool, HfApiModel\n",
"\n",
"# Tool to suggest a menu based on the occasion\n",
"@tool\n",
"def suggest_menu(occasion: str) -> str:\n",
" \"\"\"\n",
" Suggests a menu based on the occasion.\n",
" Args:\n",
" occasion (str): The type of occasion for the party. Allowed values are:\n",
" - \"casual\": Menu for casual party.\n",
" - \"formal\": Menu for formal party.\n",
" - \"superhero\": Menu for superhero party.\n",
" - \"custom\": Custom menu.\n",
" \"\"\"\n",
" if occasion == \"casual\":\n",
" return \"Pizza, snacks, and drinks.\"\n",
" elif occasion == \"formal\":\n",
" return \"3-course dinner with wine and dessert.\"\n",
" elif occasion == \"superhero\":\n",
" return \"Buffet with high-energy and healthy food.\"\n",
" else:\n",
" return \"Custom menu for the butler.\"\n",
"\n",
"# Alfred, the butler, preparing the menu for the party\n",
"agent = CodeAgent(tools=[suggest_menu], model=HfApiModel())\n",
"\n",
"# Preparing the menu for the party\n",
"agent.run(\"Prepare a formal menu for the party.\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}