Skip to content

Commit

Permalink
feat(tools): implement X Twitter tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash-1511 committed Dec 23, 2024
1 parent 6d1cb4a commit f66d90a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions api/core/tools/provider/builtin/x/tools/get_user_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _convert_tweet_to_dict(self, tweet: tweepy.Tweet) -> dict[str, Any]:
"""
tweet_dict = {}
# Convert Tweet object to dictionary
for field in tweet.data.keys():
for field in tweet.data:
value = tweet.data[field]
# Skip None values
if value is None:
Expand Down Expand Up @@ -166,7 +166,7 @@ def _invoke(

# Convert user data
user_dict = {}
for field in user_data.keys():
for field in user_data:
value = user_data[field]
if value is None:
continue
Expand Down
6 changes: 3 additions & 3 deletions api/core/tools/provider/builtin/x/tools/like_tweet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Like Tweet Tool for liking/unliking tweets
"""

from typing import Any, Dict, List, Union
from typing import Any, Union

import tweepy

Expand All @@ -12,8 +12,8 @@

class LikeTweetTool(BuiltinTool):
def _invoke(
self, user_id: str, tool_parameters: Dict[str, Any]
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
self, user_id: str, tool_parameters: dict[str, Any]
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
"""
Like or unlike a tweet
Expand Down
8 changes: 4 additions & 4 deletions api/core/tools/provider/builtin/x/tools/media_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import io
from typing import Any, Dict, List, Union
from typing import Any, Union

import tweepy

Expand All @@ -14,7 +14,7 @@


class MediaUploadTool(BuiltinTool):
def _get_twitter_api_v1(self, credentials: Dict[str, str]) -> tweepy.API:
def _get_twitter_api_v1(self, credentials: dict[str, str]) -> tweepy.API:
"""
Get Twitter API v1.1 connection for media upload
"""
Expand All @@ -33,8 +33,8 @@ def _validate_file_type(self, file_type: FileType) -> bool:
return file_type in [FileType.IMAGE, FileType.VIDEO]

def _invoke(
self, user_id: str, tool_parameters: Dict[str, Any]
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
self, user_id: str, tool_parameters: dict[str, Any]
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
"""
Upload media to Twitter
"""
Expand Down

0 comments on commit f66d90a

Please sign in to comment.