Skip to content

Commit

Permalink
Update groq agent
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Nov 17, 2024
1 parent e2af352 commit 819a829
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
84 changes: 84 additions & 0 deletions cookbook/playground/groq_agents.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/playground/groq_agents.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

xai_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="llama3-groq-70b-8192-tool-use-preview"),
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=xai_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="llama3-groq-70b-8192-tool-use-preview"),
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=xai_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="llama3-groq-70b-8192-tool-use-preview"),
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=xai_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("groq_agents:app", reload=True)
8 changes: 8 additions & 0 deletions cookbook/providers/groq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ python cookbook/providers/groq/structured_output.py

### 7. Run Agent that uses storage

Please run pgvector in a docker container using:

```shell
./cookbook/run_pgvector.sh
```

Then run the following:

```shell
python cookbook/providers/groq/storage.py
```
Expand Down
4 changes: 3 additions & 1 deletion cookbook/providers/groq/finance_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
markdown=True,
)

agent.print_response("Summarize and compare analyst recommendations and fundamentals for TSLA and NVDA. Show in tables.", 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 819a829

Please sign in to comment.