forked from phidatahq/phidata
-
Notifications
You must be signed in to change notification settings - Fork 0
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
29 changed files
with
391 additions
and
140 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
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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
from phi.assistant import Assistant | ||
from phi.tools.duckduckgo import DuckDuckGo | ||
|
||
assistant = Assistant(tools=[DuckDuckGo()], show_tool_calls=True, read_chat_history=True) | ||
assistant = Assistant( | ||
tools=[DuckDuckGo()], | ||
show_tool_calls=True, | ||
read_chat_history=True, | ||
debug_mode=True, | ||
add_chat_history_to_messages=True, | ||
num_history_messages=3, | ||
) | ||
assistant.cli_app(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
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,46 @@ | ||
# Inspired by: https://github.com/anthropics/anthropic-cookbook/blob/main/misc/prompt_caching.ipynb | ||
import requests | ||
from bs4 import BeautifulSoup | ||
|
||
from phi.assistant import Assistant | ||
from phi.llm.anthropic import Claude | ||
|
||
|
||
def fetch_article_content(url): | ||
response = requests.get(url) | ||
soup = BeautifulSoup(response.content, "html.parser") | ||
# Remove script and style elements | ||
for script in soup(["script", "style"]): | ||
script.decompose() | ||
# Get text | ||
text = soup.get_text() | ||
# Break into lines and remove leading and trailing space on each | ||
lines = (line.strip() for line in text.splitlines()) | ||
# Break multi-headlines into a line each | ||
chunks = (phrase.strip() for line in lines for phrase in line.split(" ")) | ||
# Drop blank lines | ||
text = "\n".join(chunk for chunk in chunks if chunk) | ||
return text | ||
|
||
|
||
# Fetch the content of the article | ||
book_url = "https://www.gutenberg.org/cache/epub/1342/pg1342.txt" | ||
book_content = fetch_article_content(book_url) | ||
|
||
print(f"Fetched {len(book_content)} characters from the book.") | ||
|
||
assistant = Assistant( | ||
llm=Claude( | ||
model="claude-3-5-sonnet-20240620", | ||
cache_system_prompt=True, | ||
), | ||
system_prompt=book_content[:10000], | ||
debug_mode=True, | ||
) | ||
assistant.print_response("Give me a one line summary of this book", markdown=True, stream=True) | ||
print("Prompt cache creation tokens: ", assistant.llm.metrics["cache_creation_tokens"]) # type: ignore | ||
print("Prompt cache read tokens: ", assistant.llm.metrics["cache_read_tokens"]) # type: ignore | ||
|
||
# assistant.print_response("Give me a one line summary of this book", markdown=True, stream=False) | ||
# print("Prompt cache creation tokens: ", assistant.llm.metrics["cache_creation_tokens"]) | ||
# print("Prompt cache read tokens: ", assistant.llm.metrics["cache_read_tokens"]) |
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,34 @@ | ||
## DeepSeek | ||
|
||
> Note: Fork and clone this repository if needed | ||
1. Create a virtual environment | ||
|
||
```shell | ||
python3 -m venv venv | ||
source venv/bin/activate | ||
``` | ||
|
||
2. Install libraries | ||
|
||
```shell | ||
pip install -U openai phidata | ||
``` | ||
|
||
3. Export `DEEPSEEK_API_KEY` | ||
|
||
```shell | ||
export DEEPSEEK_API_KEY=*** | ||
``` | ||
|
||
4. Test Structured output | ||
|
||
```shell | ||
python cookbook/llms/deepseek/pydantic_output.py | ||
``` | ||
|
||
5. Test function calling | ||
|
||
```shell | ||
python cookbook/llms/deepseek/tool_call.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,20 @@ | ||
from phi.assistant import Assistant | ||
from phi.llm.deepseek import DeepSeekChat | ||
from phi.tools.yfinance import YFinanceTools | ||
from pydantic import BaseModel, Field | ||
|
||
|
||
class StockPrice(BaseModel): | ||
ticker: str = Field(..., example="NVDA") | ||
price: float = Field(..., example=100.0) | ||
currency: str = Field(..., example="USD") | ||
|
||
|
||
assistant = Assistant( | ||
llm=DeepSeekChat(), | ||
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)], | ||
show_tool_calls=True, | ||
markdown=True, | ||
output_model=StockPrice, | ||
) | ||
assistant.print_response("Write a comparison between NVDA and AMD.") |
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,11 @@ | ||
from phi.assistant import Assistant | ||
from phi.llm.deepseek import DeepSeekChat | ||
from phi.tools.yfinance import YFinanceTools | ||
|
||
assistant = Assistant( | ||
llm=DeepSeekChat(), | ||
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)], | ||
show_tool_calls=True, | ||
markdown=True, | ||
) | ||
assistant.print_response("Write a comparison between NVDA and AMD, use all tools available.") |
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 |
---|---|---|
|
@@ -9,3 +9,6 @@ streamlit | |
bs4 | ||
duckduckgo-search | ||
nest_asyncio | ||
textract==1.6.3 | ||
python-docx | ||
lxml |
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 |
---|---|---|
@@ -1,5 +1,13 @@ | ||
# pip install firecrawl-py openai | ||
|
||
import os | ||
|
||
from phi.assistant import Assistant | ||
from phi.tools.firecrawl import FirecrawlTools | ||
|
||
assistant = Assistant(tools=[FirecrawlTools()], show_tool_calls=True, markdown=True) | ||
assistant.print_response("Tell me about https://github.com/phidatahq/phidata") | ||
api_key = os.getenv("FIRECRAWL_API_KEY") | ||
|
||
assistant = Assistant( | ||
tools=[FirecrawlTools(api_key=api_key, scrape=False, crawl=True)], show_tool_calls=True, markdown=True | ||
) | ||
assistant.print_response("summarize this https://finance.yahoo.com/") |
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
Oops, something went wrong.