Skip to content

Commit

Permalink
chore: refactor feed_expert and feed_prompt to enable filtering activ…
Browse files Browse the repository at this point in the history
…ities by type
  • Loading branch information
birdringxD committed Jul 24, 2024
1 parent a8c0cf7 commit b25600a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 37 deletions.
17 changes: 3 additions & 14 deletions src/openagent/agent/system_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,13 @@
"""

FEED_PROMPT = """
Based on the following wallet activities for {address}, please provide a detailed summary using markdown list format.
Focus on the most important and interesting aspects of these transactions.
Include relevant emojis to make the summary more engaging.
Here are the raw activities:
{activities_data}
Please organize your summary as follows:
1. A brief overview of the account's recent activity
2. A list of the most notable transactions, including:
- The type of transaction
- The tokens involved (if any)
- The amounts transferred
- Any interesting patterns or repeated actions
3. Any insights you can draw about the account holder's behavior or interests based on these activities
Remember to use markdown formatting and keep your tone friendly and informative.
- 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.
"""


Expand Down
36 changes: 13 additions & 23 deletions src/openagent/experts/feed_expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class ParamSchema(BaseModel):
hint: vitalik's address is vitalik.eth"""
)

type: str = Field(
description="""Retrieve activities for the specified type,
for example: all, post, comment, share."""
)


class FeedExpert(BaseTool):
name = "feed"
Expand All @@ -29,45 +34,30 @@ class FeedExpert(BaseTool):
def _run(
self,
address: str,
type: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
raise NotImplementedError

async def _arun(
self,
address: str,
type: str,
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
):
return await fetch_feeds(address)
return await fetch_feeds(address, type)


async def fetch_feeds(address: str):
url = f"""{settings.RSS3_DATA_API}/decentralized/{address}?limit=5&action_limit=10"""
async def fetch_feeds(address: str, type: str):
url = f"{settings.RSS3_DATA_API}/decentralized/{address}?limit=5&action_limit=10&tag=social"
if type != "all":
url += f"&type={type}"
headers = {"Accept": "application/json"}
async with aiohttp.ClientSession() as session:
logger.info(f"fetching {url}")
async with session.get(url, headers=headers) as resp:
data = await resp.json()

formatted_activities = []
for activity in data["data"]:
formatted_activity = f"## Transaction on {activity['network']}\n"
formatted_activity += f"- **Type**: {activity['type']}\n"
formatted_activity += f"- **Status**: {activity['status']}\n"
formatted_activity += f"- **Timestamp**: {activity['timestamp']}\n"

if "actions" in activity:
formatted_activity += "### Actions:\n"
for action in activity["actions"]:
formatted_activity += f"- {action['type']} from {action['from']} to {action['to']}\n"
if "metadata" in action:
for key, value in action["metadata"].items():
formatted_activity += f" - {key}: {value}\n"

formatted_activities.append(formatted_activity)

activities_data = "\n\n".join(formatted_activities)

result = FEED_PROMPT.format(address=address, activities_data=activities_data)
result = FEED_PROMPT.format(activities_data=data)

return result

0 comments on commit b25600a

Please sign in to comment.