-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add feed agent and dsl tool (#44)
- Loading branch information
Showing
4 changed files
with
54 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from phi.agent import Agent | ||
|
||
from openagent.tools import DSLTools | ||
|
||
feed_agent = Agent( | ||
name="Feed Agent", | ||
tools=[DSLTools()], | ||
) |
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,3 +1,4 @@ | ||
from .coingecko import CoinGeckoTools | ||
from .dsl import DSLTools | ||
|
||
__all__ = [CoinGeckoTools] | ||
__all__ = [CoinGeckoTools, DSLTools] |
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,42 @@ | ||
import requests | ||
from phi.tools import Toolkit | ||
|
||
|
||
class DSLTools(Toolkit): | ||
base_url = "https://gi.rss3.io" | ||
|
||
def __init__(self): | ||
super().__init__(name="dsl_tools") | ||
|
||
self.register(self.fetch_decentralized_feed) | ||
|
||
def fetch_decentralized_feed(self, address: str, type: str = "all") -> str: | ||
""" | ||
Fetch feed activities for a given address and activity type. | ||
Args: | ||
address (str): The wallet address or blockchain domain name to fetch activities for | ||
type (str): The type of activities to fetch (all, post, comment, share) | ||
Returns: | ||
A string containing the fetched activities formatted using FEED_PROMPT | ||
""" | ||
url = f"{self.base_url}/decentralized/{address}?limit=5&action_limit=10&tag=social" | ||
if type in ["post", "comment", "share"]: | ||
url += f"&type={type}" | ||
|
||
headers = {"Accept": "application/json"} | ||
data = requests.get(url, headers=headers).json() | ||
|
||
result = FEED_PROMPT.format(activities_data=data) | ||
return result | ||
|
||
|
||
FEED_PROMPT = """ | ||
Here are the raw activities: | ||
{activities_data} | ||
- Before answering, please first summarize how many actions the above activities have been carried out. | ||
- Display the key information in each operation, such as time, author, specific content, etc., and display this information in a markdown list format. | ||
- Finally, give a specific answer to the question. | ||
""" |