-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
1 parent
cd5a344
commit b01a803
Showing
35 changed files
with
938 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from phi.agent.agent import Agent |
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,27 @@ | ||
from collections import OrderedDict | ||
from typing import Callable, Dict | ||
|
||
from phi.tool.function import Function | ||
from phi.utils.log import logger | ||
|
||
|
||
class Agent: | ||
def __init__(self, name: str = "base_agent"): | ||
self.name: str = name | ||
self.functions: Dict[str, Function] = OrderedDict() | ||
|
||
def register(self, function: Callable): | ||
try: | ||
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()}") | ||
except Exception as e: | ||
logger.warning(f"Failed to create Function for: {function.__name__}") | ||
raise e | ||
|
||
def __repr__(self): | ||
return f"<{self.__class__.__name__} name={self.name} functions={list(self.functions.keys())}>" | ||
|
||
def __str__(self): | ||
return self.__repr__() |
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
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 phi.agent import Agent | ||
from phi.utils.log import logger | ||
|
||
|
||
class GoogleAgent(Agent): | ||
def __init__(self): | ||
super().__init__(name="google_agent") | ||
self.register(self.get_result_from_google) | ||
|
||
def get_result_from_google(self, query: str) -> str: | ||
"""Gets the result for a query from Google. | ||
Use this function to find an answer when not available in the knowledge base. | ||
:param query: The query to search for. | ||
:return: The result from Google. | ||
""" | ||
logger.info(f"Searching google for: {query}") | ||
return "Sorry, this capability is not available yet." |
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,19 @@ | ||
from phi.agent import Agent | ||
from phi.utils.log import logger | ||
|
||
|
||
class PubMedAgent(Agent): | ||
def __init__(self): | ||
super().__init__(name="pubmed_agent") | ||
self.register(self.get_articles_from_pubmed) | ||
|
||
def get_articles_from_pubmed(self, query: str, num_articles: int = 2) -> str: | ||
"""Gets the abstract for articles related to a query from PubMed: a database of biomedical literature | ||
Use this function to find information about a medical concept when not available in the knowledge base or Google | ||
:param query: The query to get related articles for. | ||
:param num_articles: The number of articles to return. | ||
:return: JSON string containing the articles | ||
""" | ||
logger.info(f"Searching Pubmed for: {query}") | ||
return "Sorry, this capability is not available yet." |
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
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.