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.0.36 #44

Merged
merged 5 commits into from
Nov 10, 2023
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
1 change: 1 addition & 0 deletions phi/agent/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from phi.agent.agent import Agent
6 changes: 3 additions & 3 deletions phi/llm/agent/base.py → phi/agent/agent.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from collections import OrderedDict
from typing import Callable, Dict

from phi.llm.schemas import Function
from phi.tool.function import Function
from phi.utils.log import logger


class BaseAgent:
class Agent:
def __init__(self, name: str = "base_agent"):
self.name: str = name
self.functions: Dict[str, Function] = OrderedDict()
Expand All @@ -15,7 +15,7 @@ def register(self, function: Callable):
f = Function.from_callable(function)
self.functions[f.name] = f
logger.debug(f"Function: {f.name} registered with {self.name}")
logger.debug(f"Json Schema: {f.to_dict()}")
# logger.debug(f"Json Schema: {f.to_dict()}")
except Exception as e:
logger.warning(f"Failed to create Function for: {function.__name__}")
raise e
Expand Down
4 changes: 2 additions & 2 deletions phi/llm/agent/arxiv.py → phi/agent/arxiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

from phi.document import Document
from phi.knowledge.arxiv import ArxivKnowledgeBase
from phi.llm.agent.base import BaseAgent
from phi.agent import Agent
from phi.utils.log import logger


class ArxivAgent(BaseAgent):
class ArxivAgent(Agent):
def __init__(self, knowledge_base: Optional[ArxivKnowledgeBase] = None):
super().__init__(name="arxiv_agent")
self.knowledge_base: Optional[ArxivKnowledgeBase] = knowledge_base
Expand Down
12 changes: 6 additions & 6 deletions phi/assistant/tool/duckdb.py → phi/agent/duckdb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional, Tuple

from phi.assistant.tool.registry import ToolRegistry
from phi.agent import Agent
from phi.utils.log import logger

try:
Expand All @@ -9,14 +9,14 @@
raise ImportError("`duckdb` not installed. Please install it using `pip install duckdb`.")


class DuckDbTools(ToolRegistry):
class DuckDbAgent(Agent):
def __init__(
self,
db_path: str = ":memory:",
s3_region: str = "us-east-1",
duckdb_connection: Optional[duckdb.DuckDBPyConnection] = None,
):
super().__init__(name="duckdb_tools")
super().__init__(name="duckdb_agent")

self.db_path: str = db_path
self.s3_region: str = s3_region
Expand Down Expand Up @@ -329,9 +329,9 @@ def full_text_search(self, table_name: str, unique_key: str, search_text: str) -
"""
logger.debug(f"Running full_text_search for {search_text} in {table_name}")
search_text_statement = f"""SELECT fts_main_corpus.match_bm25({unique_key}, '{search_text}') AS score,*
FROM {table_name}
WHERE score IS NOT NULL
ORDER BY score;"""
FROM {table_name}
WHERE score IS NOT NULL
ORDER BY score;"""

logger.debug(f"Running {search_text_statement}")
result = self.run_query(search_text_statement)
Expand Down
4 changes: 2 additions & 2 deletions phi/llm/agent/email.py → phi/agent/email.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Optional

from phi.llm.agent.base import BaseAgent
from phi.agent import Agent
from phi.utils.log import logger


class EmailAgent(BaseAgent):
class EmailAgent(Agent):
def __init__(
self,
receiver_email: Optional[str] = None,
Expand Down
4 changes: 2 additions & 2 deletions phi/llm/agent/google.py → phi/agent/google.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from phi.llm.agent.base import BaseAgent
from phi.agent import Agent
from phi.utils.log import logger


class GoogleAgent(BaseAgent):
class GoogleAgent(Agent):
def __init__(self):
super().__init__(name="google_agent")
self.register(self.get_result_from_google)
Expand Down
4 changes: 2 additions & 2 deletions phi/llm/agent/phi.py → phi/agent/phi.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import uuid
from typing import Optional

from phi.llm.agent.base import BaseAgent
from phi.agent import Agent
from phi.utils.log import logger


class PhiAgent(BaseAgent):
class PhiAgent(Agent):
def __init__(self):
super().__init__(name="phi_agent")
self.register(self.create_new_app)
Expand Down
4 changes: 2 additions & 2 deletions phi/llm/agent/pubmed.py → phi/agent/pubmed.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from phi.llm.agent.base import BaseAgent
from phi.agent import Agent
from phi.utils.log import logger


class PubMedAgent(BaseAgent):
class PubMedAgent(Agent):
def __init__(self):
super().__init__(name="pubmed_agent")
self.register(self.get_articles_from_pubmed)
Expand Down
4 changes: 2 additions & 2 deletions phi/llm/agent/shell.py → phi/agent/shell.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import List

from phi.llm.agent.base import BaseAgent
from phi.agent import Agent
from phi.utils.log import logger


class ShellAgent(BaseAgent):
class ShellAgent(Agent):
def __init__(self):
super().__init__(name="shell_agent")
self.register(self.run_shell_command)
Expand Down
6 changes: 3 additions & 3 deletions phi/assistant/tool/website.py → phi/agent/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

from phi.document import Document
from phi.knowledge.website import WebsiteKnowledgeBase
from phi.assistant.tool.registry import ToolRegistry
from phi.agent import Agent
from phi.utils.log import logger


class WebsiteTools(ToolRegistry):
class WebsiteAgent(Agent):
def __init__(self, knowledge_base: Optional[WebsiteKnowledgeBase] = None):
super().__init__(name="website_tools")
super().__init__(name="website_agent")
self.knowledge_base: Optional[WebsiteKnowledgeBase] = knowledge_base

if self.knowledge_base is not None and isinstance(self.knowledge_base, WebsiteKnowledgeBase):
Expand Down
4 changes: 2 additions & 2 deletions phi/llm/agent/wikipedia.py → phi/agent/wikipedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

from phi.document import Document
from phi.knowledge.wikipedia import WikipediaKnowledgeBase
from phi.llm.agent.base import BaseAgent
from phi.agent import Agent
from phi.utils.log import logger


class WikipediaAgent(BaseAgent):
class WikipediaAgent(Agent):
def __init__(self, knowledge_base: Optional[WikipediaKnowledgeBase] = None):
super().__init__(name="wikipedia_agent")
self.knowledge_base: Optional[WikipediaKnowledgeBase] = knowledge_base
Expand Down
13 changes: 7 additions & 6 deletions phi/ai/phi_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
from phi.cli.config import PhiCliConfig
from phi.cli.console import console
from phi.cli.settings import phi_cli_settings
from phi.llm.schemas import Function, Message, FunctionCall
from phi.llm.function.shell import ShellScriptsRegistry
from phi.llm.function.phi_commands import PhiCommandsRegistry
from phi.llm.message import Message
from phi.tool.function import Function, FunctionCall
from phi.agent.shell import ShellAgent
from phi.agent.phi import PhiAgent
from phi.workspace.config import WorkspaceConfig
from phi.utils.log import logger
from phi.utils.functions import get_function_call
Expand All @@ -41,7 +42,7 @@ def __init__(
_active_workspace = _phi_config.get_active_ws_config()

self.conversation_db: Optional[List[Dict[str, Any]]] = None
self.functions: Dict[str, Function] = {**ShellScriptsRegistry().functions, **PhiCommandsRegistry().functions}
self.functions: Dict[str, Function] = {**ShellAgent().functions, **PhiAgent().functions}

_conversation_id = None
_conversation_history = None
Expand Down Expand Up @@ -170,7 +171,7 @@ def run_function_stream(self, function_call: Dict[str, Any]) -> Iterator[str]:
yield f"Running: {function_call_obj.get_call_str()}\n\n"
function_call_timer = Timer()
function_call_timer.start()
function_call_obj.run()
function_call_obj.execute()
function_call_timer.stop()
function_call_message = Message(
role="function",
Expand Down Expand Up @@ -213,7 +214,7 @@ def run_function(self, function_call: Dict[str, Any]) -> str:
function_run_response = f"Running: {function_call_obj.get_call_str()}\n\n"
function_call_timer = Timer()
function_call_timer.start()
function_call_obj.run()
function_call_obj.execute()
function_call_timer.stop()
function_call_message = Message(
role="function",
Expand Down
3 changes: 2 additions & 1 deletion phi/api/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
ConversationCreateResponse,
)
from phi.api.schemas.user import UserSchema
from phi.llm.schemas import Function, Message
from phi.llm.message import Message
from phi.tool.function import Function
from phi.utils.log import logger


Expand Down
Loading