Skip to content

Commit

Permalink
v2.3.69
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Apr 17, 2024
1 parent 86b4abc commit 0d1753e
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 75 deletions.
16 changes: 16 additions & 0 deletions cookbook/assistants/research.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from phi.assistant import Assistant
from phi.tools.duckduckgo import DuckDuckGo
from phi.tools.newspaper4k import Newspaper4k

assistant = Assistant(
tools=[DuckDuckGo(), Newspaper4k()],
show_tool_calls=True,
description="You are a senior NYT researcher writing an article on a topic.",
instructions=[
"For the provided topic, search for the top 3 links.",
"Then read each URL and extract the article text. If a URL isn't available, ignore and move on.",
"Analyse and prepare an NYT worthy article based on the information.",
],
add_datetime_to_instructions=True,
)
assistant.print_response("Latest developments in AI", markdown=True)
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pandas==2.2.2
# via
# altair
# streamlit
phidata==2.3.67
phidata==2.3.68
# via -r cookbook/integrations/integrations/singlestore/auto_rag/requirements.in
pillow==10.3.0
# via streamlit
Expand Down
12 changes: 0 additions & 12 deletions cookbook/llms/gemini/resources.py

This file was deleted.

14 changes: 0 additions & 14 deletions cookbook/llms/groq/resources.py

This file was deleted.

10 changes: 0 additions & 10 deletions cookbook/llms/hermes2/auto_rag/resources.py

This file was deleted.

12 changes: 0 additions & 12 deletions cookbook/llms/mistral/resources.py

This file was deleted.

5 changes: 2 additions & 3 deletions phi/assistant/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class Assistant(BaseModel):
team: Optional[List["Assistant"]] = None
# When the assistant is part of a team, this is the role of the assistant in the team
role: Optional[str] = None
# Add instructions for delegating tasks to another assistant
# Add instructions for delegating tasks to another assistants
add_delegation_instructions: bool = True

# debug_mode=True enables debug logs
Expand Down Expand Up @@ -624,8 +624,7 @@ def run(
return self.output or json_resp
else:
if stream and self.streamable:
resp = self._run(message=message, stream=True, **kwargs)
return resp
yield from self._run(message=message, stream=True, **kwargs)
else:
resp = self._run(message=message, stream=False, **kwargs)
return next(resp)
Expand Down
15 changes: 9 additions & 6 deletions phi/tools/duckduckgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
class DuckDuckGo(Toolkit):
def __init__(
self,
ddgs: Optional[Any] = None,
headers: Optional[Any] = None,
proxy: Optional[str] = None,
proxies: Optional[Any] = None,
timeout: Optional[int] = 10,
search: bool = True,
news: bool = True,
):
super().__init__(name="duckduckgo")

self.ddgs = ddgs or DDGS(headers=headers, proxies=proxies, timeout=timeout)
self.headers: Optional[Any] = headers
self.proxy: Optional[str] = proxy
self.proxies: Optional[Any] = proxies
self.timeout: Optional[int] = timeout
if search:
self.register(self.duckduckgo_search)
if news:
Expand All @@ -39,8 +42,8 @@ def duckduckgo_search(self, query: str, max_results: int = 5) -> str:
The result from DuckDuckGo.
"""
logger.debug(f"Searching DDG for: {query}")
results = [r for r in self.ddgs.text(keywords=query, max_results=max_results)]
return json.dumps(results, indent=2)
ddgs = DDGS(headers=self.headers, proxy=self.proxy, proxies=self.proxies, timeout=self.timeout)
return json.dumps(ddgs.text(keywords=query, max_results=max_results), indent=2)

def duckduckgo_news(self, query: str, max_results: int = 5) -> str:
"""Use this function to get the latest news from DuckDuckGo.
Expand All @@ -53,5 +56,5 @@ def duckduckgo_news(self, query: str, max_results: int = 5) -> str:
The latest news from DuckDuckGo.
"""
logger.debug(f"Searching DDG news for: {query}")
results = [r for r in self.ddgs.news(keywords=query, max_results=max_results)]
return json.dumps(results, indent=2)
ddgs = DDGS(headers=self.headers, proxy=self.proxy, proxies=self.proxies, timeout=self.timeout)
return json.dumps(ddgs.news(keywords=query, max_results=max_results), indent=2)
52 changes: 52 additions & 0 deletions phi/tools/newspaper4k.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import json
from phi.tools import Toolkit

try:
import newspaper
except ImportError:
raise ImportError("`newspaper4k` not installed. Please run `pip install newspaper4k lxml_html_clean`.")


class Newspaper4k(Toolkit):
def __init__(
self,
read_article: bool = True,
include_summary: bool = False,
):
super().__init__(name="newspaper_toolkit")

self.include_summary: bool = include_summary
if read_article:
self.register(self.read_article)

def read_article(self, url: str) -> str:
"""Get the article information from a URL.
Args:
url (str): The URL of the article.
Returns:
str: JSON containing the article author, publish date, and text.
"""

try:
article = newspaper.article(url)
article_data = {}
if article.title:
article_data["title"] = article.title
if article.authors:
article_data["authors"] = article.authors
if article.text:
article_data["text"] = article.text
if self.include_summary and article.summary:
article_data["summary"] = article.summary

try:
if article.publish_date:
article_data["publish_date"] = article.publish_date.isoformat() if article.publish_date else None
except Exception:
pass

return json.dumps(article_data, indent=2)
except Exception as e:
return f"Error reading article from {url}: {e}"
2 changes: 1 addition & 1 deletion phi/tools/newspaper_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
try:
from newspaper import Article
except ImportError:
raise ImportError("`newspaper4k` not installed.")
raise ImportError("`newspaper3k` not installed. Please run `pip install newspaper3k lxml_html_clean`.")


class NewspaperToolkit(Toolkit):
Expand Down
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
[project]
name = "phidata"
version = "2.3.68"
description = "Build AI Assistants using function calling"
version = "2.3.69"
description = "Build AI Assistants with memory, knowledge and tools."
requires-python = ">=3.8"
readme = "README.md"
authors = [
{name = "Ashpreet Bedi", email = "[email protected]"}
]

dependencies = [
"boto3",
"botocore",
"docker",
"gitpython",
"httpx",
"pydantic",
Expand Down
11 changes: 0 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,27 @@
#
annotated-types==0.6.0
anyio==4.3.0
boto3==1.34.83
botocore==1.34.83
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.1.7
docker==7.0.0
exceptiongroup==1.2.0
gitdb==4.0.11
gitpython==3.1.43
h11==0.14.0
httpcore==1.0.5
httpx==0.27.0
idna==3.7
jmespath==1.0.1
markdown-it-py==3.0.0
mdurl==0.1.2
packaging==24.0
pydantic==2.7.0
pydantic-core==2.18.1
pydantic-settings==2.2.1
pygments==2.17.2
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
pyyaml==6.0.1
requests==2.31.0
rich==13.7.1
s3transfer==0.10.1
shellingham==1.5.4
six==1.16.0
smmap==5.0.1
sniffio==1.3.1
tomli==2.0.1
typer==0.12.3
typing-extensions==4.11.0
urllib3==1.26.18

0 comments on commit 0d1753e

Please sign in to comment.