diff --git a/notebooks/agents/Multi_Step_Tool_Use_Spotify_v2.ipynb b/notebooks/agents/Multi_Step_Tool_Use_Spotify_v2.ipynb index bb1960b..577ab9f 100644 --- a/notebooks/agents/Multi_Step_Tool_Use_Spotify_v2.ipynb +++ b/notebooks/agents/Multi_Step_Tool_Use_Spotify_v2.ipynb @@ -30,6 +30,15 @@ "## Setup" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "! pip install cohere==5.11.3 pandas==2.2.2" + ] + }, { "cell_type": "code", "execution_count": 1, @@ -46,12 +55,11 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ - "! pip install tavily-python --q\n", - "\n", + "! pip install tavily-python --q --disable-pip-version-check\n", "from tavily import TavilyClient\n", "tavily_client = TavilyClient(api_key=\"TAVILY_API_KEY\")" ] @@ -73,19 +81,19 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# here's a web search engine\n", "def web_search(query: str) -> list[dict]:\n", - " response = tavily_client.search(query, max_results=3)['results']\n", - " return {\"results\": response}" + " results = tavily_client.search(query, max_results=3)[\"results\"]\n", + " return results" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -100,13 +108,13 @@ " \"properties\": {\n", " \"query\": {\n", " \"type\": \"string\",\n", - " \"description\": \"Query to search the internet with\"\n", + " \"description\": \"Query to search the internet with\",\n", " }\n", " },\n", - " \"required\": [\"query\"]\n", - " }\n", - " }\n", - "}\n" + " \"required\": [\"query\"],\n", + " },\n", + " },\n", + "}" ] }, { @@ -118,12 +126,14 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# here's a python console, which can be used to access the spreadsheet, but also more generally to code and plot stuff\n", "import io, contextlib\n", + "\n", + "\n", "def python_interpreter(code: str) -> list[dict]:\n", " output = io.StringIO()\n", " try:\n", @@ -131,21 +141,14 @@ " with contextlib.redirect_stdout(output):\n", " exec(code, globals())\n", " except Exception as e:\n", - " return {\n", - " \"error\": str(e),\n", - " \"executed_code\": code\n", - " }\n", + " return {\"error\": str(e), \"executed_code\": code}\n", " # Get stdout\n", - " return {\n", - " \t\t\"console_output\": output.getvalue(),\n", - " \"executed_code\": code\n", - " \t}\n", - "\n" + " return [{\"console_output\": output.getvalue(), \"executed_code\": code}]" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -171,7 +174,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -190,17 +193,9 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 9, "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/meor/anaconda3/lib/python3.11/site-packages/pandas/core/arrays/masked.py:60: UserWarning: Pandas requires version '1.3.6' or newer of 'bottleneck' (version '1.3.5' currently installed).\n", - " from pandas.core import (\n" - ] - }, { "data": { "text/html": [ @@ -352,7 +347,7 @@ "[3 rows x 25 columns]" ] }, - "execution_count": 7, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -374,7 +369,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -409,7 +404,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -427,87 +422,347 @@ "==================================================\n", "\n", "TOOL PLAN:\n", - "I will first inspect the dataset to understand its structure and the columns it contains. Then, I will write and execute Python code to find the top 3 most streamed songs on Spotify in 2023 and their respective artists. Finally, I will search for the age and citizenship of each artist online.\n", + "I will first inspect the dataset to understand its structure. Then, I will use Python to find the top 3 most streamed songs on Spotify in 2023. I will then search for the age and citizenship of the artists of these songs.\n", "\n", "TOOL CALLS:\n", "Tool name: python_interpreter\n", " import pandas as pd\n", " \n", - " df = pd.read_csv('spotify_dataset.csv')\n", + " df = pd.read_csv(\"spotify_dataset.csv\")\n", " \n", - " print(df.columns)\n", + " # Inspect the dataset\n", + " print(\"Columns:\", df.columns.tolist())\n", + " print(\"Data types:\", df.dtypes)\n", + " print(\"First 5 rows:\")\n", + " print(df.head())\n", "None\n", "\n", "TOOL RESULTS:\n", - "{'console_output': \"Index(['track_name', 'artist(s)_name', 'artist_count', 'released_year',\\n 'released_month', 'released_day', 'in_spotify_playlists',\\n 'in_spotify_charts', 'streams', 'in_apple_playlists', 'in_apple_charts',\\n 'in_deezer_playlists', 'in_deezer_charts', 'in_shazam_charts', 'bpm',\\n 'key', 'mode', 'danceability', 'valence', 'energy', 'acousticness',\\n 'instrumentalness', 'liveness', 'speechiness', 'release_date'],\\n dtype='object')\\n\", 'executed_code': \"import pandas as pd\\n\\ndf = pd.read_csv('spotify_dataset.csv')\\n\\nprint(df.columns)\"} \n", + "[{'console_output': \"Columns: ['track_name', 'artist(s)_name', 'artist_count', 'released_year', 'released_month', 'released_day', 'in_spotify_playlists', 'in_spotify_charts', 'streams', 'in_apple_playlists', 'in_apple_charts', 'in_deezer_playlists', 'in_deezer_charts', 'in_shazam_charts', 'bpm', 'key', 'mode', 'danceability', 'valence', 'energy', 'acousticness', 'instrumentalness', 'liveness', 'speechiness', 'release_date']\\nData types: track_name object\\nartist(s)_name object\\nartist_count int64\\nreleased_year int64\\nreleased_month int64\\nreleased_day int64\\nin_spotify_playlists int64\\nin_spotify_charts int64\\nstreams float64\\nin_apple_playlists int64\\nin_apple_charts int64\\nin_deezer_playlists object\\nin_deezer_charts int64\\nin_shazam_charts object\\nbpm int64\\nkey object\\nmode object\\ndanceability int64\\nvalence int64\\nenergy int64\\nacousticness int64\\ninstrumentalness int64\\nliveness int64\\nspeechiness int64\\nrelease_date object\\ndtype: object\\nFirst 5 rows:\\n track_name artist(s)_name artist_count \\\\\\n0 Seven (feat. Latto) (Explicit Ver.) Latto, Jung Kook 2 \\n1 LALA Myke Towers 1 \\n2 vampire Olivia Rodrigo 1 \\n3 Cruel Summer Taylor Swift 1 \\n4 WHERE SHE GOES Bad Bunny 1 \\n\\n released_year released_month released_day in_spotify_playlists \\\\\\n0 2023 7 14 553 \\n1 2023 3 23 1474 \\n2 2023 6 30 1397 \\n3 2019 8 23 7858 \\n4 2023 5 18 3133 \\n\\n in_spotify_charts streams in_apple_playlists ... key mode \\\\\\n0 147 141381703.0 43 ... B Major \\n1 48 133716286.0 48 ... C# Major \\n2 113 140003974.0 94 ... F Major \\n3 100 800840817.0 116 ... A Major \\n4 50 303236322.0 84 ... A Minor \\n\\n danceability valence energy acousticness instrumentalness liveness \\\\\\n0 80 89 83 31 0 8 \\n1 71 61 74 7 0 10 \\n2 51 32 53 17 0 31 \\n3 55 58 72 11 0 11 \\n4 65 23 80 14 63 11 \\n\\n speechiness release_date \\n0 4 2023-07-14 \\n1 4 2023-03-23 \\n2 6 2023-06-30 \\n3 15 2019-08-23 \\n4 6 2023-05-18 \\n\\n[5 rows x 25 columns]\\n\", 'executed_code': 'import pandas as pd\\r\\n\\r\\ndf = pd.read_csv(\"spotify_dataset.csv\")\\r\\n\\r\\n# Inspect the dataset\\r\\nprint(\"Columns:\", df.columns.tolist())\\r\\nprint(\"Data types:\", df.dtypes)\\r\\nprint(\"First 5 rows:\")\\r\\nprint(df.head())'}] \n", "\n", "\n", "TOOL PLAN:\n", - "I now know the column names of the dataset. I will now find the top 3 most streamed songs on Spotify in 2023 and then find the age and citizenship of the artists of those songs.\n", + "The dataset contains information about the top streamed songs on Spotify, including the artist's name, the year the song was released, and the number of streams.\n", + "\n", + "I will now write and execute Python code to find the top 3 most streamed songs on Spotify in 2023.\n", "\n", "TOOL CALLS:\n", "Tool name: python_interpreter\n", " import pandas as pd\n", " \n", - " df = pd.read_csv('spotify_dataset.csv')\n", + " df = pd.read_csv(\"spotify_dataset.csv\")\n", " \n", - " # Filter for songs released in 2023\n", - " df_2023 = df[df['released_year'] == 2023]\n", + " # Filter the dataset to only include songs released in 2023\n", + " df_2023 = df[df[\"released_year\"] == 2023]\n", " \n", - " # Sort by streams in descending order\n", - " df_2023 = df_2023.sort_values(by='streams', ascending=False)\n", + " # Sort the songs by the number of streams in descending order\n", + " df_2023_sorted = df_2023.sort_values(by=\"streams\", ascending=False)\n", " \n", - " # Get the top 3 songs\n", - " top_3_songs = df_2023.head(3)\n", + " # Get the top 3 most streamed songs\n", + " top_3_songs = df_2023_sorted.head(3)\n", " \n", - " print(\"Top 3 most streamed songs on Spotify in 2023:\")\n", - " print(top_3_songs[['track_name', 'artist(s)_name']])\n", + " # Print the top 3 most streamed songs\n", + " print(\"Top 3 most streamed songs:\")\n", + " print(top_3_songs[['track_name', 'artist(s)_name', 'streams']])\n", "None\n", "\n", "TOOL RESULTS:\n", - "{'console_output': 'Top 3 most streamed songs on Spotify in 2023:\\n track_name artist(s)_name\\n12 Flowers Miley Cyrus\\n6 Ella Baila Sola Eslabon Armado, Peso Pluma\\n133 Shakira: Bzrp Music Sessions, Vol. 53 Shakira, Bizarrap\\n', 'executed_code': 'import pandas as pd\\n\\ndf = pd.read_csv(\\'spotify_dataset.csv\\')\\n\\n# Filter for songs released in 2023\\ndf_2023 = df[df[\\'released_year\\'] == 2023]\\n\\n# Sort by streams in descending order\\ndf_2023 = df_2023.sort_values(by=\\'streams\\', ascending=False)\\n\\n# Get the top 3 songs\\ntop_3_songs = df_2023.head(3)\\n\\nprint(\"Top 3 most streamed songs on Spotify in 2023:\")\\nprint(top_3_songs[[\\'track_name\\', \\'artist(s)_name\\']])'} \n", + "[{'console_output': 'Top 3 most streamed songs:\\n track_name artist(s)_name \\\\\\n12 Flowers Miley Cyrus \\n6 Ella Baila Sola Eslabon Armado, Peso Pluma \\n133 Shakira: Bzrp Music Sessions, Vol. 53 Shakira, Bizarrap \\n\\n streams \\n12 1.316856e+09 \\n6 7.259801e+08 \\n133 7.219756e+08 \\n', 'executed_code': 'import pandas as pd\\r\\n\\r\\ndf = pd.read_csv(\"spotify_dataset.csv\")\\r\\n\\r\\n# Filter the dataset to only include songs released in 2023\\r\\ndf_2023 = df[df[\"released_year\"] == 2023]\\r\\n\\r\\n# Sort the songs by the number of streams in descending order\\r\\ndf_2023_sorted = df_2023.sort_values(by=\"streams\", ascending=False)\\r\\n\\r\\n# Get the top 3 most streamed songs\\r\\ntop_3_songs = df_2023_sorted.head(3)\\r\\n\\r\\n# Print the top 3 most streamed songs\\r\\nprint(\"Top 3 most streamed songs:\")\\r\\nprint(top_3_songs[[\\'track_name\\', \\'artist(s)_name\\', \\'streams\\']])'}] \n", + "\n", + "\n", + "TOOL PLAN:\n", + "I have found that the top 3 most streamed songs on Spotify in 2023 were:\n", + "1. Flowers by Miley Cyrus\n", + "2. Ella Baila Sola by Eslabon Armado, Peso Pluma\n", + "3. Shakira: Bzrp Music Sessions, Vol. 53 by Shakira, Bizarrap\n", + "\n", + "I will now search for the age and citizenship of each of these artists.\n", + "\n", + "TOOL CALLS:\n", + "Tool name: web_search | Parameters: {\"query\":\"Miley Cyrus age\"}\n", + "Tool name: web_search | Parameters: {\"query\":\"Miley Cyrus citizenship\"}\n", + "Tool name: web_search | Parameters: {\"query\":\"Eslabon Armado age\"}\n", + "Tool name: web_search | Parameters: {\"query\":\"Eslabon Armado citizenship\"}\n", + "Tool name: web_search | Parameters: {\"query\":\"Peso Pluma age\"}\n", + "Tool name: web_search | Parameters: {\"query\":\"Peso Pluma citizenship\"}\n", + "Tool name: web_search | Parameters: {\"query\":\"Shakira age\"}\n", + "Tool name: web_search | Parameters: {\"query\":\"Shakira citizenship\"}\n", + "Tool name: web_search | Parameters: {\"query\":\"Bizarrap age\"}\n", + "Tool name: web_search | Parameters: {\"query\":\"Bizarrap citizenship\"}\n", + "\n", + "TOOL RESULTS:\n", + "[{'title': 'Miley Cyrus Height, Weight, Age, Husband, Bio, Net Worth, Facts', 'url': 'https://www.celebsline.com/miley-cyrus/', 'content': 'Miley Cyrus Height, Weight, Age, Husband, Bio, Net Worth, Facts Miley Cyrus Biography Miley Cyrus Husband and Love Life Miley Cyrus released her first studio album “Meet Miley Cyrus” On June 26, 2007, under the Walt Disney label, which received several Gold and Platinum certificates. Miley Cyrus Net Worth Miley Cyrus’s net worth is estimated at $160 million US dollars as of 2024. Miley Cyrus\\xa0Facts Miley Cyrus was named no. Adam Levine Height, Biography, Age, Wiki, Wife, Net Worth, Facts Anitta Biography, Age, Height, Family, Education, Husband, Albums Gafoor Height, Wiki, Biography, Age, Family, Movies, Facts', 'score': 0.94699025, 'raw_content': None}, {'title': 'Miley Cyrus - Biography - IMDb', 'url': 'https://www.imdb.com/name/nm1415323/bio/', 'content': 'Miley Cyrus is an actress and singer born on November 23, 1992 in Tennessee. She rose to fame as the star of Hannah Montana (2006) and has since appeared in movies, TV shows and music videos.', 'score': 0.9436599, 'raw_content': None}, {'title': 'Miley Cyrus | Biography, TV Shows, Songs, & Facts | Britannica', 'url': 'https://www.britannica.com/biography/Miley-Cyrus', 'content': 'Meanwhile, Cyrus continued to record under her own name for the EP The Time of Our Lives (2009), which featured the hit “Party in the U.S.A.,” and the full-length album Can’t Be Tamed (2010). She then veered away from the mainstream with Miley Cyrus & Her Dead Petz (2015), a collection of loosely psychedelic songs recorded in large part with the rock band the Flaming Lips and made available for free on the Internet. In 2005 Cyrus auditioned for the lead role in Hannah Montana, a Disney Channel series about a girl who leads a double life as a normal middle-school student and, with the help of a blonde wig, as a glamorous pop singer. Cyrus was a coach on the television singing competition The Voice in 2016–17, and she costarred with Woody Allen and Elaine May in Allen’s six-episode TV series Crisis in Six Scenes (2016). The show debuted the following year (featuring Billy Ray as her TV dad) and became an immediate sensation, scoring record ratings for cable television and turning the 13-year-old into a bona fide star.', 'score': 0.8539127, 'raw_content': None}] \n", + "\n", + "[{'title': \"Miley Cyrus Talks Global Citizen's Fight to End Inequality, COVID-19\", 'url': 'https://www.rollingstone.com/music/music-news/miley-cyrus-global-citizen-global-goal-interview-1021734/', 'content': \"Miley Cyrus Talks Fighting Inequality, COVID-19 at Global Citizen's 'Global Goal' Special. Advocacy org's latest event raised $6.9 billion in pledges to help develop, distribute a vaccine to ...\", 'score': 0.98184055, 'raw_content': None}, {'title': 'Miley Cyrus Performs Heartfelt Beatles Cover for ... - Global Citizen', 'url': 'https://www.globalcitizen.org/en/content/miley-cyrus-sings-help-beatles-global-goal-unite/', 'content': \"Miley Cyrus Performs Heartfelt Beatles Cover for 'Global Goal: Unite for Our Future' to Help Beat COVID-19 You can join our Global Goal: Unite for the Future campaign to make sure everyone, everywhere can access the tools needed to beat COVID-19and take action here. The pledging summit prior to the concert, mobilized over $6.9 billion to help the world’s most vulnerable in response to the campaign launched in May. Hosted by Dwayne Johnson, the globally televised and digitally streamed concert event highlighted the disproportionate impact COVID-19 has on marginalized communities. Countries responded to the nearly 800,000 actions Global Citizens, Cyrus, and other celebrities took to fight COVID-19\\xa0and protect the most marginalized people from its impact.\", 'score': 0.9801293, 'raw_content': None}, {'title': 'Miley Cyrus - Ethnicity of Celebs | EthniCelebs.com', 'url': 'https://ethnicelebs.com/miley-cyrus', 'content': 'Date of Birth: November 23, 1992. Ethnicity: English, Scottish, Irish, Welsh, possibly other. Miley Cyrus is an American actress, singer, and songwriter. She has starred on the series Hannah Montana, Crisis in Six Scenes, and Black Mirror: Rachel, Jack and Ashley Too, in the films Bolt, Hannah Montana: The Movie, The Last Song, LOL, and So ...', 'score': 0.7594039, 'raw_content': None}] \n", + "\n", + "[{'title': 'Eslabon Armado - Wikipedia', 'url': 'https://en.wikipedia.org/wiki/Eslabon_Armado', 'content': 'Eslabon Armado is an American regional Mexican group from Patterson, California, formed in 2017.The group consists of Pedro Tovar (lead vocals), Brian Tovar (bass), Ulises González (acoustic guitar), and Damián Pacheco (twelve-string guitar) . For most of their career, the group had a three-piece lineup, consisting of brothers Pedro and Brian Tovar, and their friend Gabriel Hidalgo.', 'score': 0.9983834, 'raw_content': None}, {'title': 'Pedro Tovar - Age, Family, Bio | Famous Birthdays', 'url': 'https://www.famousbirthdays.com/people/pedro-tovar.html', 'content': \"Age 22 years old #7,224 Most Popular. Boost. About . Singer and songwriter who has earned over 950,000 fans on his pedro.tovar007 TikTok account. He provides the lead vocals for the popular trio Eslabon Armado and he wrote and coproduced all nine songs on the band's EP Vibras de Noche. ...\", 'score': 0.9967397, 'raw_content': None}, {'title': 'Eslabón Armado - Members, Ages, Trivia | Famous Birthdays', 'url': 'https://www.famousbirthdays.com/bands/eslab--n-armado.html', 'content': 'Eslabón Armado Members. Pedro Tovar, 22 1. Brian Tovar, 20 2. Gabriel Hidalgo, 23 Former. 3. Damian Pacheco, 22 4. Popularity Band #149 California Band #25 Regional Mexican Band #2 Eslabón Armado Fans Also Viewed Fuerza Regida. Los Tigres del Norte ...', 'score': 0.994089, 'raw_content': None}] \n", + "\n", + "[{'title': 'Eslabon Armado - Wikipedia', 'url': 'https://en.wikipedia.org/wiki/Eslabon_Armado', 'content': 'Eslabon Armado is an American regional Mexican group from Patterson, California, formed in 2017.The group consists of Pedro Tovar (lead vocals), Brian Tovar (bass), Ulises González (acoustic guitar), and Damián Pacheco (twelve-string guitar) . For most of their career, the group had a three-piece lineup, consisting of brothers Pedro and Brian Tovar, and their friend Gabriel Hidalgo.', 'score': 0.99731654, 'raw_content': None}, {'title': 'Eslabon Armado: A New Era in Regional Mexican Music - Lalo', 'url': 'https://www.lalo.app/story/eslabon-armado-new-era-in-regional-mexican-music', 'content': '🇲🇽🇪🇸 Leer versión en español. Eslabon Armado is an American regional Mexican group that breaks boundaries and puts a new spin on traditional Latin music. They started as teenagers in 2017. … And they have since released six studio albums and received numerous awards including two Billboard Music Awards, two Billboard Latin Music Awards, and two Latin American Music Awards.', 'score': 0.97313875, 'raw_content': None}, {'title': 'Eslabon Armado Musician - All About Jazz', 'url': 'https://www.allaboutjazz.com/musicians/eslabon-armado', 'content': \"The record-breaking group Eslabon Armado has defied cultural barriers to surpass all expectations in the most unconventional way possible. Becoming the first ever Mexican act to reach No. 1 on Billboard's Global 200, they are conquering the world and overcoming adversities in the most unconventional way. Born and raised in California to ...\", 'score': 0.96485513, 'raw_content': None}] \n", + "\n", + "[{'title': 'Who is Peso Pluma? His real name, age, height, nationality, and more', 'url': 'https://wegotthiscovered.com/celebrities/who-is-peso-pluma-his-real-name-age-height-nationality-and-more/', 'content': 'Peso Pluma is a 24-year-old rapper, singer, and songwriter from Mexico. He was born on June 15, 1999, and his name means \"heavy feather\" in English.', 'score': 0.9997818, 'raw_content': None}, {'title': 'Peso Pluma - Age, Family, Bio | Famous Birthdays', 'url': 'https://www.famousbirthdays.com/people/peso-pluma.html', 'content': 'Peso Pluma is a 25-year-old rapper from Guadalajara, Mexico, born on June 15, 1999. He has over 10 million Spotify listeners and 13 million Instagram followers, and has collaborated with Becky G and Tony Aguirre.', 'score': 0.9997677, 'raw_content': None}, {'title': 'Peso Pluma talks global rise of Mexican music, performs at Coachella', 'url': 'https://www.usatoday.com/story/entertainment/music/2023/10/03/peso-pluma-interview-genesis-mexican-music-making-history/71029635007/', 'content': 'Peso Pluma is a 24-year-old singer of corridos tumbados and corridos bélicos, a mix of electronic beats and narcoculture lyrics. He has 21 Billboard Latin Music Award nominations, a Coachella performance, and a global fan base.', 'score': 0.99972624, 'raw_content': None}] \n", + "\n", + "[{'title': 'Peso Pluma: The Mexican singer making history and first US tour - NBC ...', 'url': 'https://www.nbcnewyork.com/entertainment/entertainment-news/whos-peso-pluma-what-to-know-about-the-mexican-singer-making-history-and-his-first-us-tour/4515079/', 'content': 'Hassan Emilio Kabande Laija, better known as Peso Pluma, is a 24-year-old Mexican musician who has achieved huge recognition on social media for viral songs -- one of them being \"El Belicon\" which ...', 'score': 0.96458924, 'raw_content': None}, {'title': 'Peso Pluma - Wikipedia', 'url': 'https://en.wikipedia.org/wiki/Peso_Pluma', 'content': 'In this Spanish name, the first or paternal surname is Kabande and the second or maternal family name is Laija. Hassan Emilio Kabande Laija (born 15 June 1999), known professionally as Peso Pluma, is a Mexican rapper and singer. Learning to play the guitar during his early teens, he developed his craft by writing songs inspired by regional ...', 'score': 0.9457011, 'raw_content': None}, {'title': 'How Peso Pluma Brought Mexican Music to the World Stage', 'url': 'https://info.xposuremusic.com/article/peso-pluma-mexican-music', 'content': 'Peso Pluma has thus far racked up 11 top 10 hits in Mexico, while also cracking the U.S. top 40 on six occasions — the highest being his collab with compatriots Eslabon Armado, \"Ella Baila Sola\", which peaked at #4 on the Billboard Hot 100. He\\'s also featured on the remix of Yng Lucas\\' \"La Bebe\", which Pitchfork named among its 20 ...', 'score': 0.9323302, 'raw_content': None}] \n", + "\n", + "[{'title': 'Shakira - Biography - IMDb', 'url': 'https://m.imdb.com/name/nm0787680/bio/', 'content': 'Shakira is a Colombian singer, songwriter, and philanthropist born on February 2, 1977. She is known for her fusion of Latin, rock, and Middle Eastern music styles, her belly dancing skills, and her foundation for education and nutrition.', 'score': 0.9219218, 'raw_content': None}, {'title': 'Shakira | Biography, Music & News - Billboard', 'url': 'https://www.billboard.com/artist/shakira/', 'content': 'Shakira is a Colombian singer born on Feb. 2, 1977. She has released several albums in English and Spanish, and has won multiple Grammys and Billboard awards.', 'score': 0.9129032, 'raw_content': None}, {'title': 'Shakira Biography - Facts, Childhood, Family Life & Achievements', 'url': 'https://www.thefamouspeople.com/profiles/shakira-4125.php', 'content': \"Shakira Biography Shakira is a highly successful Columbian pop artist, best known for her scintillating belly dance moves in the video of the song ‘Hips Don’t Lie.’ Having a keen interest in music from childhood, Shakira wrote her first poem when she was just 4. Also Known As: Shakira Isabel Mebarak Ripoll How did Shakira start her music career? What is Shakira's most popular song? Where is Shakira from? What languages does Shakira speak? Recommended Lists: Shakira was born Shakira Isabel Mebarak Ripoll on February 2, 1977, in Barranquilla, Colombia, to Nidia Ripoll and William Mebarak Chadid. Shakira's tenth studio album released on March 25, 2014. Shakira and Gerard were blessed with a son named Milan Pique on January 22, 2013.\", 'score': 0.89715594, 'raw_content': None}] \n", + "\n", + "[{'title': '\"Silence Is Dangerous\": Shakira Pens Powerful Essay on Children ...', 'url': 'https://www.hollywoodreporter.com/news/music-news/silence-is-dangerous-shakira-pens-powerful-essay-on-children-separated-at-us-southern-border-4085691/', 'content': 'Shakira acknowledges that she isn\\'t an American citizen, and could be \"perceived as an outsider commenting on domestic policies. However, the United States\\' decisions affect us all, even ...', 'score': 0.9600627, 'raw_content': None}, {'title': \"Discover Shakira's Nationality: Colombian Citizenship And Lebanese ...\", 'url': 'https://astroinsightz.com/what-is-the-nationality-of-shakira/', 'content': 'Shakira often speaks fondly of her Colombian roots, incorporating elements of Colombian culture into her songs and performances. One of the key aspects of Colombian citizenship that has influenced Shakira is the rich musical heritage of the country. Colombia is known for its diverse range of musical styles, including cumbia, vallenato, and salsa.', 'score': 0.95606345, 'raw_content': None}, {'title': 'Shakira - Wikipedia', 'url': 'https://en.wikipedia.org/wiki/Shakira', 'content': 'She was marked as \"one of the most influential artists of the 21st century\" by ET.[167]\\nThroughout her career, Shakira has earned several titles, including \"The Crossover Queen\" by The Economist,[168] \"The Queen of World Cup\" by Billboard,[169] and \"Latin America\\'s Pop Queen\" by Pitchfork.[170] Billboard has also noted that Shakira\\'s music videos have \"redefined the role of dancing in music videos\", while listing her as the best Latin female music video artist of all time.[171] The Middle Eastern newspaper El Correo del Golfo credits Shakira with \"having opened the way\" for several Hispanic singers today.[172]\\nThe authors of Reggaeton, published by Duke University Press, credited Shakira for popularizing the genre (reggaeton) in North America, Europe, and Asia,[173] while the Public Broadcasting Service called her one of the three \"most successful artists of the so-called Golden Age of Latin Music which reshaped America\\'s cultural landscape for the twenty-first century\".[174]\\nAlongside her impact on Latin and mainstream pop culture, Shakira has also impacted popular culture in the Arab World due to her popularity in the region. One of the most influential female artists of the 21st century, Shakira is credited with opening the doors of the international market for other Latin artists.[7][8] With a catalog of 145 songs, Shakira has sold over 95 million records, making her one of the best-selling music artists of all time.[9] Billboard reported that as of 2023, she is the best-selling female Latin artist of all time.[10] Noted to be a \"global phenom\" whose impact has \"reached every corner of the world\", Shakira has been described as an \"artistic link between the west and the east\" for popularizing Middle Eastern sounds in the West, and western sounds in the East (mainly the Middle East).[11][12] \"[140]\\nInfluences\\nAs a child, Shakira was influenced by rock music, listening heavily to rock bands like Led Zeppelin,[141] the Beatles, Nirvana,[142] the Police and U2,[143] while her other influences included Gloria Estefan, Madonna, Sheryl Crow, Alanis Morissette, Marc Anthony, Meredith Brooks, and the Cure.[144][145] She cited Depeche Mode\\'s \"Enjoy the Silence\" as the song that first sparked her passion for pop music.[146]\\nDance\\nShakira is well known for her dancing in her music videos and concerts.[147] Her distinctive dancing style is said to combine Latin dancing with Middle Eastern belly dancing,[147][148] which is derived from her Lebanese heritage,[147] and her hip shaking is mentioned in songs, such as Fifth Harmony\\'s \"Brave Honest Beautiful\".[149] She is noted for usually employing minimal production, usually taking the stage with minimal makeup and natural hair, and without background dancers in her performances, preferring to focus on her vocals, dance moves, and stage presence.[150] Lola Indigo,[247] Young Miko,[248] Nora Fatehi,[249] Kris Kross Ámsterdam,[250] Bad Gyal,[251] Jackson Wang,[252] and Ayra Starr.[253]\\nShakira has even received the admiration of intellectuals and writers such as Nobel Prize winner Gabriel García Márquez who has said \"No one of any age can sing or dance with the innocent sensuality Shakira seems to have invented\".[25] Márquez wrote an essay exalting Shakira\\'s \"phenomenal musical talent\", and \"extraordinary maturity\".[159]\\nThe newspaper El Correo del Golfo wrote that Shakira was the greatest exponent of Middle Eastern music in the West, citing her interest in Arabic music and dance.[172]\\nHer influence has transcended the boundaries of pop culture, that she has become a socio-political influencer, and was named as one of the \"World\\'s Greatest Leaders\" of 2017 by Fortune.[254] His lawsuit was dismissed by a Los Angeles County Superior Court judge in August\\xa02013.[317]\\nShakira entered a relationship with the Spanish football player Gerard Piqué in 2011.[318][319] Piqué, who is exactly ten years her junior, and Shakira met in spring 2010 after he appeared in the music video for Shakira\\'s song \"Waka Waka (This Time for Africa)\", the official song of the 2010 FIFA World Cup.[315] Shakira gave birth to the couple\\'s first son, Milan, on 22\\xa0January 2013 in Barcelona, where the family took residence.[320] Shakira gave birth to their second son, Sasha, on 29\\xa0January 2015.[321] Forbes listed Shakira and Piqué in their list of \"World\\'s Most Powerful Couples\".[322]', 'score': 0.19436783, 'raw_content': None}] \n", + "\n", + "[{'title': 'Bizarrap - Age, Family, Bio | Famous Birthdays', 'url': 'https://www.famousbirthdays.com/people/bizarrap.html', 'content': 'Bizarrap: his birthday, what he did before fame, his family life, fun trivia facts, popularity rankings, and more. ... Birthplace Argentina. Age 26 years old #10,025 Most Popular. Boost. About . Trap music producer who first became known for his remixes of popular hit songs by Argentinian trappers.', 'score': 0.99818975, 'raw_content': None}, {'title': 'Bizarrap - Wikipedia', 'url': 'https://en.wikipedia.org/wiki/Bizarrap', 'content': 'Gonzalo Julián Conde (born 29 August 1998), known professionally as Bizarrap, is an Argentine DJ and producer. He specializes in EDM, Latin trap and Latin hip hop. He is known for his Bzrp Music Sessions, a series of independent tracks which he records with a wide variety of artists. [1] He was nominated for a Latin Grammy Award for Producer ...', 'score': 0.98184055, 'raw_content': None}, {'title': 'Bizarrap Lyrics, Songs, and Albums - Genius', 'url': 'https://genius.com/artists/Bizarrap', 'content': 'Gonzalo Julián Conde, también conocido como Bizarrap o BZRP, es un productor musical y creador de contenido audiovisual argentino. En 2017, comenzó en YouTube como un canal de', 'score': 0.98166555, 'raw_content': None}] \n", + "\n", + "[{'title': 'Bizarrap - Wikipedia', 'url': 'https://en.wikipedia.org/wiki/Bizarrap', 'content': 'Gonzalo Julián Conde (born 29 August 1998), known professionally as Bizarrap, is an Argentine DJ and producer.He specializes in EDM, Latin trap and Latin hip hop.He is known for his Bzrp Music Sessions, a series of independent tracks which he records with a wide variety of artists. [1] He was nominated for a Latin Grammy Award for Producer of the Year in 2021 and 2023.', 'score': 0.93913656, 'raw_content': None}, {'title': \"Bizarrap: Billboard's Latin Artist on the Rise\", 'url': 'https://www.billboard.com/music/latin/bizarrap-interview-latin-artist-on-the-rise-9574988/', 'content': \"Argentine producer Bizarrap's music sessions featuring artists such as Nathy Peluso and Nicki Nicole have not only gone viral on YouTube, raking in millions of views in a matter of days, they ...\", 'score': 0.8071568, 'raw_content': None}, {'title': 'How Bizarrap Became the Hottest Name in Latin Music - Miami New Times', 'url': 'https://www.miaminewtimes.com/music/who-is-bizarrap-how-the-argentinian-producer-conquered-latin-music-18964117', 'content': 'Bizarrap won \"Song of the Year,\" \"Best Pop Song,\" and \"Best Urban Song\" at the 24th annual Latin Grammy Awards in Sevilla, Spain, last year. Photo by Borja B. Hojas/Getty Images for Latin ...', 'score': 0.7190878, 'raw_content': None}] \n", "\n", "\n", "RESPONSE:\n", "The top 3 most streamed songs on Spotify in 2023 were:\n", - "1. *Flowers* by Miley Cyrus\n", - "2. *Ella Baila Sola* by Eslabon Armado and Peso Pluma\n", - "3. *Shakira: Bzrp Music Sessions, Vol. 53* by Shakira and Bizarrap\n", + "1. 'Flowers' by Miley Cyrus\n", + "2. 'Ella Baila Sola' by Eslabon Armado and Peso Pluma\n", + "3. 'Shakira: Bzrp Music Sessions, Vol. 53' by Shakira and Bizarrap\n", + "\n", + "Miley Cyrus is an American actress, singer, and songwriter. She was born on November 23, 1992, making her 31 years old.\n", + "\n", + "Eslabon Armado is an American regional Mexican group from Patterson, California, formed in 2017. The group consists of Pedro Tovar (lead vocals), Brian Tovar (bass), Ulises González (acoustic guitar), and Damián Pacheco (twelve-string guitar). The members of the group are in their early 20s.\n", "\n", - "Miley Cyrus is 30 years old and American. Eslabon Armado is a Mexican group, and Peso Pluma is a Mexican singer. Shakira is 46 years old and Colombian.\n", + "Peso Pluma is a 24-25-year-old rapper, singer, and songwriter from Mexico. He was born on June 15, 1999.\n", + "\n", + "Shakira is a Colombian singer, songwriter, and philanthropist born on February 2, 1977. She is known for her fusion of Latin, rock, and Middle Eastern music styles, her belly dancing skills, and her foundation for education and nutrition.\n", + "\n", + "Bizarrap is an Argentine DJ and producer. He was born on August 29, 1998, making him 25 years old.\n", "\n", "CITATIONS:\n", - "Start: 59 | End: 66 | Text: 'Flowers'\n", + "Start: 58 | End: 67 | Text: ''Flowers''\n", "Sources:\n", - "python_interpreter_ryqfeye95gay:0\n", + "python_interpreter_zvrr4ac8hhps:0\n", "--------------------------------------------------\n", "Start: 71 | End: 82 | Text: 'Miley Cyrus'\n", "Sources:\n", - "python_interpreter_ryqfeye95gay:0\n", + "python_interpreter_zvrr4ac8hhps:0\n", "--------------------------------------------------\n", - "Start: 87 | End: 102 | Text: 'Ella Baila Sola'\n", + "Start: 86 | End: 103 | Text: ''Ella Baila Sola''\n", "Sources:\n", - "python_interpreter_ryqfeye95gay:0\n", + "python_interpreter_zvrr4ac8hhps:0\n", "--------------------------------------------------\n", "Start: 107 | End: 121 | Text: 'Eslabon Armado'\n", "Sources:\n", - "python_interpreter_ryqfeye95gay:0\n", + "python_interpreter_zvrr4ac8hhps:0\n", "--------------------------------------------------\n", "Start: 126 | End: 136 | Text: 'Peso Pluma'\n", "Sources:\n", - "python_interpreter_ryqfeye95gay:0\n", + "python_interpreter_zvrr4ac8hhps:0\n", "--------------------------------------------------\n", - "Start: 141 | End: 178 | Text: 'Shakira: Bzrp Music Sessions, Vol. 53'\n", + "Start: 140 | End: 179 | Text: ''Shakira: Bzrp Music Sessions, Vol. 53''\n", "Sources:\n", - "python_interpreter_ryqfeye95gay:0\n", + "python_interpreter_zvrr4ac8hhps:0\n", "--------------------------------------------------\n", "Start: 183 | End: 190 | Text: 'Shakira'\n", "Sources:\n", - "python_interpreter_ryqfeye95gay:0\n", + "python_interpreter_zvrr4ac8hhps:0\n", "--------------------------------------------------\n", "Start: 195 | End: 203 | Text: 'Bizarrap'\n", "Sources:\n", - "python_interpreter_ryqfeye95gay:0\n", + "python_interpreter_zvrr4ac8hhps:0\n", + "--------------------------------------------------\n", + "Start: 223 | End: 231 | Text: 'American'\n", + "Sources:\n", + "web_search_hrz3bzcs7a8n:2\n", + "--------------------------------------------------\n", + "Start: 232 | End: 239 | Text: 'actress'\n", + "Sources:\n", + "web_search_hrz3bzcs7a8n:2\n", + "--------------------------------------------------\n", + "Start: 241 | End: 247 | Text: 'singer'\n", + "Sources:\n", + "web_search_hrz3bzcs7a8n:2\n", + "--------------------------------------------------\n", + "Start: 253 | End: 264 | Text: 'songwriter.'\n", + "Sources:\n", + "web_search_hrz3bzcs7a8n:2\n", + "--------------------------------------------------\n", + "Start: 281 | End: 298 | Text: 'November 23, 1992'\n", + "Sources:\n", + "web_search_0me46ed9cxp9:1\n", + "web_search_hrz3bzcs7a8n:2\n", + "--------------------------------------------------\n", + "Start: 347 | End: 355 | Text: 'American'\n", + "Sources:\n", + "web_search_ra443ajyz6xj:0\n", + "web_search_ta7g2cd67jrx:0\n", + "web_search_ta7g2cd67jrx:1\n", + "web_search_ta7g2cd67jrx:2\n", + "--------------------------------------------------\n", + "Start: 356 | End: 378 | Text: 'regional Mexican group'\n", + "Sources:\n", + "web_search_ra443ajyz6xj:0\n", + "web_search_ta7g2cd67jrx:0\n", + "web_search_ta7g2cd67jrx:1\n", + "web_search_ta7g2cd67jrx:2\n", + "--------------------------------------------------\n", + "Start: 384 | End: 405 | Text: 'Patterson, California'\n", + "Sources:\n", + "web_search_ra443ajyz6xj:0\n", + "web_search_ta7g2cd67jrx:0\n", + "web_search_ta7g2cd67jrx:2\n", + "--------------------------------------------------\n", + "Start: 417 | End: 422 | Text: '2017.'\n", + "Sources:\n", + "web_search_ra443ajyz6xj:0\n", + "web_search_ta7g2cd67jrx:0\n", + "web_search_ta7g2cd67jrx:1\n", + "--------------------------------------------------\n", + "Start: 445 | End: 470 | Text: 'Pedro Tovar (lead vocals)'\n", + "Sources:\n", + "web_search_ra443ajyz6xj:0\n", + "web_search_ra443ajyz6xj:1\n", + "web_search_ra443ajyz6xj:2\n", + "web_search_ta7g2cd67jrx:0\n", + "--------------------------------------------------\n", + "Start: 472 | End: 490 | Text: 'Brian Tovar (bass)'\n", + "Sources:\n", + "web_search_ra443ajyz6xj:0\n", + "web_search_ra443ajyz6xj:2\n", + "web_search_ta7g2cd67jrx:0\n", + "--------------------------------------------------\n", + "Start: 492 | End: 525 | Text: 'Ulises González (acoustic guitar)'\n", + "Sources:\n", + "web_search_ra443ajyz6xj:0\n", + "web_search_ta7g2cd67jrx:0\n", + "--------------------------------------------------\n", + "Start: 531 | End: 568 | Text: 'Damián Pacheco (twelve-string guitar)'\n", + "Sources:\n", + "web_search_ra443ajyz6xj:0\n", + "web_search_ra443ajyz6xj:2\n", + "web_search_ta7g2cd67jrx:0\n", + "--------------------------------------------------\n", + "Start: 608 | End: 618 | Text: 'early 20s.'\n", + "Sources:\n", + "web_search_ra443ajyz6xj:1\n", + "web_search_ra443ajyz6xj:2\n", + "--------------------------------------------------\n", + "Start: 636 | End: 638 | Text: '24'\n", + "Sources:\n", + "web_search_q7bna7km1re0:0\n", + "web_search_q7bna7km1re0:1\n", + "web_search_q7bna7km1re0:2\n", + "web_search_6bma458t4fxh:0\n", + "--------------------------------------------------\n", + "Start: 638 | End: 641 | Text: '-25'\n", + "Sources:\n", + "web_search_q7bna7km1re0:1\n", + "--------------------------------------------------\n", + "Start: 641 | End: 650 | Text: '-year-old'\n", + "Sources:\n", + "web_search_q7bna7km1re0:0\n", + "web_search_q7bna7km1re0:1\n", + "web_search_q7bna7km1re0:2\n", + "web_search_6bma458t4fxh:0\n", + "--------------------------------------------------\n", + "Start: 651 | End: 657 | Text: 'rapper'\n", + "Sources:\n", + "web_search_q7bna7km1re0:0\n", + "web_search_q7bna7km1re0:1\n", + "web_search_6bma458t4fxh:0\n", + "web_search_6bma458t4fxh:1\n", + "--------------------------------------------------\n", + "Start: 659 | End: 665 | Text: 'singer'\n", + "Sources:\n", + "web_search_q7bna7km1re0:0\n", + "web_search_q7bna7km1re0:1\n", + "web_search_q7bna7km1re0:2\n", + "web_search_6bma458t4fxh:0\n", + "web_search_6bma458t4fxh:1\n", + "--------------------------------------------------\n", + "Start: 671 | End: 681 | Text: 'songwriter'\n", + "Sources:\n", + "web_search_q7bna7km1re0:0\n", + "web_search_6bma458t4fxh:1\n", + "--------------------------------------------------\n", + "Start: 687 | End: 694 | Text: 'Mexico.'\n", + "Sources:\n", + "web_search_q7bna7km1re0:0\n", + "web_search_q7bna7km1re0:1\n", + "web_search_6bma458t4fxh:0\n", + "web_search_6bma458t4fxh:1\n", + "--------------------------------------------------\n", + "Start: 710 | End: 724 | Text: 'June 15, 1999.'\n", + "Sources:\n", + "web_search_q7bna7km1re0:0\n", + "web_search_q7bna7km1re0:1\n", + "web_search_6bma458t4fxh:0\n", + "web_search_6bma458t4fxh:1\n", + "--------------------------------------------------\n", + "Start: 739 | End: 748 | Text: 'Colombian'\n", + "Sources:\n", + "web_search_7hw36333m853:0\n", + "web_search_7hw36333m853:1\n", + "web_search_7hw36333m853:2\n", + "web_search_2xr2d7ntz6zj:1\n", + "web_search_2xr2d7ntz6zj:2\n", + "--------------------------------------------------\n", + "Start: 749 | End: 755 | Text: 'singer'\n", + "Sources:\n", + "web_search_7hw36333m853:0\n", + "web_search_7hw36333m853:1\n", + "web_search_7hw36333m853:2\n", + "web_search_2xr2d7ntz6zj:2\n", + "--------------------------------------------------\n", + "Start: 757 | End: 767 | Text: 'songwriter'\n", + "Sources:\n", + "web_search_7hw36333m853:0\n", + "web_search_7hw36333m853:1\n", + "web_search_7hw36333m853:2\n", + "--------------------------------------------------\n", + "Start: 773 | End: 787 | Text: 'philanthropist'\n", + "Sources:\n", + "web_search_7hw36333m853:0\n", + "--------------------------------------------------\n", + "Start: 796 | End: 813 | Text: 'February 2, 1977.'\n", + "Sources:\n", + "web_search_7hw36333m853:0\n", + "web_search_7hw36333m853:1\n", + "web_search_7hw36333m853:2\n", + "--------------------------------------------------\n", + "Start: 835 | End: 889 | Text: 'fusion of Latin, rock, and Middle Eastern music styles'\n", + "Sources:\n", + "web_search_7hw36333m853:0\n", + "web_search_7hw36333m853:1\n", + "web_search_7hw36333m853:2\n", + "web_search_2xr2d7ntz6zj:2\n", + "--------------------------------------------------\n", + "Start: 895 | End: 915 | Text: 'belly dancing skills'\n", + "Sources:\n", + "web_search_7hw36333m853:0\n", + "web_search_7hw36333m853:1\n", + "web_search_7hw36333m853:2\n", + "web_search_2xr2d7ntz6zj:2\n", + "--------------------------------------------------\n", + "Start: 925 | End: 964 | Text: 'foundation for education and nutrition.'\n", + "Sources:\n", + "web_search_7hw36333m853:0\n", + "--------------------------------------------------\n", + "Start: 981 | End: 990 | Text: 'Argentine'\n", + "Sources:\n", + "web_search_py92r6q4y3jq:0\n", + "web_search_py92r6q4y3jq:1\n", + "web_search_py92r6q4y3jq:2\n", + "web_search_wrc3j3warw8z:0\n", + "web_search_wrc3j3warw8z:1\n", + "web_search_wrc3j3warw8z:2\n", + "--------------------------------------------------\n", + "Start: 991 | End: 993 | Text: 'DJ'\n", + "Sources:\n", + "web_search_py92r6q4y3jq:1\n", + "web_search_wrc3j3warw8z:0\n", + "--------------------------------------------------\n", + "Start: 998 | End: 1007 | Text: 'producer.'\n", + "Sources:\n", + "web_search_py92r6q4y3jq:1\n", + "web_search_wrc3j3warw8z:0\n", + "web_search_wrc3j3warw8z:1\n", + "web_search_wrc3j3warw8z:2\n", + "--------------------------------------------------\n", + "Start: 1023 | End: 1038 | Text: 'August 29, 1998'\n", + "Sources:\n", + "web_search_py92r6q4y3jq:1\n", + "web_search_wrc3j3warw8z:0\n", "--------------------------------------------------\n" ] } @@ -526,7 +781,7 @@ "res = co.chat(model=model,\n", " messages=messages,\n", " tools=tools,\n", - " temperature=0)\n", + " temperature=0.1)\n", "\n", "# Keep invoking tools as long as the model generates tool calls\n", "while res.message.tool_calls:\n", @@ -551,18 +806,19 @@ " print(\"\\nTOOL RESULTS:\")\n", " for tc in res.message.tool_calls:\n", " tool_result = functions_map[tc.function.name](**json.loads(tc.function.arguments))\n", - " tool_content = [json.dumps(tool_result)]\n", " print(tool_result, \"\\n\")\n", - " \n", - " messages.append({'role': 'tool',\n", - " 'tool_call_id': tc.id,\n", - " 'tool_content': tool_content}) \n", + " tool_content = []\n", + " for data in tool_result:\n", + " tool_content.append({\"type\": \"document\", \"document\": {\"data\": json.dumps(data)}}) # You can add your own \"id\" field in the \"document\" object, otherwise IDs will be auto-generated\n", + " messages.append(\n", + " {\"role\": \"tool\", \"tool_call_id\": tc.id, \"content\": tool_content}\n", + " )\n", "\n", " # 4 - Model either generates more tool calls or returns a response\n", " res = co.chat(model=model,\n", " messages=messages,\n", " tools=tools,\n", - " temperature=0)\n", + " temperature=0.1)\n", " \n", "messages.append({\"role\": \"assistant\", \"content\": res.message.content[0].text})\n", "\n", diff --git a/notebooks/agents/Vanilla_Tool_Use_v2.ipynb b/notebooks/agents/Vanilla_Tool_Use_v2.ipynb index 8af952b..f788632 100644 --- a/notebooks/agents/Vanilla_Tool_Use_v2.ipynb +++ b/notebooks/agents/Vanilla_Tool_Use_v2.ipynb @@ -32,29 +32,23 @@ }, { "cell_type": "code", - "execution_count": 1, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "us5dkKrLCbXW", - "outputId": "94c97f62-77fb-4492-a4e4-d9eeee4e438c" - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ - "# ! pip install cohere --quiet" + "! pip install cohere==5.11.3" ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "import cohere\n", - "import os\n", "import json\n", - "co = cohere.ClientV2(api_key=\"YOUR_COHERE_API_KEY\") # Get your free API key: https://dashboard.cohere.com/api-keys" + "\n", + "co = cohere.ClientV2(\"COHERE_API_KEY\") # Get your free API key: https://dashboard.cohere.com/api-keys" ] }, { @@ -69,7 +63,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": { "id": "yZffY8xItLGp" }, @@ -119,40 +113,39 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": { "id": "YuIH4us8tLGp" }, "outputs": [], "source": [ + "# Function definitions\n", "def query_daily_sales_report(day: str) -> dict:\n", " \"\"\"\n", " Function to retrieve the sales report for the given day\n", " \"\"\"\n", " report = sales_database.get(day, {})\n", " if report:\n", - " return {\n", - " 'date': day,\n", - " 'summary': f\"Total Sales Amount: {report['total_sales_amount']}, Total Units Sold: {report['total_units_sold']}\"\n", - " }\n", + " return [{\n", + " \"date\": day,\n", + " \"summary\": f\"Total Sales Amount: {report['total_sales_amount']}, Total Units Sold: {report['total_units_sold']}\",\n", + " }]\n", " else:\n", - " return {'date': day, 'summary': 'No sales data available for this day.'}\n", - "\n", + " return [{\"date\": day, \"summary\": \"No sales data available for this day.\"}] \n", + " # You can return a list of objects e.g. [{\"url\": \"abc.com\", \"text\": \"...\"}, {\"url\": \"xyz.com\", \"text\": \"...\"}]\n", "\n", "def query_product_catalog(category: str) -> dict:\n", " \"\"\"\n", " Function to retrieve products for the given category\n", " \"\"\"\n", " products = product_catalog.get(category, [])\n", - " return {\n", - " 'category': category,\n", - " 'products': products\n", - " }\n", + " return [{\"category\": category, \"products\": products}]\n", + " # You can return a list of objects e.g. [{\"url\": \"abc.com\", \"text\": \"...\"}, {\"url\": \"xyz.com\", \"text\": \"...\"}]\n", "\n", "\n", "functions_map = {\n", " \"query_daily_sales_report\": query_daily_sales_report,\n", - " \"query_product_catalog\": query_product_catalog\n", + " \"query_product_catalog\": query_product_catalog,\n", "}" ] }, @@ -178,7 +171,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": { "id": "aIk-of_OtLGp" }, @@ -239,14 +232,14 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": { "id": "JuDgJ7fjtLGq" }, "outputs": [], "source": [ - "# preamble containing instructions about the task and the desired style for the output.\n", - "preamble = \"\"\"\n", + "# System message containing instructions about the task and the desired style for the output.\n", + "system_message = \"\"\"\n", "## Task and Context\n", "You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging.\n", "\n", @@ -254,7 +247,7 @@ "Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.\n", "\"\"\"\n", "\n", - "# user request\n", + "# User request\n", "message = \"Can you provide a sales summary for 29th September 2023, and also give me some details about the products in the 'Electronics' category, for example their prices and stock levels?\"" ] }, @@ -270,7 +263,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 11, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -286,7 +279,7 @@ "The model recommends doing the following tool calls:\n", "\n", "Tool plan:\n", - "I will search for the sales summary for 29th September 2023 and the details of products in the 'Electronics' category. \n", + "I will first search for the sales summary for 29th September 2023. Then, I will search for the products in the 'Electronics' category. \n", "\n", "Tool calls:\n", "Tool name: query_daily_sales_report | Parameters: {\"day\":\"2023-09-29\"}\n", @@ -295,24 +288,29 @@ } ], "source": [ - "messages=[{\"role\": \"system\", \"content\": preamble},\n", + "messages=[{\"role\": \"system\", \"content\": system_message},\n", " {\"role\": \"user\", \"content\": message}]\n", "\n", - "response = co.chat(\n", - " model=\"command-r-plus\",\n", - " messages=messages,\n", - " tools=tools\n", - ")\n", + "\n", + "response = co.chat(model=\"command-r-plus-08-2024\",\n", + " messages=messages,\n", + " tools=tools)\n", "\n", "print(\"The model recommends doing the following tool calls:\\n\")\n", "print(\"Tool plan:\")\n", - "print(response.message.tool_plan,\"\\n\")\n", + "print(response.message.tool_plan, \"\\n\")\n", "print(\"Tool calls:\")\n", "for tc in response.message.tool_calls:\n", " print(f\"Tool name: {tc.function.name} | Parameters: {tc.function.arguments}\")\n", - " \n", + "\n", "# append the chat history\n", - "messages.append({'role': 'assistant', 'tool_calls': response.message.tool_calls, 'tool_plan': response.message.tool_plan})" + "messages.append(\n", + " {\n", + " \"role\": \"assistant\",\n", + " \"tool_calls\": response.message.tool_calls,\n", + " \"tool_plan\": response.message.tool_plan,\n", + " }\n", + ")" ] }, { @@ -329,7 +327,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 14, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -343,50 +341,30 @@ "output_type": "stream", "text": [ "Tool results that will be fed back to the model in step 4:\n", - "{\n", - " \"date\": \"2023-09-29\",\n", - " \"summary\": \"Total Sales Amount: 10000, Total Units Sold: 250\"\n", - "}\n", - "{\n", - " \"category\": \"Electronics\",\n", - " \"products\": [\n", - " {\n", - " \"product_id\": \"E1001\",\n", - " \"name\": \"Smartphone\",\n", - " \"price\": 500,\n", - " \"stock_level\": 20\n", - " },\n", - " {\n", - " \"product_id\": \"E1002\",\n", - " \"name\": \"Laptop\",\n", - " \"price\": 1000,\n", - " \"stock_level\": 15\n", - " },\n", - " {\n", - " \"product_id\": \"E1003\",\n", - " \"name\": \"Tablet\",\n", - " \"price\": 300,\n", - " \"stock_level\": 25\n", - " }\n", - " ]\n", - "}\n" + "{'type': 'document', 'document': {'data': '{\"date\": \"2023-09-29\", \"summary\": \"Total Sales Amount: 10000, Total Units Sold: 250\"}'}}\n", + "Tool results that will be fed back to the model in step 4:\n", + "{'type': 'document', 'document': {'data': '{\"category\": \"Electronics\", \"products\": [{\"product_id\": \"E1001\", \"name\": \"Smartphone\", \"price\": 500, \"stock_level\": 20}, {\"product_id\": \"E1002\", \"name\": \"Laptop\", \"price\": 1000, \"stock_level\": 15}, {\"product_id\": \"E1003\", \"name\": \"Tablet\", \"price\": 300, \"stock_level\": 25}]}'}}\n" ] } ], "source": [ - "tool_content = []\n", "# Iterate over the tool calls generated by the model\n", "for tc in response.message.tool_calls:\n", " # here is where you would call the tool recommended by the model, using the parameters recommended by the model\n", - " tool_result= functions_map[tc.function.name](**json.loads(tc.function.arguments))\n", + " tool_result = functions_map[tc.function.name](**json.loads(tc.function.arguments))\n", " # store the output in a list\n", - " tool_content.append(json.dumps(tool_result))\n", + " tool_content = []\n", + " for data in tool_result:\n", + " tool_content.append({\"type\": \"document\", \"document\": {\"data\": json.dumps(data)}})\n", + " # Optional: add an \"id\" field in the \"document\" object, otherwise IDs are auto-generated\n", " # append the chat history\n", - " messages.append({'role': 'tool', 'tool_call_id': tc.id, 'tool_content': tool_content}) \n", - "\n", - "print(\"Tool results that will be fed back to the model in step 4:\")\n", - "for result in tool_content:\n", - " print(json.dumps(json.loads(result), indent=2))\n" + " messages.append(\n", + " {\"role\": \"tool\", \"tool_call_id\": tc.id, \"content\": tool_content}\n", + " )\n", + " \n", + " print(\"Tool results that will be fed back to the model in step 4:\")\n", + " for result in tool_content:\n", + " print(result)" ] }, { @@ -408,45 +386,32 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 15, "metadata": { "id": "MKnjXVfXtLGr" }, - "outputs": [], - "source": [ - "response = co.chat(\n", - " model=\"command-r-plus\",\n", - " messages=messages,\n", - " tools=tools\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "jlxKTsaztLGr", - "outputId": "b2cd8667-bca9-4928-c423-61930b4b49fa" - }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Final answer:\n", - "On 29 September 2023, the total sales amount was $10,000, and 250 units were sold. \n", + "On 29th September 2023, the total sales amount was 10,000, and the total units sold were 250.\n", "\n", - "Here are the details for the products in the 'Electronics' category:\n", - "- Smartphone: $500, 20 in stock\n", - "- Laptop: $1,000, 15 in stock\n", - "- Tablet: $300, 25 in stock\n" + "The following products are available in the Electronics category:\n", + "- Smartphone (E1001) - £500, 20 in stock\n", + "- Laptop (E1002) - £1,000, 15 in stock\n", + "- Tablet (E1003) - £300, 25 in stock\n" ] } ], "source": [ + "response = co.chat(\n", + " model=\"command-r-plus-08-2024\",\n", + " messages=messages,\n", + " tools=tools\n", + ")\n", + "\n", "print(\"Final answer:\")\n", "print(response.message.content[0].text)" ] @@ -468,7 +433,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 16, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -482,47 +447,39 @@ "output_type": "stream", "text": [ "Citations that support the final answer:\n", - "start=26 end=56 text='total sales amount was $10,000' sources=[Source_Tool(id='query_daily_sales_report_6c5v4phf8d4f:0', tool_output={'date': '2023-09-29', 'summary': 'Total Sales Amount: 10000, Total Units Sold: 250'}, type='tool'), Source_Tool(id='query_product_catalog_7395zjrh8m8w:0', tool_output={'date': '2023-09-29', 'summary': 'Total Sales Amount: 10000, Total Units Sold: 250'}, type='tool')]\n", - "Start: 26 | End: 56 | Text: 'total sales amount was $10,000'\n", - "start=62 end=81 text='250 units were sold' sources=[Source_Tool(id='query_daily_sales_report_6c5v4phf8d4f:0', tool_output={'date': '2023-09-29', 'summary': 'Total Sales Amount: 10000, Total Units Sold: 250'}, type='tool'), Source_Tool(id='query_product_catalog_7395zjrh8m8w:0', tool_output={'date': '2023-09-29', 'summary': 'Total Sales Amount: 10000, Total Units Sold: 250'}, type='tool')]\n", - "Start: 62 | End: 81 | Text: '250 units were sold'\n", - "start=156 end=185 text='Smartphone: $500, 20 in stock' sources=[Source_Tool(id='query_daily_sales_report_6c5v4phf8d4f:1', tool_output={'category': 'Electronics', 'products': '[{\"name\":\"Smartphone\",\"price\":500,\"product_id\":\"E1001\",\"stock_level\":20},{\"name\":\"Laptop\",\"price\":1000,\"product_id\":\"E1002\",\"stock_level\":15},{\"name\":\"Tablet\",\"price\":300,\"product_id\":\"E1003\",\"stock_level\":25}]'}, type='tool'), Source_Tool(id='query_product_catalog_7395zjrh8m8w:1', tool_output={'category': 'Electronics', 'products': '[{\"name\":\"Smartphone\",\"price\":500,\"product_id\":\"E1001\",\"stock_level\":20},{\"name\":\"Laptop\",\"price\":1000,\"product_id\":\"E1002\",\"stock_level\":15},{\"name\":\"Tablet\",\"price\":300,\"product_id\":\"E1003\",\"stock_level\":25}]'}, type='tool')]\n", - "Start: 156 | End: 185 | Text: 'Smartphone: $500, 20 in stock'\n", - "start=188 end=215 text='Laptop: $1,000, 15 in stock' sources=[Source_Tool(id='query_daily_sales_report_6c5v4phf8d4f:1', tool_output={'category': 'Electronics', 'products': '[{\"name\":\"Smartphone\",\"price\":500,\"product_id\":\"E1001\",\"stock_level\":20},{\"name\":\"Laptop\",\"price\":1000,\"product_id\":\"E1002\",\"stock_level\":15},{\"name\":\"Tablet\",\"price\":300,\"product_id\":\"E1003\",\"stock_level\":25}]'}, type='tool'), Source_Tool(id='query_product_catalog_7395zjrh8m8w:1', tool_output={'category': 'Electronics', 'products': '[{\"name\":\"Smartphone\",\"price\":500,\"product_id\":\"E1001\",\"stock_level\":20},{\"name\":\"Laptop\",\"price\":1000,\"product_id\":\"E1002\",\"stock_level\":15},{\"name\":\"Tablet\",\"price\":300,\"product_id\":\"E1003\",\"stock_level\":25}]'}, type='tool')]\n", - "Start: 188 | End: 215 | Text: 'Laptop: $1,000, 15 in stock'\n", - "start=218 end=243 text='Tablet: $300, 25 in stock' sources=[Source_Tool(id='query_daily_sales_report_6c5v4phf8d4f:1', tool_output={'category': 'Electronics', 'products': '[{\"name\":\"Smartphone\",\"price\":500,\"product_id\":\"E1001\",\"stock_level\":20},{\"name\":\"Laptop\",\"price\":1000,\"product_id\":\"E1002\",\"stock_level\":15},{\"name\":\"Tablet\",\"price\":300,\"product_id\":\"E1003\",\"stock_level\":25}]'}, type='tool'), Source_Tool(id='query_product_catalog_7395zjrh8m8w:1', tool_output={'category': 'Electronics', 'products': '[{\"name\":\"Smartphone\",\"price\":500,\"product_id\":\"E1001\",\"stock_level\":20},{\"name\":\"Laptop\",\"price\":1000,\"product_id\":\"E1002\",\"stock_level\":15},{\"name\":\"Tablet\",\"price\":300,\"product_id\":\"E1003\",\"stock_level\":25}]'}, type='tool')]\n", - "Start: 218 | End: 243 | Text: 'Tablet: $300, 25 in stock'\n" + "Start: 28 | End: 57 | Text: 'total sales amount was 10,000'\n", + "Start: 67 | End: 93 | Text: 'total units sold were 250.'\n", + "Start: 163 | End: 201 | Text: 'Smartphone (E1001) - £500, 20 in stock'\n", + "Start: 204 | End: 240 | Text: 'Laptop (E1002) - £1,000, 15 in stock'\n", + "Start: 243 | End: 277 | Text: 'Tablet (E1003) - £300, 25 in stock'\n" ] } ], "source": [ "print(\"Citations that support the final answer:\")\n", "for citation in response.message.citations:\n", - " print(citation)\n", " print(f\"Start: {citation.start} | End: {citation.end} | Text: '{citation.text}'\")" ] }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "On 29 September 2023, the total sales amount was $10,000[3,4], and 250 units were sold[3,4]. \n", + "On 29th September 2023, the total sales amount was 10,000[2], and the total units sold were 250.[2]\n", "\n", - "Here are the details for the products in the 'Electronics' category:\n", - "- Smartphone: $500, 20 in stock[1,2]\n", - "- Laptop: $1,000, 15 in stock[1,2]\n", - "- Tablet: $300, 25 in stock[1,2]\n", + "The following products are available in the Electronics category:\n", + "- Smartphone (E1001) - £500, 20 in stock[1]\n", + "- Laptop (E1002) - £1,000, 15 in stock[1]\n", + "- Tablet (E1003) - £300, 25 in stock[1]\n", "\n", "Source tools:\n", - "[1]: query_daily_sales_report_6c5v4phf8d4f:1 | {'category': 'Electronics', 'products': '[{\"name\":\"Smartphone\",\"price\":500,\"product_id\":\"E1001\",\"stock_level\":20},{\"name\":\"Laptop\",\"price\":1000,\"product_id\":\"E1002\",\"stock_level\":15},{\"name\":\"Tablet\",\"price\":300,\"product_id\":\"E1003\",\"stock_level\":25}]'}\n", - "[2]: query_product_catalog_7395zjrh8m8w:1 | {'category': 'Electronics', 'products': '[{\"name\":\"Smartphone\",\"price\":500,\"product_id\":\"E1001\",\"stock_level\":20},{\"name\":\"Laptop\",\"price\":1000,\"product_id\":\"E1002\",\"stock_level\":15},{\"name\":\"Tablet\",\"price\":300,\"product_id\":\"E1003\",\"stock_level\":25}]'}\n", - "[3]: query_daily_sales_report_6c5v4phf8d4f:0 | {'date': '2023-09-29', 'summary': 'Total Sales Amount: 10000, Total Units Sold: 250'}\n", - "[4]: query_product_catalog_7395zjrh8m8w:0 | {'date': '2023-09-29', 'summary': 'Total Sales Amount: 10000, Total Units Sold: 250'}\n" + "[1]: query_product_catalog_zeq4jk768e19:0 | {'content': '{\"category\": \"Electronics\", \"products\": [{\"product_id\": \"E1001\", \"name\": \"Smartphone\", \"price\": 500, \"stock_level\": 20}, {\"product_id\": \"E1002\", \"name\": \"Laptop\", \"price\": 1000, \"stock_level\": 15}, {\"product_id\": \"E1003\", \"name\": \"Tablet\", \"price\": 300, \"stock_level\": 25}]}'}\n", + "[2]: query_daily_sales_report_7me1rzpgww1x:0 | {'date': '2023-09-29', 'summary': 'Total Sales Amount: 10000, Total Units Sold: 250'}\n" ] } ], diff --git a/notebooks/guides/getting-started/v2/tutorial_pt7_v2.ipynb b/notebooks/guides/getting-started/v2/tutorial_pt7_v2.ipynb index f705a80..18bbf50 100644 --- a/notebooks/guides/getting-started/v2/tutorial_pt7_v2.ipynb +++ b/notebooks/guides/getting-started/v2/tutorial_pt7_v2.ipynb @@ -45,6 +45,15 @@ "To get started, first we need to install the `cohere` library and create a Cohere client." ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "! pip install cohere==5.11.3" + ] + }, { "cell_type": "code", "execution_count": 1, @@ -52,7 +61,7 @@ "outputs": [], "source": [ "\n", - "# pip install cohere\n", + "\n", "\n", "import cohere\n", "import json\n", @@ -312,7 +321,7 @@ "for tc in response.message.tool_calls:\n", " tool_result = functions_map[tc.function.name](**json.loads(tc.function.arguments))\n", " tool_content = []\n", - " for idx, data in enumerate(tool_result):\n", + " for data in tool_result:\n", " tool_content.append({\"type\": \"document\", \"document\": {\"data\": json.dumps(data)}})\n", " # Optional: add an \"id\" field in the \"document\" object, otherwise IDs are auto-generated\n", " # Append tool results to the chat history\n", @@ -446,7 +455,7 @@ " **json.loads(tc.function.arguments)\n", " )\n", " tool_content = []\n", - " for idx, data in enumerate(tool_result):\n", + " for data in tool_result:\n", " tool_content.append({\"type\": \"document\", \"document\": {\"data\": json.dumps(data)}})\n", " # Optional: add an \"id\" field in the \"document\" object, otherwise IDs are auto-generated\n", " messages.append(\n", @@ -550,7 +559,7 @@ "kernelspec": { "display_name": "base", "language": "python", - "name": "python3" + "name": "base" }, "language_info": { "codemirror_mode": {