Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.3.64 #166

Merged
merged 24 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions cookbook/claude/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,51 @@ export ANTHROPIC_API_KEY=xxx
### 3. Install libraries

```shell
pip install -U anthropic phidata duckduckgo-search duckdb yfinance exa_py
pip install -U anthropic duckduckgo-search duckdb yfinance exa_py phidata
```

### 4. Web search function calling
### 4. Run Assistant

- stream on

```shell
python cookbook/claude/web_search.py
python cookbook/claude/assistant.py
```

### 5. YFinance function calling
- stream off

```shell
python cookbook/claude/finance.py
python cookbook/claude/assistant_stream_off.py
```

### 6. Structured output
### 5. Run Assistant with Tools

- Web search

```shell
python cookbook/claude/structured_output.py
python cookbook/claude/web_search.py
```

- YFinance

```shell
python cookbook/claude/finance.py
```

### 7. Data Analyst
- Data Analyst

```shell
python cookbook/claude/data_analyst.py
```

### 8. Exa Search
- Exa Search

```shell
python cookbook/claude/exa_search.py
```

### 6. Run Assistant with Structured output

```shell
python cookbook/claude/structured_output.py
```
12 changes: 9 additions & 3 deletions cookbook/claude/exa_search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from phi.assistant import Assistant
from phi.llm.anthropic import Claude
from phi.tools.exa import ExaTools
from phi.tools.website import WebsiteTools
from phi.llm.anthropic import Claude

assistant = Assistant(llm=Claude(), tools=[ExaTools()], show_tool_calls=True)
assistant.cli_app(markdown=True)
assistant = Assistant(llm=Claude(), tools=[ExaTools(), WebsiteTools()], show_tool_calls=True)
assistant.print_response(
"Produce this table: research chromatic homotopy theory."
"Access each link in the result outputting the summary for that article, its link, and keywords; "
"After the table output make conceptual ascii art of the overarching themes and constructions",
markdown=True,
)
10 changes: 7 additions & 3 deletions cookbook/claude/finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
from phi.llm.anthropic import Claude

assistant = Assistant(
llm=Claude(model="claude-3-opus-20240229"),
name="Finance Assistant",
llm=Claude(model="claude-3-haiku-20240307"),
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True)],
show_tool_calls=True,
description="You are an investment analyst that researches stock prices, analyst recommendations, and stock fundamentals.",
instructions=["Format your response using markdown and use tables to display data where possible."],
# debug_mode=True,
)
assistant.print_response("Share the NVDA stock price and some analyst recommendations", markdown=True)
assistant.print_response("Summarize fundamentals for TSLA", markdown=True)
assistant.print_response("Share the NVDA stock price and analyst recommendations", markdown=True)
# assistant.print_response("Summarize fundamentals for TSLA", markdown=True)
2 changes: 1 addition & 1 deletion cookbook/claude/web_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
llm=Claude(model="claude-3-opus-20240229"),
tools=[DuckDuckGo()],
show_tool_calls=True,
debug_mode=True,
# debug_mode=True,
)
assistant.print_response("Share 1 story from france and 1 from germany?", markdown=True, stream=False)
48 changes: 48 additions & 0 deletions cookbook/cohere/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# CohereChat function calling

Currently "command-r" model supports function calling

> 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 CohereChat API Key

```shell
export CO_API_KEY=xxx
```

### 3. Install libraries

```shell
pip install -U cohere duckduckgo-search yfinance exa_py phidata
```

### 4. Web search function calling

```shell
python cookbook/cohere/web_search.py
```

### 5. YFinance function calling

```shell
python cookbook/cohere/finance.py
```

### 6. Structured output

```shell
python cookbook/cohere/structured_output.py
```

### 7. Exa Search

```shell
python cookbook/cohere/exa_search.py
```
Empty file added cookbook/cohere/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions cookbook/cohere/assistant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from phi.assistant import Assistant
from phi.llm.cohere import CohereChat

assistant = Assistant(
llm=CohereChat(model="command-r"),
description="You help people with their health and fitness goals.",
debug_mode=True,
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True)
9 changes: 9 additions & 0 deletions cookbook/cohere/assistant_stream_off.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from phi.assistant import Assistant
from phi.llm.cohere import CohereChat

assistant = Assistant(
llm=CohereChat(model="command-r"),
description="You help people with their health and fitness goals.",
debug_mode=True,
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False)
20 changes: 20 additions & 0 deletions cookbook/cohere/data_analyst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from phi.assistant import Assistant
from phi.llm.cohere import CohereChat
from phi.tools.duckdb import DuckDbTools

duckdb_tools = DuckDbTools(create_tables=False, export_tables=False, summarize_tables=False)
duckdb_tools.create_table_from_path(
path="https://phidata-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv", table="movies"
)

assistant = Assistant(
llm=CohereChat(model="command-r-plus"),
tools=[duckdb_tools],
show_tool_calls=True,
add_to_system_prompt="""
Here are the tables you have access to:
- movies: Contains information about movies from IMDB.
""",
# debug_mode=True,
)
assistant.print_response("What is the average rating of movies?", markdown=True, stream=False)
12 changes: 12 additions & 0 deletions cookbook/cohere/exa_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from phi.assistant import Assistant
from phi.tools.exa import ExaTools
from phi.tools.website import WebsiteTools
from phi.llm.cohere import CohereChat

assistant = Assistant(llm=CohereChat(model="command-r-plus"), tools=[ExaTools(), WebsiteTools()], show_tool_calls=True)
assistant.print_response(
"Produce this table: research chromatic homotopy theory."
"Access each link in the result outputting the summary for that article, its link, and keywords; "
"After the table output make conceptual ascii art of the overarching themes and constructions",
markdown=True,
)
14 changes: 14 additions & 0 deletions cookbook/cohere/finance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from phi.assistant import Assistant
from phi.tools.yfinance import YFinanceTools
from phi.llm.cohere import CohereChat

assistant = Assistant(
llm=CohereChat(model="command-r-plus"),
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True)],
show_tool_calls=True,
description="You are an investment analyst that researches stock prices, analyst recommendations, and stock fundamentals.",
instructions=["Format your response using markdown and use tables to display data where possible."],
# debug_mode=True,
)
assistant.print_response("Share the NVDA stock price and analyst recommendations", markdown=True)
assistant.print_response("Summarize fundamentals for TSLA", markdown=True)
26 changes: 26 additions & 0 deletions cookbook/cohere/structured_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import List
from pydantic import BaseModel, Field
from rich.pretty import pprint
from phi.assistant import Assistant
from phi.llm.cohere import CohereChat


class MovieScript(BaseModel):
setting: str = Field(..., description="Provide a nice setting for a blockbuster movie.")
ending: str = Field(..., description="Ending of the movie. If not available, provide a happy ending.")
genre: str = Field(
..., description="Genre of the movie. If not available, select action, thriller or romantic comedy."
)
name: str = Field(..., description="Give a name to this movie")
characters: List[str] = Field(..., description="Name of characters for this movie.")
storyline: str = Field(..., description="3 sentence storyline for the movie. Make it exciting!")


movie_assistant = Assistant(
llm=CohereChat(model="command-r"),
description="You help people write movie scripts.",
output_model=MovieScript,
debug_mode=True,
)

pprint(movie_assistant.run("New York"))
12 changes: 12 additions & 0 deletions cookbook/cohere/web_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from phi.assistant import Assistant
from phi.tools.duckduckgo import DuckDuckGo
from phi.llm.cohere import CohereChat

assistant = Assistant(
llm=CohereChat(model="command-r"),
tools=[DuckDuckGo()],
show_tool_calls=True,
instructions=["Format your response using markdown and use tables to display information where possible."],
debug_mode=True,
)
assistant.print_response("Share 1 story from france and 1 from germany?", markdown=True)
12 changes: 12 additions & 0 deletions cookbook/groq/finance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from phi.assistant import Assistant
from phi.tools.yfinance import YFinanceTools
from phi.llm.groq import Groq

assistant = Assistant(
llm=Groq(model="mixtral-8x7b-32768"),
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True)],
show_tool_calls=True,
# debug_mode=True,
)
assistant.print_response("Share the NVDA stock price and analyst recommendations", markdown=True, stream=False)
# assistant.print_response("Summarize fundamentals for TSLA", markdown=True, stream=False)
26 changes: 26 additions & 0 deletions cookbook/groq/structured_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import List
from pydantic import BaseModel, Field
from rich.pretty import pprint
from phi.assistant import Assistant
from phi.llm.groq import Groq


class MovieScript(BaseModel):
setting: str = Field(..., description="Provide a nice setting for a blockbuster movie.")
ending: str = Field(..., description="Ending of the movie. If not available, provide a happy ending.")
genre: str = Field(
..., description="Genre of the movie. If not available, select action, thriller or romantic comedy."
)
name: str = Field(..., description="Give a name to this movie")
characters: List[str] = Field(..., description="Name of characters for this movie.")
storyline: str = Field(..., description="3 sentence storyline for the movie. Make it exciting!")


movie_assistant = Assistant(
llm=Groq(model="mixtral-8x7b-32768"),
description="You help people write movie scripts.",
output_model=MovieScript,
# debug_mode=True,
)

pprint(movie_assistant.run("New York"))
11 changes: 11 additions & 0 deletions cookbook/groq/web_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from phi.assistant import Assistant
from phi.tools.duckduckgo import DuckDuckGo
from phi.llm.groq import Groq

assistant = Assistant(
llm=Groq(model="mixtral-8x7b-32768"),
tools=[DuckDuckGo()],
show_tool_calls=True,
# debug_mode=True
)
assistant.print_response("Tell me about OpenAI Sora", markdown=True, stream=False)
4 changes: 2 additions & 2 deletions cookbook/hermes2/assistant.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from phi.assistant import Assistant
from phi.llm.ollama import Ollama
from phi.llm.ollama import Hermes

assistant = Assistant(
llm=Ollama(model="adrienbrault/nous-hermes2pro:Q8_0"),
llm=Hermes(model="adrienbrault/nous-hermes2pro:Q8_0"),
description="You help people with their health and fitness goals.",
)
assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True)
2 changes: 1 addition & 1 deletion cookbook/hermes2/finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True)],
show_tool_calls=True,
)
assistant.print_response("Share the NVDA stock price and some analyst recommendations", markdown=True)
assistant.print_response("Share the NVDA stock price and analyst recommendations", markdown=True)
assistant.print_response("Summarize fundamentals for TSLA", markdown=True)
2 changes: 1 addition & 1 deletion cookbook/knowledge/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
)

# Use the assistant
assistant.print_response("Ask me about something from the knowledge base", markdown=True)
assistant.print_response("Ask me about something from the knowledge base", markdown=True)
7 changes: 5 additions & 2 deletions cookbook/pinecone/assistant.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import typer
from typing import Optional
from rich.prompt import Prompt
from typing import Optional, List

from phi.assistant import Assistant
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.pineconedb import PineconeDB
import os

api_key = os.getenv("PINECONE_API_KEY")
index_name = "recipes"
Expand All @@ -28,6 +29,7 @@
# Comment out after first run
# knowledge_base.load(recreate=False)


def pdf_assistant(user: str = "user"):
run_id: Optional[str] = None

Expand Down Expand Up @@ -55,5 +57,6 @@ def pdf_assistant(user: str = "user"):
break
assistant.print_response(message)


if __name__ == "__main__":
typer.run(pdf_assistant)
6 changes: 3 additions & 3 deletions cookbook/teams/hackernews.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import httpx

from phi.assistant.team import Assistant, Team
from phi.assistant.team import Assistant
from phi.utils.log import logger


Expand Down Expand Up @@ -95,5 +95,5 @@ def get_user_details(username: str) -> str:
show_tool_calls=True,
)

team = Team(name="HackerNews", assistants=[hn_top_stories, hn_user_researcher], debug_mode=True)
team.print_response("Tell me about the users with the top 2 stores on hackernews?", markdown=True)
hn_assistant = Assistant(name="HackerNews Assistant", team=[hn_top_stories, hn_user_researcher], debug_mode=True)
hn_assistant.print_response("Tell me about the users with the top 2 stores on hackernews?", markdown=True)
Loading
Loading