diff --git a/cookbook/providers/groq/agent.py b/cookbook/providers/groq/agent.py index 16b70a633..e3098ab67 100644 --- a/cookbook/providers/groq/agent.py +++ b/cookbook/providers/groq/agent.py @@ -5,7 +5,7 @@ from phi.tools.yfinance import YFinanceTools agent = Agent( - model=Groq(id="llama3-groq-70b-8192-tool-use-preview"), + model=Groq(id="llama-3.3-70b-versatile"), tools=[YFinanceTools(stock_price=True)], show_tool_calls=True, markdown=True, diff --git a/cookbook/providers/groq/agent_stream.py b/cookbook/providers/groq/agent_stream.py index f4d5b7a06..e128f29b1 100644 --- a/cookbook/providers/groq/agent_stream.py +++ b/cookbook/providers/groq/agent_stream.py @@ -6,7 +6,7 @@ from phi.tools.yfinance import YFinanceTools agent = Agent( - model=Groq(id="llama3-groq-70b-8192-tool-use-preview"), + model=Groq(id="llama-3.3-70b-versatile"), tools=[YFinanceTools(stock_price=True)], show_tool_calls=True, markdown=True, diff --git a/cookbook/providers/groq/agent_team.py b/cookbook/providers/groq/agent_team.py new file mode 100644 index 000000000..3eae90920 --- /dev/null +++ b/cookbook/providers/groq/agent_team.py @@ -0,0 +1,34 @@ +from phi.agent import Agent +from phi.model.groq import Groq +from phi.tools.duckduckgo import DuckDuckGo +from phi.tools.yfinance import YFinanceTools + +web_agent = Agent( + name="Web Agent", + role="Search the web for information", + model=Groq(id="llama-3.3-70b-versatile"), + tools=[DuckDuckGo()], + instructions=["Always include sources"], + show_tool_calls=True, + markdown=True, +) + +finance_agent = Agent( + name="Finance Agent", + role="Get financial data", + model=Groq(id="llama-3.3-70b-versatile"), + tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True)], + instructions=["Use tables to display data"], + show_tool_calls=True, + markdown=True, +) + +team_leader = Agent( + team=[web_agent, finance_agent], + model=Groq(id="llama-3.3-70b-versatile"), + instructions=["Always include sources", "Use tables to display data"], + show_tool_calls=True, + markdown=True, +) + +team_leader.print_response("Summarize analyst recommendations and share the latest news for NVDA", stream=True) diff --git a/cookbook/providers/groq/agent_ui.py b/cookbook/providers/groq/agent_ui.py new file mode 100644 index 000000000..72278f5d5 --- /dev/null +++ b/cookbook/providers/groq/agent_ui.py @@ -0,0 +1,84 @@ +"""Usage: +1. Install libraries: `pip install groq duckduckgo-search yfinance pypdf sqlalchemy 'fastapi[standard]' youtube-transcript-api phidata` +2. Run the script: `python cookbook/providers/groq/agent_ui.py` +""" + +from phi.agent import Agent +from phi.model.groq import Groq +from phi.playground import Playground, serve_playground_app +from phi.storage.agent.sqlite import SqlAgentStorage +from phi.tools.duckduckgo import DuckDuckGo +from phi.tools.yfinance import YFinanceTools +from phi.tools.youtube_tools import YouTubeTools + +groq_agent_storage: str = "tmp/groq_agents.db" +common_instructions = [ + "If the user about you or your skills, tell them your name and role.", +] + +web_agent = Agent( + name="Web Agent", + role="Search the web for information", + agent_id="web-agent", + model=Groq(id="llama-3.3-70b-versatile"), + tools=[DuckDuckGo()], + instructions=[ + "Use the `duckduckgo_search` or `duckduckgo_news` tools to search the web for information.", + "Always include sources you used to generate the answer.", + ] + + common_instructions, + storage=SqlAgentStorage(table_name="web_agent", db_file=groq_agent_storage), + show_tool_calls=True, + add_history_to_messages=True, + num_history_responses=2, + add_name_to_instructions=True, + add_datetime_to_instructions=True, + markdown=True, +) + +finance_agent = Agent( + name="Finance Agent", + role="Get financial data", + agent_id="finance-agent", + model=Groq(id="llama-3.3-70b-versatile"), + tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)], + description="You are an investment analyst that researches stocks and helps users make informed decisions.", + instructions=["Always use tables to display data"] + common_instructions, + storage=SqlAgentStorage(table_name="finance_agent", db_file=groq_agent_storage), + show_tool_calls=True, + add_history_to_messages=True, + num_history_responses=5, + add_name_to_instructions=True, + add_datetime_to_instructions=True, + markdown=True, +) + + +youtube_agent = Agent( + name="YouTube Agent", + role="Understand YouTube videos and answer questions", + agent_id="youtube-agent", + model=Groq(id="llama-3.3-70b-versatile"), + tools=[YouTubeTools()], + description="You are a YouTube agent that has the special skill of understanding YouTube videos and answering questions about them.", + instructions=[ + "Using a video URL, get the video data using the `get_youtube_video_data` tool and captions using the `get_youtube_video_data` tool.", + "Using the data and captions, answer the user's question in an engaging and thoughtful manner. Focus on the most important details.", + "If you cannot find the answer in the video, say so and ask the user to provide more details.", + "Keep your answers concise and engaging.", + "If the user just provides a URL, summarize the video and answer questions about it.", + ] + + common_instructions, + storage=SqlAgentStorage(table_name="youtube_agent", db_file=groq_agent_storage), + show_tool_calls=True, + add_history_to_messages=True, + num_history_responses=5, + add_name_to_instructions=True, + add_datetime_to_instructions=True, + markdown=True, +) + +app = Playground(agents=[finance_agent, youtube_agent, web_agent]).get_app(use_async=False) + +if __name__ == "__main__": + serve_playground_app("agent_ui:app", reload=True) diff --git a/cookbook/providers/groq/basic.py b/cookbook/providers/groq/basic.py index a39878d54..3d49c63de 100644 --- a/cookbook/providers/groq/basic.py +++ b/cookbook/providers/groq/basic.py @@ -1,7 +1,7 @@ from phi.agent import Agent, RunResponse # noqa from phi.model.groq import Groq -agent = Agent(model=Groq(id="llama3-groq-70b-8192-tool-use-preview"), markdown=True) +agent = Agent(model=Groq(id="llama-3.3-70b-versatile"), markdown=True) # Get the response in a variable # run: RunResponse = agent.run("Share a 2 sentence horror story") diff --git a/cookbook/providers/groq/basic_stream.py b/cookbook/providers/groq/basic_stream.py index 09b9cdba6..c8e236727 100644 --- a/cookbook/providers/groq/basic_stream.py +++ b/cookbook/providers/groq/basic_stream.py @@ -2,7 +2,7 @@ from phi.agent import Agent, RunResponse # noqa from phi.model.groq import Groq -agent = Agent(model=Groq(id="llama3-groq-70b-8192-tool-use-preview"), markdown=True) +agent = Agent(model=Groq(id="llama-3.3-70b-versatile"), markdown=True) # Get the response in a variable # run_response: Iterator[RunResponse] = agent.run("Share a 2 sentence horror story", stream=True) diff --git a/cookbook/providers/groq/data_analyst.py b/cookbook/providers/groq/data_analyst.py index c963b8a22..67166b876 100644 --- a/cookbook/providers/groq/data_analyst.py +++ b/cookbook/providers/groq/data_analyst.py @@ -11,7 +11,7 @@ ) agent = Agent( - model=Groq(id="llama3-groq-70b-8192-tool-use-preview"), + model=Groq(id="llama-3.3-70b-versatile"), tools=[duckdb_tools], markdown=True, show_tool_calls=True, diff --git a/cookbook/providers/groq/knowledge.py b/cookbook/providers/groq/knowledge.py index 1afadbd84..ef1579f2a 100644 --- a/cookbook/providers/groq/knowledge.py +++ b/cookbook/providers/groq/knowledge.py @@ -14,7 +14,7 @@ knowledge_base.load(recreate=False) # Comment out after first run agent = Agent( - model=Groq(id="llama3-groq-70b-8192-tool-use-preview"), + model=Groq(id="llama-3.3-70b-versatile"), knowledge_base=knowledge_base, use_tools=True, show_tool_calls=True, diff --git a/cookbook/providers/groq/research_agent_ddg.py b/cookbook/providers/groq/research_agent_ddg.py new file mode 100644 index 000000000..a0a97724b --- /dev/null +++ b/cookbook/providers/groq/research_agent_ddg.py @@ -0,0 +1,24 @@ +"""Please install dependencies using: +pip install openai duckduckgo-search newspaper4k lxml_html_clean phidata +""" + +from phi.agent import Agent +from phi.model.groq import Groq +from phi.tools.duckduckgo import DuckDuckGo +from phi.tools.newspaper4k import Newspaper4k + +agent = Agent( + model=Groq(id="llama-3.3-70b-versatile"), + tools=[DuckDuckGo(), Newspaper4k()], + description="You are a senior NYT researcher writing an article on a topic.", + instructions=[ + "For a given topic, search for the top 5 links.", + "Then read each URL and extract the article text, if a URL isn't available, ignore it.", + "Analyse and prepare an NYT worthy article based on the information.", + ], + markdown=True, + show_tool_calls=True, + add_datetime_to_instructions=True, + # debug_mode=True, +) +agent.print_response("Simulation theory", stream=True) diff --git a/cookbook/providers/groq/research_agent.py b/cookbook/providers/groq/research_agent_exa.py similarity index 92% rename from cookbook/providers/groq/research_agent.py rename to cookbook/providers/groq/research_agent_exa.py index 63fd6f4a1..49915d2f1 100644 --- a/cookbook/providers/groq/research_agent.py +++ b/cookbook/providers/groq/research_agent_exa.py @@ -15,8 +15,8 @@ today = datetime.now().strftime("%Y-%m-%d") -assistant = Agent( - llm=Groq(model="llama-3.3-70b-versatile"), +agent = Agent( + model=Groq(id="llama-3.3-70b-versatile"), tools=[ExaTools(start_published_date=today, type="keyword")], description="You are an advanced AI researcher writing a report on a topic.", instructions=[ @@ -58,4 +58,4 @@ save_response_to_file=str(tmp.joinpath("{message}.md")), # debug_mode=True, ) -assistant.print_response("Llama 3.3 running on Groq", stream=True) +agent.print_response("Llama 3.3 running on Groq", stream=True) diff --git a/cookbook/providers/groq/storage.py b/cookbook/providers/groq/storage.py index d2f561f7e..7a3aa8207 100644 --- a/cookbook/providers/groq/storage.py +++ b/cookbook/providers/groq/storage.py @@ -8,7 +8,7 @@ db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai" agent = Agent( - model=Groq(id="llama3-groq-70b-8192-tool-use-preview"), + model=Groq(id="llama-3.3-70b-versatile"), storage=PgAgentStorage(table_name="agent_sessions", db_url=db_url), tools=[DuckDuckGo()], add_history_to_messages=True, diff --git a/cookbook/providers/groq/structured_output.py b/cookbook/providers/groq/structured_output.py index 57509ddcf..386bd0914 100644 --- a/cookbook/providers/groq/structured_output.py +++ b/cookbook/providers/groq/structured_output.py @@ -17,7 +17,7 @@ class MovieScript(BaseModel): json_mode_agent = Agent( - model=Groq(id="mixtral-8x7b-32768"), + model=Groq(id="llama-3.3-70b-versatile"), description="You help people write movie scripts.", response_model=MovieScript, # debug_mode=True, diff --git a/cookbook/providers/groq/web_search.py b/cookbook/providers/groq/web_search.py index 0508342e8..049dc0943 100644 --- a/cookbook/providers/groq/web_search.py +++ b/cookbook/providers/groq/web_search.py @@ -5,7 +5,7 @@ from phi.tools.duckduckgo import DuckDuckGo agent = Agent( - model=Groq(id="llama3-groq-70b-8192-tool-use-preview"), + model=Groq(id="llama-3.3-70b-versatile"), tools=[DuckDuckGo()], show_tool_calls=True, markdown=True, diff --git a/cookbook/providers/openai/finance_agent.py b/cookbook/providers/openai/finance_agent.py index 720fbdd1d..9df1c49ab 100644 --- a/cookbook/providers/openai/finance_agent.py +++ b/cookbook/providers/openai/finance_agent.py @@ -14,4 +14,6 @@ ) # agent.print_response("Share the NVDA stock price and analyst recommendations", stream=True) -agent.print_response("Summarize fundamentals for TSLA", stream=True) +agent.print_response( + "Summarize and compare analyst recommendations and fundamentals for TSLA and NVDA. Show in tables.", stream=True +)