-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
second pass implementing post text to twitter
- Loading branch information
Showing
12 changed files
with
158 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from cdp_agentkit_core.actions.social.twitter.post_text import ( | ||
POST_TEXT_PROMPT as POST_TEXT_PROMPT, | ||
) | ||
from cdp_agentkit_core.actions.social.twitter.post_text import ( | ||
PostTextInput as PostTextInput, | ||
) | ||
from cdp_agentkit_core.actions.social.twitter.post_text import ( | ||
post_text as post_text, | ||
) |
23 changes: 8 additions & 15 deletions
23
cdp-agentkit-core/cdp_agentkit_core/actions/social/twitter/post_text.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,34 @@ | ||
from typing import Any | ||
import tweepy | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
TWITTER_POST_TEXT_PROMPT = """ | ||
This tool will post a text on Twitter.""" | ||
POST_TEXT_PROMPT = """ | ||
This tool will post text on Twitter.""" | ||
|
||
class TwitterPostTextInput(BaseModel): | ||
class PostTextInput(BaseModel): | ||
"""Input argument schema for twitter post text actions.""" | ||
|
||
client: Any = Field( | ||
..., | ||
description="The tweepy client used to interface with the Twitter API", | ||
) | ||
|
||
text: str = Field( | ||
..., | ||
description="The text to post to twitter", | ||
) | ||
|
||
def twitter_post_text(client: tweepy.Client, text: str) -> str: | ||
def post_text(client: tweepy.Client, text: str) -> str: | ||
"""Post text to Twitter. | ||
Args: | ||
client (tweepy.Client): The tweepy client to use. | ||
text (str): The text to post. | ||
Returns: | ||
str: A text containing the result of the post text to twitter response. | ||
""" | ||
|
||
message = "" | ||
|
||
try: | ||
client.create_tweet(text=text) | ||
message = f"Successfully posted!" | ||
except tweepy.error.TweepError as e: | ||
message = "Successfully posted!" | ||
except tweepy.errors.TweepyException as e: | ||
message = f"Error posting: {e}" | ||
|
||
return text | ||
return message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.PHONY: format | ||
format: | ||
ruff format . | ||
|
||
.PHONY: lint | ||
lint: | ||
ruff check . | ||
|
||
.PHONY: lint-fix | ||
lint-fix: | ||
ruff check . --fix | ||
|
||
.PHONY: docs | ||
docs: | ||
sphinx-apidoc -f -o ./docs ./cdp_langchain | ||
|
||
.PHONY: local-docs | ||
local-docs: docs | ||
cd docs && make html && open ./_build/html/index.html | ||
|
||
.PHONY: test | ||
test: | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,65 @@ | ||
# Twitter (X) Langchain Toolkit | ||
|
||
## Developing | ||
- `cdp-sdk` has a dependency on `cargo`, please install rust and add `cargo` to your path | ||
- [Rust Installation Instructions](https://doc.rust-lang.org/cargo/getting-started/installation.html) | ||
- `export PATH="$HOME/.cargo/bin:$PATH"` | ||
- Agentkit uses `poetry` for package management and tooling | ||
- [Poetry Installation Instructions](https://python-poetry.org/docs/#installation) | ||
- Run `poetry install` to install `cdp-langchain` dependencies | ||
- Run `poetry shell` to activate the virtual environment | ||
|
||
## Documentation | ||
- [Agentkit-Core](https://coinbase.github.io/cdp-agentkit-core) | ||
- [Agentkit-Langchain](https://coinbase.github.io/cdp-langchain) | ||
- [Agentkit-Twitter-Langchain](https://coinbase.github.io/twitter-langchain) | ||
|
||
### Formatting | ||
`make format` | ||
|
||
### Linting | ||
- Check linter | ||
`make lint` | ||
|
||
- Fix linter errors | ||
`make lint-fix` | ||
|
||
## Adding an Agentic Action to the Langchain Toolkit | ||
1. Ensure the action is implemented in `cdp-agentkit-core`. | ||
2. Add a wrapper method to `TwitterApiWrapper` in `./twitter_langchain/twitter_api_wrapper.py` | ||
- E.g. | ||
```python | ||
def post_text_wrapper(self, text: str) -> str: | ||
"""Post text to Twitter. | ||
Args: | ||
text (str): The text to post. | ||
Returns: | ||
str: A text containing the result of the post text to twitter response. | ||
""" | ||
return post_text(client=self.client, text=text) | ||
``` | ||
3. Add call to the wrapper in `TwitterApiWrapper.run` in `./twitter_langchain/twitter_api_wrapper.py` | ||
- E.g. | ||
```python | ||
if mode == "post_text": | ||
return self.post_text_wrapper(**kwargs) | ||
|
||
``` | ||
4. Add the action to the list of available tools in the `TwitterToolkit` in `./twitter_langchain/twitter_toolkit.py` | ||
- E.g. | ||
```python | ||
actions: List[Dict] = [ | ||
{ | ||
"mode": "post_text", | ||
"name": "post_text", | ||
"description": POST_TEXT_PROMPT, | ||
"args_schema": PostTextInput, | ||
}, | ||
] | ||
``` | ||
5. Update `TwitterToolkit` documentation | ||
- Add the action to the list of tools | ||
- Add any additional ENV requirements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.