We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

42
1.759.504,10

Cart

Quantity 8.950,00
Quantity 18,00
Quantity 123.090,00

AutoGPT plugins can improve the capability of Auto GPT and tailor the functions to our own need, which can improve its operation and offer new features. AutoGPT plugins that customizes the behavior of the GPT system to meet specific needs or requirements. In this article, we will look at how to create AutoGPT plugins and the advantages they may provide to users.

How to create AutoGPT plugins

You can also read How to install AutoGPT plugins.

Download or clone the plugin repository: Clone the plugin repository or get it in zip format.

AutoGPT Plugins

Install any dependencies for the plugin: In your terminal, navigate to the plugin’s folder and run the following command to install any needed dependencies:

   pip install -r requirements.txt

Package the plugin as a Zip file: If you cloned the repository, zip the plugin folder.

Copy the Zip file containing the plugin: Place the plugin’s Zip file in the Auto-GPT repository’s plugins folder.

Allow the plugin to be listed (optional): To prevent being presented with a warning while loading the plugin, add the plugin’s class name to the ALLOWLISTED_PLUGINS in the .env file:

ALLOWLISTED_PLUGINS=example-plugin1,example-plugin2,example-plugin3

If the plugin is not allowlisted, you will be warned before it’s loaded.

To create AutoGPT plugins for Twitter

A plugin that integrates the Twitter API with Auto GPT.

Now, in this article, we create a Twitter AutoGPT plugins that helps you to tweet within Auto GPT. Please find more about this in Github.

Feature: Post a tweet using the post_tweet(tweet) command

Create your AutoGPT plugin

  1. As directed in the main repository, clone this repo.
  2. Include the following code in the .env file along with your twitter API details:
################################################################################
### TWITTER API
################################################################################

# Consumer Keys are also known as API keys on the dev portal

TW_CONSUMER_KEY=
TW_CONSUMER_SECRET=
TW_ACCESS_TOKEN=
TW_ACCESS_TOKEN_SECRET=
TW_CLIENT_ID=
TW_CLIENT_ID_SECRET=
"""Twitter API integrations using Tweepy."""
from typing import Any, Dict, List, Optional, Tuple, TypedDict, TypeVar
from auto_gpt_plugin_template import AutoGPTPluginTemplate
import os
import tweepy

PromptGenerator = TypeVar("PromptGenerator")


class Message(TypedDict):
    role: str
    content: str


class AutoGPTTwitter(AutoGPTPluginTemplate):
    """
    Twitter API integrations using Tweepy
    """

    def __init__(self):
        super().__init__()
        self._name = "autogpt-twitter"
        self._version = "0.1.0"
        self._description = "Twitter API integrations using Tweepy."
        self.twitter_consumer_key = os.getenv("TW_CONSUMER_KEY")
        self.twitter_consumer_secret = os.getenv("TW_CONSUMER_SECRET")
        self.twitter_access_token = os.getenv("TW_ACCESS_TOKEN")
        self.twitter_access_token_secret = os.getenv("TW_ACCESS_TOKEN_SECRET")
        self.tweet_id = []
        self.tweets = []

        self.api = None

        if (
            self.twitter_consumer_key
            and self.twitter_consumer_secret
            and self.twitter_access_token
            and self.twitter_access_token_secret
        ) is not None:
            # Authenticating to twitter
            self.auth = tweepy.OAuth1UserHandler(
                self.twitter_consumer_key,
                self.twitter_consumer_secret,
                self.twitter_access_token,
                self.twitter_access_token_secret,
            )
            self.api = tweepy.API(self.auth)
            self.stream = tweepy.Stream(
                self.twitter_consumer_key,
                self.twitter_consumer_secret,
                self.twitter_access_token,
                self.twitter_access_token_secret,
            )
        else:
            print("Twitter credentials not found in .env file.")

    def can_handle_on_response(self) -> bool:
        """This method is called to check that the plugin can
        handle the on_response method.
        Returns:
            bool: True if the plugin can handle the on_response method."""
        return False

    def on_response(self, response: str, *args, **kwargs) -> str:
        """This method is called when a response is received from the model."""
        pass

    def can_handle_post_prompt(self) -> bool:
        """This method is called to check that the plugin can
        handle the post_prompt method.
        Returns:
            bool: True if the plugin can handle the post_prompt method."""
        return True

    def can_handle_on_planning(self) -> bool:
        """This method is called to check that the plugin can
        handle the on_planning method.
        Returns:
            bool: True if the plugin can handle the on_planning method."""
        return False

    def on_planning(
        self, prompt: PromptGenerator, messages: List[str]
    ) -> Optional[str]:
        """This method is called before the planning chat completeion is done.
        Args:
            prompt (PromptGenerator): The prompt generator.
            messages (List[str]): The list of messages.
        """
        pass

    def can_handle_post_planning(self) -> bool:
        """This method is called to check that the plugin can
        handle the post_planning method.
        Returns:
            bool: True if the plugin can handle the post_planning method."""
        return False

    def post_planning(self, response: str) -> str:
        """This method is called after the planning chat completeion is done.
        Args:
            response (str): The response.
        Returns:
            str: The resulting response.
        """
        pass

    def can_handle_pre_instruction(self) -> bool:
        """This method is called to check that the plugin can
        handle the pre_instruction method.
        Returns:
            bool: True if the plugin can handle the pre_instruction method."""
        return False

    def pre_instruction(self, messages: List[str]) -> List[str]:
        """This method is called before the instruction chat is done.
        Args:
            messages (List[str]): The list of context messages.
        Returns:
            List[str]: The resulting list of messages.
        """
        pass

    def can_handle_on_instruction(self) -> bool:
        """This method is called to check that the plugin can
        handle the on_instruction method.
        Returns:
            bool: True if the plugin can handle the on_instruction method."""
        return False

    def on_instruction(self, messages: List[str]) -> Optional[str]:
        """This method is called when the instruction chat is done.
        Args:
            messages (List[str]): The list of context messages.
        Returns:
            Optional[str]: The resulting message.
        """
        pass

    def can_handle_post_instruction(self) -> bool:
        """This method is called to check that the plugin can
        handle the post_instruction method.
        Returns:
            bool: True if the plugin can handle the post_instruction method."""
        return False

    def post_instruction(self, response: str) -> str:
        """This method is called after the instruction chat is done.
        Args:
            response (str): The response.
        Returns:
            str: The resulting response.
        """
        pass

    def can_handle_pre_command(self) -> bool:
        """This method is called to check that the plugin can
        handle the pre_command method.
        Returns:
            bool: True if the plugin can handle the pre_command method."""
        return False

    def pre_command(
        self, command_name: str, arguments: Dict[str, Any]
    ) -> Tuple[str, Dict[str, Any]]:
        """This method is called before the command is executed.
        Args:
            command_name (str): The command name.
            arguments (Dict[str, Any]): The arguments.
        Returns:
            Tuple[str, Dict[str, Any]]: The command name and the arguments.
        """
        pass

    def can_handle_post_command(self) -> bool:
        """This method is called to check that the plugin can
        handle the post_command method.
        Returns:
            bool: True if the plugin can handle the post_command method."""
        return False

    def post_command(self, command_name: str, response: str) -> str:
        """This method is called after the command is executed.
        Args:
            command_name (str): The command name.
            response (str): The response.
        Returns:
            str: The resulting response.
        """
        pass

    def can_handle_chat_completion(
        self,
        messages: list[Dict[Any, Any]],
        model: str,
        temperature: float,
        max_tokens: int,
    ) -> bool:
        """This method is called to check that the plugin can
        handle the chat_completion method.
        Args:
            messages (Dict[Any, Any]): The messages.
            model (str): The model name.
            temperature (float): The temperature.
            max_tokens (int): The max tokens.
        Returns:
            bool: True if the plugin can handle the chat_completion method."""
        return False

    def handle_chat_completion(
        self,
        messages: list[Dict[Any, Any]],
        model: str,
        temperature: float,
        max_tokens: int,
    ) -> str:
        """This method is called when the chat completion is done.
        Args:
            messages (Dict[Any, Any]): The messages.
            model (str): The model name.
            temperature (float): The temperature.
            max_tokens (int): The max tokens.
        Returns:
            str: The resulting response.
        """
        return None

    def post_prompt(self, prompt: PromptGenerator) -> PromptGenerator:
        """This method is called just after the generate_prompt is called,
            but actually before the prompt is generated.
        Args:
            prompt (PromptGenerator): The prompt generator.
        Returns:
            PromptGenerator: The prompt generator.
        """
        if self.api:
            from .twitter import (
                get_mentions,
                post_reply,
                post_tweet,
                search_twitter_user,
            )

            prompt.add_command(
                "post_tweet", "Post Tweet", {"tweet_text": "<tweet_text>"}, post_tweet
            )
            prompt.add_command(
                "post_reply",
                "Post Twitter Reply",
                {"tweet_text": "<tweet_text>", "tweet_id": "<tweet_id>"},
                post_reply,
            )
            prompt.add_command("get_mentions", "Get Twitter Mentions", {}, get_mentions)
            prompt.add_command(
                "search_twitter_user",
                "Search Twitter",
                {
                    "target_user": "<target_user>",
                    "number_of_tweets": "<number_of_tweets",
                },
                search_twitter_user,
            )

        return prompt

Copy this code and paste it in the Twitter plugin directory. You can also customise this code as per your wishes.

"""This module contains functions for interacting with the Twitter API."""
from __future__ import annotations
from . import AutoGPTTwitter
import pandas as pd
import tweepy

plugin = AutoGPTTwitter()


def post_tweet(tweet_text: str) -> str:
    """Posts a tweet to twitter.
    Args:
        tweet (str): The tweet to post.
    Returns:
        str: The tweet that was posted.
    """

    _tweetID = plugin.api.update_status(status=tweet_text)

    return f"Success! Tweet: {_tweetID.text}"

To know more about AutoGPT plugins read this.

This article is to help you learn about how to create AutoGPT plugins. We trust that it has been helpful to you. Please feel free to share your thoughts and feedback in the comment section below.

42
1.759.504,10

Cart

Quantity 8.950,00
Quantity 18,00
Quantity 123.090,00