-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Showing
15 changed files
with
643 additions
and
1 deletion.
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
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,64 @@ | ||
# Anthropic Claude | ||
|
||
[Models overview](https://docs.anthropic.com/claude/docs/models-overview) | ||
|
||
> 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. Set your `ANTHROPIC_API_KEY` | ||
|
||
```shell | ||
export ANTHROPIC_API_KEY=xxx | ||
``` | ||
|
||
### 3. Install libraries | ||
|
||
```shell | ||
pip install -U anthropic duckduckgo-search duckdb yfinance exa_py phidata | ||
``` | ||
|
||
### 4. Run Assistant | ||
|
||
- stream on | ||
|
||
```shell | ||
python cookbook/llms/claude/assistant.py | ||
``` | ||
|
||
- stream off | ||
|
||
```shell | ||
python cookbook/llms/claude/assistant_stream_off.py | ||
``` | ||
|
||
### 5. Run Assistant with Tools | ||
|
||
- YFinance | ||
|
||
```shell | ||
python cookbook/llms/claude/finance.py | ||
``` | ||
|
||
- Data Analyst | ||
|
||
```shell | ||
python cookbook/llms/claude/data_analyst.py | ||
``` | ||
|
||
- Exa Search | ||
|
||
```shell | ||
python cookbook/llms/claude/exa_search.py | ||
``` | ||
|
||
### 6. Run Assistant with Structured output | ||
|
||
```shell | ||
python cookbook/llms/claude/structured_output.py | ||
``` |
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,10 @@ | ||
from phi.agent import Agent | ||
from phi.tools.duckduckgo import DuckDuckGo | ||
from phi.model.anthropic import Claude | ||
|
||
assistant = Agent( | ||
model=Claude(model="claude-3-5-sonnet-20240620"), | ||
tools=[DuckDuckGo()], | ||
show_tool_calls=True, | ||
) | ||
assistant.print_response("Whats happening in France", markdown=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,18 @@ | ||
from rich.pretty import pprint | ||
from phi.agent import Agent | ||
from phi.tools.duckduckgo import DuckDuckGo | ||
from phi.model.anthropic import Claude | ||
|
||
agent = Agent( | ||
model=Claude(model="claude-3-5-sonnet-20240620"), | ||
tools=[DuckDuckGo()], | ||
show_tool_calls=True, | ||
debug_mode=True, | ||
) | ||
# agent.print_response("Whats happening in France?", markdown=True, stream=False) | ||
|
||
response = agent.run("Whats happening in France?", markdown=True, stream=False) | ||
|
||
pprint(response) | ||
|
||
|
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 @@ | ||
from phi.agent import Agent | ||
from phi.model.anthropic import Claude | ||
|
||
# agent = Agent( | ||
# llm=Claude(model="claude-3-haiku-20240307"), | ||
# description="You help people with their health and fitness goals.", | ||
# debug_mode=True, | ||
# ) | ||
# agent.print_response("Share a quick healthy breakfast recipe.", markdown=True) | ||
|
||
|
||
agent = Agent( | ||
model=Claude(model="claude-3-5-sonnet-20240620"), | ||
description="You help people with their health and fitness goals.", | ||
debug_mode=True, | ||
) | ||
agent.print_response("Share a quick healthy breakfast recipe.", markdown=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,15 @@ | ||
from rich.pretty import pprint | ||
from phi.agent import Agent | ||
from phi.model.anthropic import Claude | ||
|
||
agent = Agent( | ||
model=Claude(model="claude-3-5-sonnet-20240620"), | ||
description="You help people with their health and fitness goals.", | ||
debug_mode=True, | ||
) | ||
# agent.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False) | ||
|
||
|
||
response = agent.run("Share a quick healthy breakfast recipe.", markdown=True, stream=False) | ||
|
||
pprint(response) |
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,20 @@ | ||
from phi.assistant import Assistant | ||
from phi.llm.anthropic import Claude | ||
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=Claude(model="claude-3-opus-20240229"), | ||
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) |
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,12 @@ | ||
from phi.assistant import Assistant | ||
from phi.tools.exa import ExaTools | ||
from phi.tools.website import WebsiteTools | ||
from phi.llm.anthropic import Claude | ||
|
||
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, | ||
) |
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,15 @@ | ||
from phi.assistant import Assistant | ||
from phi.tools.yfinance import YFinanceTools | ||
from phi.llm.anthropic import Claude | ||
|
||
assistant = Assistant( | ||
llm=Claude(model="claude-3-5-sonnet-20240620"), | ||
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=["Use tables to display data where possible."], | ||
markdown=True, | ||
# debug_mode=True, | ||
) | ||
# assistant.print_response("Share the NVDA stock price and analyst recommendations") | ||
assistant.print_response("Summarize fundamentals for TSLA") |
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,26 @@ | ||
from typing import List | ||
from pydantic import BaseModel, Field | ||
from rich.pretty import pprint | ||
from phi.assistant import Assistant | ||
from phi.llm.anthropic import Claude | ||
|
||
|
||
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=Claude(model="claude-3-opus-20240229"), | ||
description="You help people write movie scripts.", | ||
output_model=MovieScript, | ||
# debug_mode=True, | ||
) | ||
|
||
pprint(movie_assistant.run("New York")) |
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 @@ | ||
from rich.pretty import pprint | ||
from phi.agent import Agent | ||
from phi.model.openai import OpenAIChat | ||
from phi.tools.duckduckgo import DuckDuckGo | ||
|
||
agent = Agent( | ||
model=OpenAIChat(model="gpt-4o"), | ||
tools=[DuckDuckGo()], | ||
show_tool_calls=True, | ||
debug_mode=True, | ||
) | ||
agent.print_response("Whats happening in France?", markdown=True, stream=False) | ||
|
||
# response = agent.run("Whats happening in France?", markdown=True, stream=False) | ||
# | ||
# pprint(response) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from phi.model.anthropic.claude import Claude |
Oops, something went wrong.