-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add lookup_tweet_by_id
to X Toolkit
#165
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
toolkits/x/.pre-commit-config.yaml
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this file be at the root? (I don't think it has any effect when it's deep in a dir path like this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
helps with make check
from the toolkit's root
toolkits/x/Makefile
Outdated
.PHONY: clean-build | ||
clean-build: ## clean build artifacts | ||
rm -rf dist | ||
|
||
.PHONY: clean-dist | ||
clean-dist: ## Clean all built distributions | ||
@echo "🗑️ Cleaning dist directory" | ||
@rm -rf dist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 2 seem duplicative?
toolkits/x/pyproject.toml
Outdated
@@ -1,17 +1,43 @@ | |||
[tool.poetry] | |||
name = "arcade_x" | |||
version = "0.1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to bump this to 0.1.3
at least (0.1.2 is the current release on pypi)
toolkits/x/arcade_x/tools/tweets.py
Outdated
if response.status_code != 201: | ||
raise ToolExecutionError( | ||
f"Failed to post a tweet during execution of '{post_tweet.__name__}' tool. Request returned an error: {response.status_code} {response.text}" | ||
error_message = response.text | ||
raise ToolExecutionError( # noqa: TRY003 | ||
"Error posting tweet", | ||
developer_message=f"Twitter API Error: {response.status_code} {error_message}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have started simply doing response.raise_for_status()
which raises an exception that is caught and turned into a ToolExecutionError
by the ToolExecutor. Let's discuss which pattern we want to use.
raise RetryableToolError( # noqa: TRY003 | ||
"No keywords or phrases provided", | ||
developer_message="Predicted inputs didn't contain any keywords or phrases", | ||
additional_prompt_content="Please provide at least one keyword or phrase for search", | ||
retry_after_ms=500, # Play nice with X API rate limits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
toolkits/x/arcade_x/tools/users.py
Outdated
except httpx.HTTPError as e: | ||
raise ToolExecutionError( # noqa: TRY003 | ||
"Network error during user lookup", | ||
developer_message=str(e), | ||
) from e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be caught by ToolExecutor (one level up)
toolkits/x/pyproject.toml
Outdated
pre-commit = "^3.4.0" | ||
tox = "^4.11.1" | ||
ruff = "^0.7.4" | ||
arcade-ai = {version = "0.1.*", extras = ["fastapi", "evals"]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extras should not be required (let's discuss)
toolkits/x/evals/eval_x_tools.py
Outdated
"keywords": ["Arcade AI"], | ||
"phrases": [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expected keyword & phrases should be flipped. Keywords should be list of tokenized words.
Looking back on the search_recent_tweets_by_keywords
implementation, I think the keywords and phrases input params can be handled better. The evals seem be to telling us that the LM has difficulty deciphering between the differences of keywords and phrases.
"Arcade-AI is the go-to startup"
as keywords: ["Arcade", "AI", "is", "the", "go", "to", "startup"]
as phrase: ["Arcade-AI is the go-to startup"]
|
||
def get_tweet_url(tweet_id: str) -> str: | ||
"""Get the URL of a tweet given its ID.""" | ||
return f"https://x.com/x/status/{tweet_id}" | ||
|
||
|
||
def parse_search_recent_tweets_response(response_data: Any) -> dict: | ||
def get_headers_with_token(context: ToolContext) -> dict[str, str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So altering dict
in-place is not idiomatic?
url = f"https://api.x.com/2/users/by/username/{username}?user.fields=created_at,description,id,location,most_recent_tweet_id,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,verified_type,withheld,entities" | ||
headers = get_headers_with_token(context) | ||
|
||
user_fields = ",".join([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
much cleaner
toolkits/x/arcade_x/tools/users.py
Outdated
|
||
async with httpx.AsyncClient() as client: | ||
response = await client.get(url, headers=headers, timeout=10) | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the update to error handling for tools I've been avoiding try/catch wrapped around API calls.
@echo "🚀 Bumping version in pyproject.toml" | ||
poetry version patch | ||
|
||
.PHONY: check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make check
doesn't pass the mypy portion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scratch that. after make install
all is well
arcade/arcade/py.typed
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this help with the "unfollowed import" mypy error?
This PR introduces the
lookup_tweet_by_id
tool to the X toolkit, enabling users to retrieve tweet details by tweet ID. This enhancement extends the toolkit's capabilities, allowing for more comprehensive interactions with the X (Twitter) API.Key Changes:
Added
lookup_tweet_by_id
Tool:lookup_tweet_by_id
function intools/tweets.py
, which allows users to fetch tweet information using a tweet ID.Enhanced Toolkit Structure:
arcade new
. These include:.pre-commit-config.yaml
: Defines pre-commit hooks for code quality checks..ruff.toml
: Configuration for the Ruff linter.LICENSE
: MIT License file for the toolkit.Makefile
: Contains common commands for building, testing, and linting the toolkit.Updated Makefile:
make check-toolkits
command to the top-levelMakefile
. This command runs code quality tools for each toolkit that contains aMakefile
.Additional Notes:
Tests:
lookup_tweet_by_id
tool intests/test_tweets.py
.tests/test_users.py
.Linting and Code Quality:
pyproject.toml
file with development dependencies for testing and linting.