-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87388fb
commit 05fbef1
Showing
11 changed files
with
228 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Agents 101 | ||
|
||
> Note: Fork and clone this repository if needed | ||
### 1. Create and activate a virtual environment | ||
|
||
```shell | ||
python3 -m venv ~/.venvs/aienv | ||
source ~/.venvs/aienv/bin/activate | ||
``` | ||
|
||
### 2. Export your `OPENAI_API_KEY` | ||
|
||
```shell | ||
export OPENAI_API_KEY=*** | ||
``` | ||
|
||
### 3. Install libraries | ||
|
||
```shell | ||
pip install -U openai duckduckgo-search duckdb yfinance lancedb tantivy pypdf sqlalchemy 'fastapi[standard]' phidata | ||
``` | ||
|
||
### 4. Web Search Agent | ||
|
||
```shell | ||
python cookbook/agents_101/web_search.py | ||
``` | ||
|
||
### 5. Web Reader Agent | ||
|
||
```shell | ||
python cookbook/agents_101/web_reader.py | ||
``` | ||
|
||
### 5. Finance Agent | ||
|
||
```shell | ||
python cookbook/agents_101/finance_agent.py | ||
``` | ||
|
||
### 6. RAG Agent | ||
|
||
```shell | ||
python cookbook/agents_101/rag_agent.py | ||
``` | ||
|
||
### 7. Playground | ||
|
||
Authenticate with phidata.app | ||
|
||
``` | ||
phi auth | ||
``` | ||
|
||
Run the playground | ||
|
||
```shell | ||
python cookbook/agents_101/playground.py | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"""Run `pip install yfinance` to install dependencies.""" | ||
|
||
from phi.agent import Agent | ||
from phi.model.openai import OpenAIChat | ||
from phi.tools.yfinance import YFinanceTools | ||
|
||
finance_agent = Agent( | ||
name="Finance Agent", | ||
role="Get financial data", | ||
model=OpenAIChat(id="gpt-4o"), | ||
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)], | ||
instructions=["Always use tables to display data"], | ||
markdown=True, | ||
show_tool_calls=True, | ||
) | ||
finance_agent.print_response("Share analyst recommendations for NVDA and provide a recommendation", stream=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from phi.agent import Agent | ||
from phi.model.openai import OpenAIChat | ||
from phi.tools.duckduckgo import DuckDuckGo | ||
from phi.tools.yfinance import YFinanceTools | ||
from phi.storage.agent.sqlite import SqlAgentStorage | ||
from phi.playground import Playground, serve_playground_app | ||
|
||
web_agent = Agent( | ||
name="Web Agent", | ||
agent_id="web_agent", | ||
role="Search the web for information", | ||
model=OpenAIChat(id="gpt-4o"), | ||
tools=[DuckDuckGo()], | ||
instructions=["Always include sources"], | ||
storage=SqlAgentStorage(table_name="web_agent_sessions", db_file="tmp/agents.db"), | ||
markdown=True, | ||
) | ||
|
||
finance_agent = Agent( | ||
name="Finance Agent", | ||
agent_id="finance_agent", | ||
role="Get financial data", | ||
model=OpenAIChat(id="gpt-4o"), | ||
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)], | ||
instructions=["Always use tables to display data"], | ||
storage=SqlAgentStorage(table_name="finance_agent_sessions", db_file="tmp/agents.db"), | ||
markdown=True, | ||
) | ||
|
||
agent_team = Agent( | ||
name="Agent Team", | ||
agent_id="agent_team", | ||
team=[web_agent, finance_agent], | ||
storage=SqlAgentStorage(table_name="agent_team_sessions", db_file="tmp/agents.db"), | ||
markdown=True, | ||
) | ||
|
||
app = Playground(agents=[finance_agent, web_agent, agent_team]).get_app() | ||
|
||
if __name__ == "__main__": | ||
serve_playground_app("playground:app", reload=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Run `pip install openai lancedb tantivy` to install dependencies.""" | ||
|
||
from phi.agent import Agent | ||
from phi.model.openai import OpenAIChat | ||
from phi.knowledge.pdf import PDFUrlKnowledgeBase | ||
from phi.vectordb.lancedb import LanceDb, SearchType | ||
|
||
db_uri = "tmp/lancedb" | ||
knowledge_base = PDFUrlKnowledgeBase( | ||
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"], | ||
vector_db=LanceDb(table_name="recipes", uri=db_uri, search_type=SearchType.vector), | ||
) | ||
# Load the knowledge base: Comment out after first run | ||
knowledge_base.load(upsert=True) | ||
|
||
agent = Agent( | ||
model=OpenAIChat(id="gpt-4o"), | ||
knowledge=knowledge_base, | ||
# Add a tool to read chat history. | ||
read_chat_history=True, | ||
show_tool_calls=True, | ||
markdown=True, | ||
# debug_mode=True, | ||
) | ||
agent.print_response("How do I make chicken and galangal in coconut milk soup", stream=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"""Run `pip install duckduckgo-search sqlalchemy openai` to install dependencies.""" | ||
|
||
from phi.agent import Agent | ||
from phi.tools.duckduckgo import DuckDuckGo | ||
from phi.storage.agent.sqlite import SqlAgentStorage | ||
|
||
agent = Agent( | ||
storage=SqlAgentStorage(table_name="agent_runs", db_file="tmp/data.db"), | ||
tools=[DuckDuckGo()], | ||
add_history_to_messages=True, | ||
) | ||
agent.print_response("How many people live in Canada?") | ||
agent.print_response("What is their national anthem called?") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Run `pip install openai duckduckgo-search` to install dependencies.""" | ||
|
||
from phi.agent import Agent | ||
from phi.model.openai import OpenAIChat | ||
from phi.tools.duckduckgo import DuckDuckGo | ||
|
||
web_agent = Agent( | ||
name="Web Agent", | ||
role="Search the web for information", | ||
model=OpenAIChat(id="gpt-4o"), | ||
tools=[DuckDuckGo()], | ||
instructions=["Always include sources"], | ||
markdown=True, | ||
show_tool_calls=True, | ||
add_datetime_to_instructions=True, | ||
) | ||
web_agent.print_response("Write a report on the US election", stream=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters