Want to talk to SnoopStein? Post a tweet with
@snoop_stein
and wait for the reply.Make your own SnoopStein
To get started:- Create an account on MindsDB cloud (if you don’t have one yet).
- Go to your MindsDB SQL Editor
1. Create a GPT-4 Model!
Let’s first see how simple it is to create a machine learning model represented as a virtual ‘AI table’ in MindsDB. In this example, we will call our GPT-4 modelgpt_model
.
(Bear in mind that GPT-4 API is in HIGH demand and is rate limited, so can be slow. The following steps might each take a few seconds.)
Before creating an OpenAI model, please create an engine, providing your OpenAI API key:
If you are using MindsDB on Docker or if you want to use your own OpenAI API key, simply pass the
api_key
argument in the USING
clause.prompt_template
. This is where we tell GPT how to write answers; it is a template because you can pass values from columns, in this case the template contains {{author_username}}
and {{text}}
, which will be replaced from the WHERE
clause variables in the query. Let’s see it in action:
2. Create an ML Model with Personality
prompt_template
to explain in plain english how we want GPT to formulate its responses.
Let’s create a model called snoopstein_model
with a prompt template that gives GPT a hybrid personality: he is half-Einstein, half-Snoop Dogg. A brilliant physicist who owns the rap game. His name is Snoop Stein:
Before creating an OpenAI model, please create an engine, providing your OpenAI API key:
3. Connect your GPT-4 Model to Twitter!
You will need to sign up for a Twitter dev account in order to actually be able to read and write tweets into Twitter, if you don’t have a Twitter dev account already. Twitter may take a day or so to approve your new dev account. Once you are approved, here are the steps to link your Twitter account to MindsDB: https://www.youtube.com/watch?v=qVe7PeC0sUQ You can find the details on how to connect your Twitter developer account to MindsDB here. We are going to prepare a MindsDB SQL statement to connect to Twitter:my_twitter
. This database ships with a table called tweets
that we can use to search for tweets as well as to write tweets.
You can use the Twitter API to get a list of tweets with a particular text or hashtag:
query
parameter supports anything that the Twitter API supports as query
, for more reference, read here.
Let’s test that this model can generate outputs based on the Snoop Stein personality on many tweets, by joining the model with the tweets
table:
4. Writing Tweets using SQL
Let’s test by tweeting a few things into the MindsDB Twitter account:You can insert any of the values of the tweepy function
create_tweet
: https://docs.tweepy.org/en/stable/client.html#tweepy.Client.create_tweet5. Setting up a Database
MindsDB processes your data but doesn’t store it. Therefore, you need a database where MindsDB can insert query results to ensure the JOBs run smoothly. It also helps keeping the logs of conversations. Let’s create a MariaDB SkySQL cloud database, it takes just minutes to launch, and it comes with a free trial as well. Follow the docs to set up SkySQL and connect it to MindsDB.Alternatively, you can opt for using the MindsDB’s custom
LAST
keyword that, when used in a query, ensures only the newly added data is selected. Jump to the end of point 7 if you prefer to not use any external database for storing tweets.6. Creating Job Components
First, we input all tweets that need a reply into the chatbot_input table:7. At last: let’s create the JOB
Now we put together all job components and automate the process.Alternatively, you can skip setting up a database to store input and output tweets. Instead, you can use the
LAST
keyword that ensures only the newly added tweets are selected.Here is how to set up a job using the LAST
keyword: