Skip to content

Commit

Permalink
Groq Research Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Dec 7, 2024
1 parent d081613 commit 64249db
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cookbook/providers/groq/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cookbook/providers/groq/agent_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 34 additions & 0 deletions cookbook/providers/groq/agent_team.py
Original file line number Diff line number Diff line change
@@ -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)
84 changes: 84 additions & 0 deletions cookbook/providers/groq/agent_ui.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion cookbook/providers/groq/basic.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cookbook/providers/groq/basic_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cookbook/providers/groq/data_analyst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cookbook/providers/groq/knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions cookbook/providers/groq/research_agent_ddg.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion cookbook/providers/groq/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cookbook/providers/groq/structured_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cookbook/providers/groq/web_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion cookbook/providers/openai/finance_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 64249db

Please sign in to comment.