From b25600a29b08d0954ddadf87135e86ed995f6f81 Mon Sep 17 00:00:00 2001 From: birdringxD Date: Wed, 24 Jul 2024 17:45:04 +0800 Subject: [PATCH] chore: refactor feed_expert and feed_prompt to enable filtering activities by type --- src/openagent/agent/system_prompt.py | 17 +++---------- src/openagent/experts/feed_expert.py | 36 ++++++++++------------------ 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/src/openagent/agent/system_prompt.py b/src/openagent/agent/system_prompt.py index edd198ca..7cf65993 100644 --- a/src/openagent/agent/system_prompt.py +++ b/src/openagent/agent/system_prompt.py @@ -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. """ diff --git a/src/openagent/experts/feed_expert.py b/src/openagent/experts/feed_expert.py index 63f9ae87..cf750479 100644 --- a/src/openagent/experts/feed_expert.py +++ b/src/openagent/experts/feed_expert.py @@ -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" @@ -29,6 +34,7 @@ class FeedExpert(BaseTool): def _run( self, address: str, + type: str, run_manager: Optional[CallbackManagerForToolRun] = None, ) -> str: raise NotImplementedError @@ -36,38 +42,22 @@ def _run( 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