Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tools): Add X(twitter) tool #12026

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(tools): implement X Twitter tools
  • Loading branch information
Yash-1511 committed Dec 23, 2024
commit f66d90aa170417700b33bc723dbad46c224ff278
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
Loading