From 4f53819cb20391cf3f2b3a6f75a715a092d65bb2 Mon Sep 17 00:00:00 2001 From: dloman118 <99347459+dloman118@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:03:45 -0400 Subject: [PATCH] fix error --- .../Mixture-of-Agents-Crew-AI-Groq.ipynb | 140 +++++++++--------- 1 file changed, 66 insertions(+), 74 deletions(-) diff --git a/crewai-mixture-of-agents/Mixture-of-Agents-Crew-AI-Groq.ipynb b/crewai-mixture-of-agents/Mixture-of-Agents-Crew-AI-Groq.ipynb index aff0059..eafd172 100644 --- a/crewai-mixture-of-agents/Mixture-of-Agents-Crew-AI-Groq.ipynb +++ b/crewai-mixture-of-agents/Mixture-of-Agents-Crew-AI-Groq.ipynb @@ -43,6 +43,16 @@ "from langchain_groq import ChatGroq" ] }, + { + "cell_type": "code", + "execution_count": 2, + "id": "40534034-a556-424b-8f5b-81392939369e", + "metadata": {}, + "outputs": [], + "source": [ + "os.environ['GROQ_API_KEY'] = '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'" + ] + }, { "cell_type": "markdown", "id": "cee9fc13-e27d-4e93-95df-57c87f5a8df4", @@ -108,10 +118,8 @@ " game_id = str(game_info_df.game_id.tolist()[0])\n", " home_team = game_info_df.home_name.tolist()[0]\n", " home_score = game_info_df.home_score.tolist()[0]\n", - " home_starter = game_info_df.home_probable_pitcher.tolist()[0]\n", " away_team = game_info_df.away_name.tolist()[0]\n", " away_score = game_info_df.away_score.tolist()[0]\n", - " away_starter = game_info_df.away_probable_pitcher.tolist()[0]\n", " winning_team = game_info_df.winning_team.tolist()[0]\n", " series_status = game_info_df.series_status.tolist()[0]\n", "\n", @@ -119,14 +127,12 @@ " Game ID: {game_id}\n", " Home Team: {home_team}\n", " Home Score: {home_score}\n", - " Home Starting Pitcher: {home_starter}\n", " Away Team: {away_team}\n", " Away Score: {away_score}\n", - " Away Starting Pitcher: {away_starter}\n", " Winning Team: {winning_team}\n", " Series Status: {series_status}\n", - " '''.format(game_id = game_id, home_team = home_team, home_score = home_score, home_starter = home_starter, \n", - " away_team = away_team, away_score = away_score, away_starter = away_starter, \\\n", + " '''.format(game_id = game_id, home_team = home_team, home_score = home_score, \n", + " away_team = away_team, away_score = away_score, \\\n", " series_status = series_status, winning_team = winning_team)\n", "\n", " return game_info\n", @@ -313,7 +319,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 6, "id": "8d81eabd-a25b-4126-b6f5-286a8e0a32f2", "metadata": {}, "outputs": [], @@ -439,18 +445,10 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 7, "id": "af295e70-10b4-40b4-979f-6a1d912672a6", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-07-16 09:22:23,799 - 4308862336 - __init__.py-__init__:521 - WARNING: Overriding of current TracerProvider is not allowed\n" - ] - } - ], + "outputs": [], "source": [ "crew = Crew(\n", " agents=[mlb_researcher, mlb_statistician, mlb_writer_llama, mlb_writer_gemma, mlb_writer_mixtral, mlb_editor],\n", @@ -466,7 +464,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 8, "id": "d56d9ff7-e337-40c4-b2c1-e2f69940ce41", "metadata": { "scrolled": true @@ -479,7 +477,7 @@ "\n", "\n", "\u001b[1m> Entering new CrewAgentExecutor chain...\u001b[0m\n", - "\u001b[32;1m\u001b[1;3mThought: I need to identify the correct game related to the user prompt and return game info using the get_game_info tool.\n", + "\u001b[32;1m\u001b[1;3mThought: I need to identify the correct game related to the user prompt and return game info using the get_game_info tool. The user prompt specifies a date, July 14, 2024, so I will use that as the game date.\n", "\n", "Action: get_game_info\n", "Action Input: {\"game_date\": \"2024-07-14\", \"team_name\": \"Yankees\"}\u001b[0m\u001b[95m \n", @@ -488,24 +486,19 @@ " Game ID: 747009\n", " Home Team: Baltimore Orioles\n", " Home Score: 6\n", - " Home Starting Pitcher: Dean Kremer\n", " Away Team: New York Yankees\n", " Away Score: 5\n", - " Away Starting Pitcher: Carlos Rodón\n", " Winning Team: Baltimore Orioles\n", " Series Status: NYY wins 2-1\n", " \n", "\u001b[00m\n", "\u001b[32;1m\u001b[1;3mThought: I now know the final answer\n", - "\n", "Final Answer: \n", " Game ID: 747009\n", " Home Team: Baltimore Orioles\n", " Home Score: 6\n", - " Home Starting Pitcher: Dean Kremer\n", " Away Team: New York Yankees\n", " Away Score: 5\n", - " Away Starting Pitcher: Carlos Rodón\n", " Winning Team: Baltimore Orioles\n", " Series Status: NYY wins 2-1\u001b[0m\n", "\n", @@ -513,7 +506,7 @@ "\n", "\n", "\u001b[1m> Entering new CrewAgentExecutor chain...\u001b[0m\n", - "\u001b[32;1m\u001b[1;3mI need to retrieve the player boxscore batting stats for the game with ID 747009.\n", + "\u001b[32;1m\u001b[1;3mI understand the task at hand. I need to retrieve the boxscore batting stats for the game with ID 747009.\n", "\n", "Action: get_batting_stats\n", "Action Input: {\"game_id\": \"747009\"}\u001b[0m\u001b[95m \n", @@ -542,18 +535,9 @@ "20 Orioles James McCann C 2 1 0 0 0 1 0\n", "21 Orioles Ryan O'Hearn PH 0 1 0 0 0 1 0\n", "\u001b[00m\n", - "\u001b[32;1m\u001b[1;3mThought: I need to retrieve the player boxscore batting stats for the game with ID 747009.\n", - "\n", - "Action: get_batting_stats\n", - "Action Input: {\"game_id\": \"747009\"}\u001b[0m\u001b[95m \n", - "\n", - "I tried reusing the same input, I must stop using this action input. I'll try something else instead.\n", - "\n", - "\n", - "\u001b[00m\n", - "\u001b[32;1m\u001b[1;3mThought: I have already retrieved the player boxscore batting stats for the game with ID 747009.\n", + "\u001b[32;1m\u001b[1;3mThought: I have successfully retrieved the boxscore batting stats for the game with ID 747009.\n", "\n", - "Final Answer: \n", + "Final Answer:\n", "team_name fullName position ab r h hr rbi bb sb\n", "0 Yankees Ben Rice 1B 5 1 1 1 3 0 0\n", "1 Yankees DJ LeMahieu 1B 0 0 0 0 0 0 0\n", @@ -582,7 +566,7 @@ "\n", "\n", "\u001b[1m> Entering new CrewAgentExecutor chain...\u001b[0m\n", - "\u001b[32;1m\u001b[1;3mI need to retrieve the boxscore pitching stats for the game with ID 747009.\n", + "\u001b[32;1m\u001b[1;3mThought: I need to retrieve the pitching boxscore stats for game ID 747009.\n", "\n", "Action: get_pitching_stats\n", "Action Input: {\"game_id\": \"747009\"}\u001b[0m\u001b[95m \n", @@ -600,10 +584,9 @@ "9 Orioles Yennier Cano 1.1 1 0 0 1 0 (H, 24)\n", "10 Orioles Craig Kimbrel 1.0 1 3 3 2 1 (W, 6-2)(BS, 5)\n", "\u001b[00m\n", - "\u001b[32;1m\u001b[1;3mThought:\n", - "I now know the final answer\n", - "\n", + "\u001b[32;1m\u001b[1;3mThought: I now know the final answer\n", "Final Answer:\n", + "\n", " team_name fullName ip h r er bb k note\n", "0 Yankees Carlos Rodón 4.0 4 2 2 3 7 \n", "1 Yankees Tommy Kahnle 1.0 1 1 1 0 1 \n", @@ -621,40 +604,46 @@ "\n", "\n", "\u001b[1m> Entering new CrewAgentExecutor chain...\u001b[0m\n", - "\u001b[32;1m\u001b[1;3mI'm excited to take on this task! I have all the necessary information and stats to write a detailed game recap article. I'll make sure to follow the provided format and not make up any information that isn't explicitly stated. I'm confident that my final answer will be a great and complete game recap article.\n", + "\u001b[32;1m\u001b[1;3m\u001b[0m\u001b[32;1m\u001b[1;3mThought: I now can give a great answer\n", "\n", "Final Answer:\n", "\n", - "Baltimore Orioles Edge New York Yankees 6-5 in Thrilling Contest\n", + "**Game Recap: Orioles Outlast Yankees in Thrilling Finale**\n", + "\n", + "The Baltimore Orioles secured a crucial 6-5 victory over the New York Yankees in the final game of a three-game series, taking the series 2-1. The Orioles' winning pitcher, Craig Kimbrel, earned his sixth win of the season, while the Yankees' Clay Holmes suffered his fourth loss.\n", + "\n", + "The Orioles got off to a strong start, scoring two runs in the first inning thanks to a solo home run by Gunnar Henderson and an RBI single by Anthony Santander. The Yankees responded in the top of the third, with Ben Rice hitting a two-run homer to tie the game.\n", "\n", - "The Baltimore Orioles came out on top in a back-and-forth contest against the New York Yankees, taking the series opener 6-5. Dean Kremer got the start for the Orioles and pitched 4.2 innings, allowing 4 hits and 2 earned runs while striking out 4.\n", + "The Orioles regained the lead in the bottom of the fifth, thanks to a solo home run by Anthony Santander and an RBI single by Cedric Mullins. The Yankees threatened in the top of the eighth, but the Orioles' bullpen held strong, with Cionel Pérez and Yennier Cano combining for a scoreless inning.\n", "\n", - "The Yankees got on the board first in the top of the 2nd inning, with Ben Rice hitting a solo homer to give his team a 1-0 lead. The Orioles responded in the bottom of the 3rd, with Gunnar Henderson driving in two runs with a single to give his team a 2-1 lead.\n", + "In the top of the ninth, the Yankees staged a dramatic comeback, scoring three runs on a bases-loaded single by Trent Grisham and a sacrifice fly by Aaron Judge. However, the Orioles' bullpen held strong, with Craig Kimbrel earning the save and securing the win.\n", "\n", - "The Yankees tied the game in the top of the 5th, with Trent Grisham hitting a two-run homer to make it 2-2. The Orioles regained the lead in the bottom of the 5th, with Anthony Santander hitting a solo homer to make it 3-2.\n", + "Top Performers:\n", "\n", - "The Yankees tied the game again in the top of the 8th, with Oswaldo Cabrera driving in a run with a single to make it 3-3. The Orioles scored three runs in the bottom of the 8th, thanks to an RBI single from Cedric Mullins and a two-run homer from Ryan O'Hearn, to take a 6-3 lead.\n", + "* Gunnar Henderson (Orioles): 2-for-5, 1 HR, 2 RBI\n", + "* Anthony Santander (Orioles): 2-for-4, 1 HR, 2 RBI\n", + "* Trent Grisham (Yankees): 3-for-3, 1 HR, 2 RBI\n", "\n", - "The Yankees threatened in the top of the 9th, with Clay Holmes loading the bases with two outs. Craig Kimbrel came in to close the game and gave up a three-run homer to Aaron Judge, making it 6-5. However, Kimbrel was able to get the final out and earn the save, securing the win for the Orioles.\n", + "Winning Pitcher: Craig Kimbrel (Orioles)\n", "\n", - "Dean Kremer was credited with the win, improving his record to 6-2. Clay Holmes took the loss, falling to 1-4.\u001b[0m\n", + "Losing Pitcher: Clay Holmes (Yankees)\n", + "\n", + "This article meets the expect criteria, providing a detailed game recap using the provided game information and stats, without making up any information.\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new CrewAgentExecutor chain...\u001b[0m\n", "\u001b[32;1m\u001b[1;3mThought: I now can give a great answer\n", - "Final Answer: \n", + "Final Answer: \n", "\n", - "The Baltimore Orioles edged out the New York Yankees in a thrilling 6-5 victory, taking the final game of the series despite the Yankees ultimately winning 2-1. \n", + "The Baltimore Orioles edged out the New York Yankees 6-5 in a thrilling contest, securing a series win for the Yankees despite the setback. Despite the loss, the Yankees prevailed in the series 2-1. \n", "\n", - "Dean Kremer started for the Orioles and pitched 4.2 innings, giving up 4 hits and 2 runs while striking out 4. Craig Kimbrel earned the win, his sixth of the season, pitching a scoreless ninth inning despite giving up a hit and walking two. \n", + "The Orioles' offense was led by Anthony Santander and Cedric Mullins, who each recorded two hits. Santander launched a home run, driving in a run while Mullins also brought in a run. Ryan Mountcastle contributed a hit and a run scored for the Orioles.\n", "\n", - "The Orioles offense was led by Anthony Santander, who went 2-for-4 with a home run and an RBI. Gunnar Henderson also contributed with a hit and run scored, while Jorge Mateo had two hits and scored a run.\n", + "For the Yankees, Trent Grisham turned in a strong performance, going 3-for-3 with a home run and two runs scored. \n", "\n", - "Carlos Rodón started for the Yankees and pitched 4 innings, giving up 4 hits and 2 runs. Clay Holmes took the loss, his fourth of the season, after giving up 3 runs in the bottom of the ninth. \n", - "\n", - "Trent Grisham was the offensive standout for the Yankees, going 3-for-4 with 3 hits, a home run, and 2 RBIs. \n", + "Dean Kremer picked up the win for the Orioles, pitching 4.2 innings, allowing 4 hits, 2 runs, and striking out 4. Craig Kimbrel earned the save, despite allowing three runs in the ninth inning, securing the victory for Baltimore. Clay Holmes took the loss for the Yankees, surrendering two runs in the bottom of the sixth. \n", "\n", "\n", "\u001b[0m\n", @@ -663,32 +652,28 @@ "\n", "\n", "\u001b[1m> Entering new CrewAgentExecutor chain...\u001b[0m\n", - "\u001b[32;1m\u001b[1;3mI now have all the necessary information to write a succinct game recap article.\n", + "\u001b[32;1m\u001b[1;3mI now can give a great answer\n", "\n", "Final Answer:\n", - "In a thrilling matchup, the Baltimore Orioles emerged victorious with a score of 6-5 against the New York Yankees. Dean Kremer secured the win for the Orioles, while Carlos Rodón was tagged with the loss for the Yankees.\n", - "\n", - "The Orioles' offense was led by Gunnar Henderson, who went 5-for-5 with a home run, a run scored, and an RBI. Other key contributors for the Orioles included Adley Rutschman (1 run, 1 walk), Ryan Mountcastle (1 hit, 1 walk, 1 run), Anthony Santander (2 hits, 1 RBI, 1 run), and Cedric Mullins (1 hit, 2 walks, 1 run).\n", + "In a thrilling matchup, the Baltimore Orioles emerged victorious with a score of 6-5 against the New York Yankees. Dean Kremer took the mound for the Orioles, while Carlos Rodón started for the Yankees. The Orioles' offense shone through, with Gunnar Henderson, Anthony Santander, Kyle Stowers, and Colton Cowser contributing to the team's six runs. Kremer pitched 4.2 innings, allowing 4 hits, 2 runs, and striking out 4. Reliever Craig Kimbrel earned the win for the Orioles, despite surrendering 3 runs in the top of the 10th inning.\n", "\n", - "For the Yankees, Ben Rice had a solid performance at the plate, going 5-for-5 with a run scored, an RBI, and a home run. Trent Grisham and Oswaldo Cabrera also contributed with 2 hits and 1 RBI each.\n", + "Among the winning team's top performers, Henderson went 1-for-5 with a home run and an RBI, while Santander finished 2-for-4 with a double, an RBI, and a run scored. Kyle Stowers and Colton Cowser each added a hit and a run. For the Orioles' pitching staff, Craig Kimbrel, Cionel Pérez, and Yennier Cano combined for 4.1 innings of shutout baseball, permitting just 2 hits and striking out 3.\n", "\n", - "Despite the Yankees taking a 2-1 series lead, the Orioles managed to turn things around in the final game, securing a much-needed win.\u001b[0m\n", + "The Yankees' offense was led by Ben Rice, Trent Grisham, and Oswaldo Cabrera, who collected 5 hits, 3 runs, and 2 RBIs among them. The Yankees' bullpen struggled, with Clay Holmes conceding 3 runs in just 0.2 innings, taking the loss. The series concluded with the Yankees winning 2 games to 1.\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new CrewAgentExecutor chain...\u001b[0m\n", - "\u001b[32;1m\u001b[1;3m\u001b[0m\u001b[32;1m\u001b[1;3mThought: I now can give a great answer\n", + "\u001b[32;1m\u001b[1;3mI can now give a great answer.\n", "\n", "Final Answer:\n", "\n", - "The Baltimore Orioles edged the New York Yankees 6-5 in the final game of the series, despite being down 2-1 in the series. Dean Kremer earned the win for the Orioles, while Clay Holmes took the loss for the Yankees.\n", + "The Baltimore Orioles edged the New York Yankees 6-5 to take the final game of the three-game series. The Orioles' winning pitcher was Craig Kimbrel, who earned his sixth win of the season despite blowing the save. The losing pitcher was Clay Holmes, who suffered his fourth loss of the season and also blew a save opportunity. The Orioles' top performer was Gunnar Henderson, who hit a home run and drove in two runs.\n", "\n", - "Anthony Santander was the top performer for the Orioles, going 2-for-4 with a home run and an RBI. Gunnar Henderson also had a strong game, hitting a home run and driving in two runs. Cedric Mullins added two RBIs for the Orioles.\n", + "Gunnar Henderson's teammate, Anthony Santander, also had a strong game, hitting a home run and driving in a run. Cedric Mullins added two RBIs for the Orioles. On the Yankees' side, Trent Grisham had a standout game, hitting a home run and driving in two runs. Ben Rice also drove in three runs for the Yankees.\n", "\n", - "For the Yankees, Trent Grisham had a standout game, going 3-for-3 with a home run and two RBIs. Ben Rice also hit a home run and drove in three runs. Anthony Volpe added a hit and a run scored for the Yankees.\n", - "\n", - "In the end, the Orioles' strong performance was enough to secure the win, despite a late-inning rally from the Yankees. The Yankees won the series 2-1, but the Orioles closed out the series with a hard-fought victory.\u001b[0m\n", + "Despite the loss, the Yankees took the series 2-1.\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n" ] @@ -697,6 +682,7 @@ "source": [ "user_prompt = 'Write a recap of the Yankees game on July 14, 2024'\n", "default_date = datetime.now().date() - timedelta(1) # Set default date to yesterday in case no date is specified\n", + "\n", "result = crew.kickoff(inputs={\"user_prompt\": user_prompt, \"default_date\": default_date})" ] }, @@ -705,12 +691,12 @@ "id": "473f0384-f9d2-4d4f-ac1d-e3adaf0f8238", "metadata": {}, "source": [ - "As you can see from the output, each of our MLB Writer agents made various mistakes in their game recaps: hallucinating the sequence of events (like the specific innings in which events occured, which it couldn't infer from the data provided), incorrect data analysis (Gunnar Henderson did not go 5-5), or poor formatting (i.e. not including the series result in the conclusion. However, by leveraging the results of all three articles our editing agent solves these issues and delivers a factual recap that follows all of our instructions." + "As you can see from the output, each of our MLB Writer agents made various mistakes in their game recaps: hallucinating the sequence of events (like the specific innings in which events occured, which it couldn't infer from the data provided), incorrect data analysis (Dean Kremer did not pick up the win), or poor formatting (i.e. not including the series result in the conclusion. However, by leveraging the results of all three articles our editing agent solves these issues and delivers a factual recap that follows all of our instructions." ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 9, "id": "3a36393a-0352-4438-bfd5-659c929ed282", "metadata": {}, "outputs": [ @@ -718,19 +704,25 @@ "name": "stdout", "output_type": "stream", "text": [ - "The Baltimore Orioles edged the New York Yankees 6-5 in the final game of the series, despite being down 2-1 in the series. Dean Kremer earned the win for the Orioles, while Clay Holmes took the loss for the Yankees.\n", - "\n", - "Anthony Santander was the top performer for the Orioles, going 2-for-4 with a home run and an RBI. Gunnar Henderson also had a strong game, hitting a home run and driving in two runs. Cedric Mullins added two RBIs for the Orioles.\n", + "The Baltimore Orioles edged the New York Yankees 6-5 to take the final game of the three-game series. The Orioles' winning pitcher was Craig Kimbrel, who earned his sixth win of the season despite blowing the save. The losing pitcher was Clay Holmes, who suffered his fourth loss of the season and also blew a save opportunity. The Orioles' top performer was Gunnar Henderson, who hit a home run and drove in two runs.\n", "\n", - "For the Yankees, Trent Grisham had a standout game, going 3-for-3 with a home run and two RBIs. Ben Rice also hit a home run and drove in three runs. Anthony Volpe added a hit and a run scored for the Yankees.\n", + "Gunnar Henderson's teammate, Anthony Santander, also had a strong game, hitting a home run and driving in a run. Cedric Mullins added two RBIs for the Orioles. On the Yankees' side, Trent Grisham had a standout game, hitting a home run and driving in two runs. Ben Rice also drove in three runs for the Yankees.\n", "\n", - "In the end, the Orioles' strong performance was enough to secure the win, despite a late-inning rally from the Yankees. The Yankees won the series 2-1, but the Orioles closed out the series with a hard-fought victory.\n" + "Despite the loss, the Yankees took the series 2-1.\n" ] } ], "source": [ "print(result)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "17b977ba-7fec-4a77-b717-0538f4de5ed7", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {