www.singlestore.com
Open in
urlscan Pro
2600:9000:223e:3a00:1d:6ef1:2fc0:93a1
Public Scan
Submitted URL: https://app.go.singlestore.com/e/er?s=1387486446&lid=5113&elqTrackId=f3fc7f2d2b394c259b63b536f5afefb6&elq=508a729487f54818967c6...
Effective URL: https://www.singlestore.com/blog/how-to-build-a-charismatic-twitter-chatbot-in-a-few-hours/?utm_medium=email&utm_source=sing...
Submission: On May 03 via api from CH — Scanned from DE
Effective URL: https://www.singlestore.com/blog/how-to-build-a-charismatic-twitter-chatbot-in-a-few-hours/?utm_medium=email&utm_source=sing...
Submission: On May 03 via api from CH — Scanned from DE
Form analysis
0 forms found in the DOMText Content
We value your privacy We use cookies to enhance your browsing experience, serve personalized ads or content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies. Read More Customize Reject All Accept All Customize Consent Preferences We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below. The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more NecessaryAlways Active Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data. * Cookie checkForPermission * Duration 10 minutes * Description This cookie is set by Beeswax to determine whether the user has accepted the cookie consent box. * Cookie AUTH_SESSION_ID * Duration session * Description No description available. * Cookie AUTH_SESSION_ID_LEGACY * Duration session * Description No description available. * Cookie KC_RESTART * Duration session * Description No description available. * Cookie _forum_session * Duration session * Description No description available. * Cookie __cfruid * Duration session * Description Cloudflare sets this cookie to identify trusted web traffic. * Cookie AWSALBCORS * Duration 7 days * Description This cookie is managed by Amazon Web Services and is used for load balancing. * Cookie YII_CSRF_TOKEN * Duration session * Description This cookie is used a unique token that used in securing forms and other website inputs against XSS attacks. * Cookie _GRECAPTCHA * Duration 5 months 27 days * Description This cookie is set by the Google recaptcha service to identify bots to protect the website against malicious spam attacks. * Cookie AWSALB * Duration 7 days * Description AWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target. * Cookie cookieyes-consent * Duration 1 year * Description CookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on their subsequent visits to this site. It does not collect or store any personal information of the site visitors. * Cookie __stripe_sid * Duration 0 * Description Cookie set by Stripe for fraud prevention purposes * Cookie __stripe_mid * Duration 0 * Description Set by Stripe for fraud prevention purposes Functional Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features. * Cookie ARRAffinity * Duration session * Description ARRAffinity cookie is set by Azure app service, and allows the service to choose the right instance established by a user to deliver subsequent requests made by that user. * Cookie ARRAffinitySameSite * Duration session * Description This cookie is set by Windows Azure cloud, and is used for load balancing to make sure the visitor page requests are routed to the same server in any browsing session. * Cookie _biz_uid * Duration 1 year * Description This cookie is set by Bizible, to store user id on the current domain. * Cookie _biz_nA * Duration 1 year * Description This cookie, set by Bizible, is a sequence number that Bizible includes for all requests, for internal diagnostics purposes. * Cookie __cf_bm * Duration 30 minutes * Description This cookie, set by Cloudflare, is used to support Cloudflare Bot Management. * Cookie UserMatchHistory * Duration 1 month * Description LinkedIn sets this cookie for LinkedIn Ads ID syncing. * Cookie lang * Duration session * Description LinkedIn sets this cookie to remember a user's language setting. * Cookie bcookie * Duration 1 year * Description LinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser ID. * Cookie lidc * Duration 1 day * Description LinkedIn sets the lidc cookie to facilitate data center selection. * Cookie bscookie * Duration 1 year * Description LinkedIn sets this cookie to store performed actions on the website. * Cookie ELOQUA * Duration 1 year 1 month * Description Eloqua global user identifier * Cookie connect.sid * Duration 2 hours * Description This cookie is used for authentication and for secure log-in. It registers the log-in information. * Cookie split * Duration 1 month * Description This cookie is used to evaluate the changes to the website by checking which multivariate test the user takes part in. * Cookie ELOQUA * Duration 1 year 1 month * Description Eloqua global user identifier * Cookie ajs_anonymous_id * Duration 1 year * Description This cookie set by Segment is used to record the number of people that visit our site, and track whether you've visited before. Analytics Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc. * Cookie singlestoreTraits * Duration 1 year * Description No description * Cookie mp_956569872348636f9bc2d62e4f838261_mixpanel * Duration 1 year * Description Mixpanel production * Cookie _biz_sid * Duration 30 minutes * Description This cookie is set by Bizible, to store the user's session id. * Cookie _biz_pendingA * Duration 1 year * Description A Cloudflare cookie set to record users’ settings as well as for authentication and analytics. * Cookie _biz_flagsA * Duration 1 year * Description A single cookie from Bizible that stores multiple information, such as whether or not the user has submitted a form, performed a crossdomain migration, sent a viewthrough pixel, opted out from tracking, etc. * Cookie _BUID * Duration 1 year * Description This cookie, set by Bizible, is a universal user id to identify the same user across multiple clients’ domains. * Cookie _ga * Duration 2 years * Description The _ga cookie, installed by Google Analytics, calculates visitor, session and campaign data and also keeps track of site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognize unique visitors. * Cookie _gid * Duration 1 day * Description Installed by Google Analytics, _gid cookie stores information on how visitors use a website, while also creating an analytics report of the website's performance. Some of the data that are collected include the number of visitors, their source, and the pages they visit anonymously. * Cookie _gcl_au * Duration 3 months * Description Provided by Google Tag Manager to experiment advertisement efficiency of websites using their services. * Cookie _hjFirstSeen * Duration 30 minutes * Description Hotjar sets this cookie to identify a new user’s first session. It stores a true/false value, indicating whether it was the first time Hotjar saw this user. * Cookie _hjIncludedInSessionSample * Duration 2 minutes * Description Hotjar sets this cookie to know whether a user is included in the data sampling defined by the site's daily session limit. * Cookie _hjIncludedInPageviewSample * Duration 2 minutes * Description Hotjar sets this cookie to know whether a user is included in the data sampling defined by the site's pageview limit. * Cookie _hjAbsoluteSessionInProgress * Duration 30 minutes * Description Hotjar sets this cookie to detect the first pageview session of a user. This is a True/False flag set by the cookie. * Cookie _gat_UA-21693588-1 * Duration 1 minute * Description A variation of the _gat cookie set by Google Analytics and Google Tag Manager to allow website owners to track visitor behaviour and measure site performance. The pattern element in the name contains the unique identity number of the account or website it relates to. * Cookie _hjTLDTest * Duration session * Description To determine the most generic cookie path that has to be used instead of the page hostname, Hotjar sets the _hjTLDTest cookie to store different URL substring alternatives until it fails. * Cookie CONSENT * Duration 2 years * Description YouTube sets this cookie via embedded youtube-videos and registers anonymous statistical data. * Cookie browser_id * Duration 5 years * Description This cookie is used for identifying the visitor browser on re-visit to the website. * Cookie _jsuid * Duration 1 year * Description This cookie contains random number which is generated when a visitor visits the website for the first time. This cookie is used to identify the new visitors to the website. * Cookie IDE * Duration 1 year 24 days * Description Google DoubleClick IDE cookies are used to store information about how the user uses the website to present them with relevant ads and according to the user profile. * Cookie mp_aee4da1111c439e10ee2982f40abcd0d_mixpanel * Duration 1 year * Description Mixpanel development Performance Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors. * Cookie _gat * Duration 1 minute * Description This cookie is installed by Google Universal Analytics to restrain request rate and thus limit the collection of data on high traffic sites. * Cookie _uetsid * Duration 1 day * Description Bing Ads sets this cookie to engage with a user that has previously visited the website. * Cookie _uetvid * Duration 1 year 24 days * Description Bing Ads sets this cookie to engage with a user that has previously visited the website. * Cookie SRM_B * Duration 1 year 24 days * Description Used by Microsoft Advertising as a unique ID for visitors. * Cookie dtCookie * Duration session * Description This cookie is set by the provider Dynatrace. This is a session cookie used to collect information for Dynatrace. Its a system to track application performance and user errors. Advertisement Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns. * Cookie li_gc * Duration 5 months 27 days * Description No description * Cookie MUID * Duration 1 year 24 days * Description Bing sets this cookie to recognize unique web browsers visiting Microsoft sites. This cookie is used for advertising, site analytics, and other operations. * Cookie test_cookie * Duration 15 minutes * Description The test_cookie is set by doubleclick.net and is used to determine if the user's browser supports cookies. * Cookie _fbp * Duration 3 months * Description This cookie is set by Facebook to display advertisements when either on Facebook or on a digital platform powered by Facebook advertising, after visiting the website. * Cookie personalization_id * Duration 2 years * Description Twitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting. * Cookie IDE * Duration 1 year 24 days * Description Google DoubleClick IDE cookies are used to store information about how the user uses the website to present them with relevant ads and according to the user profile. * Cookie bito * Duration 1 year 1 month * Description This cookie is set by Beeswax for advertisement purposes. * Cookie bitoIsSecure * Duration 1 year 1 month * Description Beeswax sets this cookie for targeting and advertising. The cookie is used to serve the user with relevant advertisements based on real time bidding. * Cookie tuuid * Duration 2 years * Description The tuuid cookie, set by BidSwitch, stores an unique ID to determine what adverts the users have seen if they have visited any of the advertiser's websites. The information is used to decide when and how often users will see a certain banner. * Cookie tuuid_lu * Duration 2 years * Description This cookie, set by BidSwitch, stores a unique ID to determine what adverts the users have seen while visiting an advertiser's website. This information is then used to understand when and how often users will see a certain banner. * Cookie ANONCHK * Duration 10 minutes * Description The ANONCHK cookie, set by Bing, is used to store a user's session ID and also verify the clicks from ads on the Bing search engine. The cookie helps in reporting and personalization as well. * Cookie bku * Duration 6 months 1 day * Description Bluekai uses this cookie to build an anonymous user profile with data like the user's online behaviour and interests. * Cookie bkpa * Duration 6 months 1 day * Description Set by Bluekai, this cookie stores anonymized data about the users' web usage in an aggregate form to build a profile for targeted advertising. * Cookie NID * Duration 6 months * Description NID cookie, set by Google, is used for advertising purposes; to limit the number of times the user sees an ad, to mute unwanted ads, and to measure the effectiveness of ads. * Cookie YSC * Duration session * Description YSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages. * Cookie VISITOR_INFO1_LIVE * Duration 5 months 27 days * Description A cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface. * Cookie yt-remote-device-id * Duration never * Description YouTube sets this cookie to store the video preferences of the user using embedded YouTube video. * Cookie yt.innertube::requests * Duration never * Description This cookie, set by YouTube, registers a unique ID to store data on what videos from YouTube the user has seen. * Cookie yt.innertube::nextId * Duration never * Description This cookie, set by YouTube, registers a unique ID to store data on what videos from YouTube the user has seen. * Cookie yt-remote-connected-devices * Duration never * Description YouTube sets this cookie to store the video preferences of the user using embedded YouTube video. * Cookie ln_or * Duration 1 day * Description Set by LinkedIn. Used to determine if Oribi analytics can be carried out on a specific domain Others Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet. * Cookie AnalyticsSyncHistory * Duration 1 month * Description No description * Cookie _rdt_uuid * Duration 3 months * Description No description available. * Cookie muc_ads * Duration 2 years * Description No description * Cookie CLID * Duration 1 year * Description No description * Cookie _hjSessionUser_2171074 * Duration 1 year * Description No description * Cookie _hjSession_2171074 * Duration 30 minutes * Description No description * Cookie chzdpsync * Duration 1 month * Description No description available. * Cookie _clck * Duration 1 year * Description No description * Cookie _clsk * Duration 1 day * Description No description * Cookie SM * Duration session * Description No description available. * Cookie intercom-id-oc3xi4bh * Duration 8 months 26 days 1 hour * Description No description * Cookie intercom-session-oc3xi4bh * Duration 7 days * Description No description * Cookie loglevel * Duration never * Description No description available. * Cookie _zendesk_shared_session * Duration session * Description No description available. * Cookie _zendesk_session * Duration session * Description No description available. * Cookie _zendesk_thirdparty_test * Duration session * Description No description available. * Cookie _zendesk_authenticated * Duration past * Description No description * Cookie __tld__ * Duration session * Description No description * Cookie r * Duration session * Description No description * Cookie docebo_session * Duration session * Description No description available. * Cookie SimpleSAMLSessionID * Duration session * Description This cookie is used for tracking the website sessions. It enables the users to remain logged in. * Cookie route-gcrowd-fe-prod * Duration session * Description No description available. * Cookie _cookie_id * Duration session * Description No description available. * Cookie _help_center_session * Duration session * Description No description available. * Cookie _heatmaps_g2g_100794436 * Duration 10 minutes * Description No description * Cookie visitorId * Duration 1 year * Description No description * Cookie dosp * Duration session * Description No description Reject All Save My Preferences Accept All SQL in Seconds. Now That’s Nuts. Chat with SQrL → Times Icon * Product Database Cloud IconCloudDatabase IconSelf-ManagedAlign Right IconIngest DataTools IconTools and MonitoringLock IconSecurityLayer Plus IconPartner Connect Services User Headset IconProfessional ServicesLife Ring IconSupportPresentation IconTrainingFile Certificate IconCertification Request a DemoOur product experts will give you a live demo and discuss your requirementsLearn MoreArrow Right IconVideoLearn how SingleStore works and see it in actionWatch NowArrow Right Icon * Solutions Use Cases Analytics IconReal-Time AnalyticsTachometer Fast IconSupercharge SaaS AppsExpand IconScale Your DatabaseDatabase IconConsolidate DatabasesList Check IconCompare Databases Industries Landmark IconFinancial ServicesVideo IconMedia & CommunicationBolt IconEnergyMicrochip IconHigh Tech View All SolutionsArrow Right Icon Why SingleStore?SingleStore enables companies to simplify their data architecturesLearn MoreArrow Right IconCustomer StoriesTrusted by Leading Global Brands and Data Innovators.View Case StudiesArrow Right Icon * Docs Build Book IconDocumentationQuestion Circle IconFAQCheck IconTutorialsPresentation IconTraining Developer HubBuild fast data applications with code repositories and moreStart DevelopingArrow Right Icon * Resources View File IconCase StudiesChart Line IconInfographicsPresentation IconWebinarsPlay IconVideos View All ResourcesArrow Right Icon Read Book IconEbooksFile IconWhite PapersFile IconSolution BriefsNewspaper IconIndustry Reports Industry ReportThe Forrester Wave™: Translytical Data Platforms, Q4 2022Read NowArrow Right Icon * Community Engage Comments IconForumsCode IconDeveloper HubCalendar IconEvents WebinarTranslytical Platforms, Use Cases & Trends, Featuring ForresterWatch NowArrow Right Icon * Company About Building IconAbout UsMountain IconLeadershipPuzzle Piece IconPartnersBriefcase IconCareers We're hiringArrow Right Icon Connect Blog IconBlogNewspaper IconNews & PressHeart IconSingleStore For GoodComment IconContact Us Blog PostIt’s a Pivotal Time for Data and Disruption — and SingleStore Is Leading the Way in the CloudRead NowArrow Right Icon * Pricing * Open Search * Sign InSign In Laptop IconPortalAccess Cloud & LicensesComments IconForumsAsk the CommunityUsers Class IconTrainingSelf-Paced LearningLife Ring IconEnterprise SupportSubmit a Ticket * Start FreeStart Free Product HOW TO BUILD A CHARISMATIC TWITTER CHATBOT IN A FEW HOURS AC Akmal Chaudhri Costa Tin Tom Hudson Share to FacebookShare to TwitterShare to LinkedInShare to RedditShare to Email Discover the secret to building an interactive conversation chatbot on Twitter with state-of-the-art natural language processing in this technical tutorial — and create a chatbot that can respond to users with the appropriate context and personality. But why stop there? This tutorial also dives into advanced capabilities using the powerful combination of SingleStoreDB and MindsDB, instead of direct API integration with the GPT-4 model. Take your chatbot game to the next level — and learn how to create a more personalized, engaging user experience. In this technical tutorial, we'll show you how to create a chatbot that can interact with users on Twitter, responding with the appropriate context and personality using state-of-the-art natural language processing. To help you get started, we'll use the example of @Snoop_Stein, a Twitter bot that combines the unique personalities of Snoop Dogg and Albert Einstein. By tweeting @Snoop_Stein, users can engage with a rapping physicist who will respond with witty and intelligent remarks, all thanks to the advanced capabilities of the latest OpenAI GPT-4 model. MAKE YOUR OWN SNOOPSTEINMAKE-YOUR-OWN-SNOOP-STEIN To get started: * Create an account on MindsDB cloud * Create an account on SingleStoreDB Cloud MindsDB is a popular open-source low-code machine learning platform that helps developers easily build AI-powered solutions. It automates and integrates top machine learning frameworks into the data stack to streamline the integration of AI into applications, making it accessible to developers of all skill levels. SingleStoreDB is a distributed, multi-model Database Management System (DBMS) designed for high-performance, real-time analytics and operational workloads. It combines both transactional and analytical processing in a single, unified platform. Now we’ll show you how we built the Snoop_Stein GPT-4 bot, and how you can build your own. CONNECT TO A GPT-4 MODELCONNECT-TO-A-GPT-4-MODEL Let’s first connect to a machine learning model (in this case, OpenAI’s GPT-4) that will be abstracted as a virtual ‘AI table’. In this example, we will call it gptbot_model. Bear in mind that GPT-4 API is in high demand and is rate limited, so it can be slow. The following steps might each take a few seconds. CREATE MODEL mindsdb.gpt_model PREDICT response USING engine = 'openai', -- api_key = 'your openai key', in MindsDB cloud accounts we provide a default key model_name = 'gpt-4', -- you can also use 'text-davinci-003', 'gpt-3.5-turbo' prompt_template = 'respond to {{text}} by {{author_username}}'; Note: Another option, 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. One important attribute here is 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 variables in the query. Let’s see in action: SELECT response from mindsdb.gpt_model WHERE author_username = "mindsdb" AND text = "why is gravity so different on the sun?"; MODIFY GPT-4 MODEL WITH PERSONALITYMODIFY-GPT-4-MODEL-WITH-PERSONALITY The previous model's responses were not very exciting, but we can improve them using prompt templates. Essentially, we can use prompt_template to tell the GPT model how to formulate its responses in plain English. To create a new model, we'll call it mindsdb.snoopstein_model, and we'll give it a prompt template that creates a hybrid personality - half-Einstein, half-Snoop Dogg. This personality is named SnoopStein, a brilliant physicist who also dominates the rap game. CREATE MODEL mindsdb.snoopstein_model PREDICT response USING engine = 'openai', max_tokens = 300, -- api_key = 'your openai key, in cloud accounts we provide one', model_name = 'gpt-4', -- you can also use 'text-davinci-003' or 'gpt-3.5-turbo' prompt_template = 'From input message: {{text}}\ by from_user: {{author_username}}\ In less than 550 characters, write a Twitter response to {{author_username}} in the following format:\ Dear @<from_user>, <respond a rhyme as if you were Snoop Dogg but you also were as smart as Albert Einstein, still explain things like Snoop Dogg would, do not mention that you are part Einstein. If possible include references to publications for further reading. If you make a reference quoting some personality, add OG, for example;, if you are referencing Alan Turing, say OG Alan Turing and very briefly explain why you think they would be dope reads. If the question makes no sense, explain that you are a bit lost, and make something up that is both hilarious and relevant. sign with -- mdb.ai/bot by @mindsdb.'; If you are familiar with ChatGPT prompting, it works exactly the same way, so feel free to experiment with the prompt to achieve the best results for your own personality you create. Now, let’s test SnoopStein's persona by asking another question: SELECT response from mindsdb.snoopstein_model WHERE author_username = "someuser" AND text="@snoop_stein, why is gravity so different on the sun?."; It should give you a SnoopStein response similar to the following 😉 Let’s try another one: SELECT response from mindsdb.snoopstein_model WHERE author_username = "someuser" AND text="@snoop_stein, Apart from yourself, which rappers would make the best physicists and why?!"; CONNECT YOUR GPT-4 MODEL TO TWITTER AND STORE TWEETS INTO SINGLESTOREDBCONNECT-YOUR-GPT-4-MODEL-TO-TWITTER-AND-STORE-TWEETS-INTO-SINGLE-STORE-DB First, we are going to connect to twitter with read-only access via MindsDB. We use the same command as if we’re connecting to a database: CREATE DATABASE my_twitter WITH ENGINE = 'twitter'; This command creates a MindsDB data integration called my_twitter. It behaves like a database and represents data in 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 — in the case below ‘snoopstein or ’#mindsdb’ SELECT id, created_at, author_username, text FROM my_twitter.tweets WHERE query = '(@snoopstein OR @snoop_stein OR #snoopstein OR #snoop_stein) -is:retweet' AND created_at > '2023-03-20' LIMIT 20; Note that the parameter ‘query’ supports anything that the twitter API supports as ‘query.’ You can get more information and references here. Let’s test this model’s ability to generate outputs based on several SnoopStein personality tweets, joining the model with the tweets table: SELECT t.id AS in_reply_to_tweet_id, t.text AS input_text, t.author_username, t.created_at, r.response AS text FROM my_twitter.tweets t JOIN mindsdb.snoopstein_model r WHERE t.query = '(@snoopstein OR @snoop_stein OR #snoopstein OR #snoop_stein) -is:retweet -from:snoop_stein' AND t.created_at > '2023-03-31' LIMIT 4; We can also store the results of the query in SingleStoreDB. This could be very useful for several reasons: * Log all tweets (for troubleshooting and analysis) * Ensure JOBs (described further) run smoothly To use SingleStoreDB, we need to create a free account. This is very straightforward. We just need to follow the detailed instructions in the Create a SingleStoreDB Cloud account section. We’ll use ChatGPT Demo Group as our Workspace Group Name and chatgpt-demo as our Workspace Name. We’ll make a note of our password and host name. We’ll use the SingleStore SQL Editor to create a new database and table, as follows: CREATE DATABASE IF NOT EXISTS chatgpt_db; USE chatgpt_db; CREATE TABLE chatbot_input ( id text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, created_at text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, text text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, edit_history_tweet_ids text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, author_id text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, author_name text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, author_username text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, conversation_id text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, in_reply_to_user_id text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, in_reply_to_user_name text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, in_reply_to_user_username text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ) CREATE TABLE chatbot_output ( id text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, created_at text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, text text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, edit_history_tweet_ids text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, author_id text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, author_name text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, author_username text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, conversation_id text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, in_reply_to_user_id text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, in_reply_to_user_name text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, in_reply_to_user_username text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ) In the MindsDB SQL Editor, we’ll create a connection, as follows: CREATE DATABASE chatgpt_db WITH ENGINE = "singlestore", PARAMETERS = { "user" : "admin", "password" : "<password>", "host" : "<host>", "port" : "3306", "database" : "chatgpt_db" } We’ll replace <password> and <host> with the values from our SingleStoreDB Cloud account. We can now store the results of twitter queries in SingleStoreDB using the MindsDB SQL Editor, as follows: INSERT INTO singlestore_demo.chatbot_input ( SELECT * FROM my_twitter_v2.tweets WHERE query = '(@snoopstein OR @snoop_stein OR #snoopstein OR #snoop_stein OR @mindsdb OR #mindsdb) -is:retweet -from:snoop_stein' AND created_at > '2023-04-04 11:50:00' ) INSERT INTO singlestore_demo.chatbot_output ( SELECT * FROM my_twitter.tweets WHERE query = 'from:snoop_stein' AND created_at > '2023-04-04 11:50:00' ) COMPOSING TWEET RESPONSESCOMPOSING-TWEET-RESPONSES Now, we need to prepare MindsDB to write responses back into Twitter. For this, you will need to sign up for a Twitter dev account. 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: Please accept the cookie consent * Open developer portal * Select the [+ Add app] button to create a new app * Select [Create new] * Select “Production” and give it a name * Copy and populate in the query * API Key (aka. consumer_key) * API Key Secret (aka. consumer_secret) * Bearer Token * Click Setup on User authentication settings * On Permissions select: Read and Write * On Type of App select: Web App, Automated App or Bot * On App Info: Provide any url for the callback url and website url * Click Save * Once you are back in the app settings, click Keys and Tokens * Generate Access Token and Secret, and populate on the query * Access Token Access Token Secret Proceed to create a new updated database, so it can read and write as follows: CREATE DATABASE mindsdb.my_twitter_v2 WITH PARAMETERS = { "consumer_key": "your twitter App API key", "consumer_secret": "your twitter App API key secret", "bearer_token": "your twitter App bearer TOKEN", "access_token": "your twitter App Access Token", "access_token_secret": "your twitter App Access Token Secret" }; Let's test this by tweeting a few things into the MindsDB Twitter account: INSERT INTO my_twitter_v2.tweets (in_reply_to_tweet_id, text) VALUES (1633439839491092482, 'MindsDB is great! now its super simple to build ML powered apps using JOBS https://docs.mindsdb.com/sql/tutorials/twitter-chatbot'), (1634126825377996800, 'Holy!! MindsDB is such a useful tool for developers doing ML https://docs.mindsdb.com/sql/tutorials/twitter-chatbot'); Works like magic, right? Those tweets should now be live now on Twitter. You can check your tweet responses here: https://twitter.com/MindsDB/status/1633439839491092482 And here: https://twitter.com/MindsDB/status/1634126825377996800 Note: you can insert any of the values of the tweepy function create_tweet: https://docs.tweepy.org/en/stable/client.html#tweepy.Client.create_tweet AUTOMATE THE WORKFLOW WITH JOBSAUTOMATE-THE-WORKFLOW-WITH-JO-BS The CREATE JOB statement is great because you can use it to automate work. The idea is simple — you give it the query you want to execute, and how often. Let’s set up a job for Snoop Stein! Let’s write a JOB called chatbot_job, which is split into three parts: 1. Check for new tweets 2. Check for tweets it has already replied to 3. Reply to the remaining tweets 1. Find the tweets it hasn’t replied to yet 2. Generate responses using the OpenAI model 3. Insert the responses back into Twitter All of this can be written in SQL. Let’s go one step at a time: Check for new tweets Here we are finding any new tweets that meet our filters, and inserting them into SingleStoreDB. INSERT INTO singlestore_demo.chatbot_input ( SELECT * FROM my_twitter_v2.tweets WHERE query = '(@snoopstein OR @snoop_stein OR #snoopstein OR #snoop_stein OR @mindsdb OR #mindsdb) -is:retweet -from:snoop_stein' AND created_at > '2023-04-04 11:50:00' ) Check for tweets it has already replied to INSERT INTO singlestore_demo.chatbot_output ( SELECT * FROM my_twitter_v2.tweets WHERE query = 'from:snoop_stein' AND created_at > '2023-04-04 11:50:00' ) Reply to the remaining tweets. Find the tweets it hasn’t replied to yet -- Find all the input tweets, where snoopstein has not already been involved in the conversation SELECT * FROM singlestore_demo.chatbot_input WHERE conversation_id not in (select r.conversation_id from singlestore_demo.chatbot_output as r) AND id IS NOT NULL -- Create a view for the above to simplify things CREATE VIEW to_reply_to ( SELECT * FROM singlestore_demo.chatbot_input WHERE conversation_id not in (select r.conversation_id from singlestore_demo.chatbot_output as r) AND id IS NOT NULL ) -- View the tweets we would like to reply to select * from to_reply_to; Generate responses using the OpenAI model -- Join one with the model SELECT * FROM to_reply_to JOIN mindsdb.snoopstein_model_v4 LIMIT 1; -- Create a view for the above CREATE VIEW to_tweet ( SELECT * FROM to_reply_to JOIN mindsdb.snoopstein_model_v4 LIMIT 1 ) -- See the output select author_username, text, response from to_tweet; Insert the responses back into Twitter SELECT id as in_reply_to_tweet_id, response as text FROM to_tweet; Now let’s join it all together! There are a few new variables parameters we have included: * "{{PREVIOUS_START_DATETIME}}": this: * For more information, please check out our documentation on JOBs. CREATE JOB chatbot_job ( -- Part 1 INSERT INTO chatgpt_db.chatbot_input( SELECT * FROM my_twitter_v2.tweets WHERE query = '(@snoopstein OR @snoop_stein OR #snoopstein OR #snoop_stein OR @mindsdb OR #mindsdb) -is:retweet -from:snoop_stein' AND created_at > '2023-04-04 11:50:00' AND created_at > "{{PREVIOUS_START_DATETIME}}" ); -- Part 2 INSERT INTO chatgpt_db.chatbot_output ( SELECT * FROM my_twitter_v2.tweets WHERE query = 'from:snoop_stein' AND created_at > '2023-04-04 11:50:00' AND created_at > "{{PREVIOUS_START_DATETIME}}" ); -- Part 3 INSERT INTO my_twitter_v2.tweets ( SELECT id as in_reply_to_tweet_id, response as text FROM to_tweet ) ) EVERY minute; And there it is! Every minute, we will check for new tweets, and reply with responses generated by OpenAI GPT-4, responding in a style that combines Albert Einstein and Snoop Dogg. You can check if your JOB is running effectively: SELECT * FROM jobs WHERE name="chatbot_job"; SELECT * FROM jobs_history WHERE name="chatbot_job"; You can stop the job, as follows: DROP JOB gpt4_twitter_job There are also other advanced applications you can build, including: * Sentiment analysis of tweets * Classification of tweets * Forecasting the number of tweets Using MindsDB and SingleStoreDB together makes building and deploying these kinds of advanced Machine Learning solutions much faster than ever before. SUMMARYSUMMARY In conclusion, the MindsDB-SinglestoreDB-GPT-4 combination is a powerful tool for developers to easily incorporate machine learning features, like chatbots, into your applications. With multiple machine learning engines and data integrations available, you can generate automated conversations or get ML predictions — and output them directly into your database and application. Building a Twitter chatbot with GPT-4 is just one example of the quick solutions developers can implement in just a few minutes. For more tutorials, check out the example library. You can also join our community Slack for feedback, support and any questions you may have. Happy coding! April 4th, 2023 Tags Icon ProductEngineering -------------------------------------------------------------------------------- AC Akmal Chaudhri Akmal Chaudhri is a Senior Technical Evangelist at SingleStore. Costa Tin Costa Tin is a Marketing Manager at MindsDB Tom Hudson Tom Hudson is an Engineering Manager at MindsDB RELATED POSTS Product AN INTRODUCTION TO SINGLESTORE If you’ve wondered what makes SingleStore different, how it fits in the database landscape, and why customers are saying great things about it, our updated webinar sh… Read Post Product RUN REAL-TIME APPLICATIONS WITH SPARK AND THE SINGLESTORE SPARK CONNECTOR Apache Spark is one of the most powerful distributed computing frameworks available today. Its combination of fast, in-memory computing with an architecture t… Read Post Product5 min Read WINTER 2022 RELEASE: SINGLESTOREDB UNIVERSAL STORAGE, PART 5 SingleStore Universal Storage is a single table type that supports analytical and transactional workloads. Universal Storage is our… Read Post SingleStore Recognized In THE FORRESTER WAVE:TM TRANSLYTICAL DATA PLATFORMS, Q4 2022 AS A ‘STRONG PERFORMER’ Download ReportArrow Right Icon * Product * Cloud * Self-Managed * Ingest Data * Tools and Monitoring * Security * Pricing * Partner Connect * Request a Demo * Solutions * Why SingleStore? * Real-Time Analytics * Supercharge SaaS Apps * Scale Your Database * End Database Sprawl * Compare Databases * Customers * Learn * Developer Hub * Forums * Events * Resources * Blog * News * Support * Support Plans * Support FAQ * Professional Services * Documentation * Training * Company * About Us * Leadership * Careers We're hiring * Partners * SingleStore For Good * Contact Us Twitter IconFacebook IconLinkedin In IconYoutube IconDiscourse IconGithub Icon © SingleStore, Inc. | Privacy Policy | Terms of Service | Legal Terms and Conditions