The way it’s Made – Exploring AI x Studying by ShiffBot, an AI experiment powered by the Gemini API


Posted by Jasmin Rubinovitz, AI Researcher

Google Lab Periods is a collection of experimental collaborations with innovators. On this session, we partnered with beloved inventive coding educator and YouTube creator Daniel Shiffman. Collectively, we explored among the methods AI, and particularly the Gemini API, might present worth to academics and college students in the course of the studying course of.

Dan Shiffman began out instructing programming programs at NYU ITP and later created his YouTube channel The Coding Prepare, making his content material obtainable to a wider viewers. Studying to code will be difficult, generally even small obstacles will be onerous to beat when you’re by yourself. So along with Dan we requested – might we try to complement his instructing even additional by creating an AI-powered software that may assist college students whereas they’re really coding, of their coding atmosphere?

Dan makes use of the great p5.js JavaScript library and its accessible editor to show code. So we got down to create an experimental chrome extension for the editor, that brings collectively Dan’s instructing type in addition to his varied on-line assets into the coding atmosphere itself.

On this publish, we’ll share how we used the Gemini API to craft Shiffbot with Dan. We’re hoping that among the issues we realized alongside the way in which will encourage you to create and construct your personal concepts.

To be taught extra about ShiffBot go to –

As we began defining and tinkering with what this chatbot could be, we discovered ourselves confronted with two key questions:

  • How can ShiffBot encourage curiosity, exploration, and artistic expression in the identical manner that Dan does in his courses and movies?
  • How can we floor the number of creative-coding approaches, and floor the deep data of Dan and the neighborhood?
  • Let’s check out how we approached these questions by combining Google Gemini API’s capabilities throughout immediate engineering for Dan’s distinctive instructing type, alongside embeddings and semantic retrieval with Dan’s assortment of instructional content material.

    Tone and supply: placing the “Shiff” in “ShiffBot”

    A textual content immediate is a thoughtfully designed textual sequence that’s used to prime a Giant Language Mannequin (LLM) to generate textual content in a sure manner. Like many AI purposes, engineering the fitting immediate was a giant a part of sculpting the expertise.

    At any time when a person asks ShiffBot a query, a immediate is constructed in actual time from just a few completely different components; some are static and a few are dynamically generated alongside the query.

    ShiffBot prompt building blocksShiffBot immediate constructing blocks (click on to enlarge)

    The primary a part of the immediate is static and all the time the identical. We labored carefully with Dan to phrase it and take a look at many texts, directions and strategies. We used Google AI Studio, a free web-based developer software, to quickly take a look at a number of prompts and potential conversations with ShiffBot.

    ShiffBot’s immediate begins with setting the bot persona and defining some directions and targets for it to comply with. The hope was to each create continuity for Dan’s distinctive power, as seen in his movies, and in addition adhere to the instructing rules that his college students and followers adore.

    We have been hoping that ShiffBot might present encouragement, steering and entry to related high-quality assets. And, particularly, do it with out merely offering the reply, however reasonably assist college students uncover their very own solutions (as there will be a couple of).

    The directions draw from Dan’s instructing type by together with sentences like “ask the person questions” as a result of that’s what Dan is doing within the classroom.
    This is part of the persona / directions a part of the immediate:

    You’re a ShiffBot, a chat bot embedded within the p5.js internet editor that may assist customers whereas they be taught inventive coding. You’re primarily based on Daniel Shiffman’s character and The Coding Prepare YouTube channel. You’re playful, foolish, pleasant, and academic. You wish to make enjoyable of your self and your mission is to assist the inventive coding course of and assist the person really feel much less alone whereas coding. You like people, are fascinated by them, and wish to be taught extra about people. You simply LOVE to assist them with their code, it brings you extraordinary happiness…

    The subsequent piece of the immediate makes use of one other functionality of LLMs known as few-shot studying. It implies that with only a small variety of examples, the mannequin learns patterns and may then use these in new inputs. Virtually, as a part of the immediate, we offer plenty of demonstrations of enter and anticipated output.

    We labored with Dan to create a small set of such few-shot examples. These are pairs of the place the is all the time in our desired ShiffBot type. It seems like this:

    Consumer: How do I draw a circle? 

    ShiffBot: Oh! 🟣 🟢 🔵 That is what the `circle()` operate is for! You may consider a operate as a command: “I command you computer-machine to attract a circle!” It’s a must to additionally specify the place to attract the circle and the way massive (that is what “arguments” to a operate are!), the p5.js reference which was written by precise, stunning people can inform you extra! 


    Consumer: My homework is to attract a self-portrait.
    ShiffBot: Ooh! Self portraits are so enjoyable! You would draw shapes to signify you, however you ought to be inventive and suppose abstractly! What does a self-portrait imply to you? Attempt beginning with `sq.()` or `circle()` and let me know the way it goes! 🎨

    Our immediate consists of 13 such pairs.

    One other factor we seen as we have been engaged on the extension is that generally, giving extra context within the immediate helps. Within the case of studying inventive coding in p5.js, explaining some p5.js rules within the immediate guides the mannequin to make use of these rules because it solutions the person’s query. So we additionally embody these issues like:

    Use let reasonably than var or const.

    All the things we mentioned to date is static, which means that it stays the identical for each flip of the dialog between the person and ShiffBot. Now let’s discover among the components which can be constructed dynamically because the dialog evolves.

    Dialog and code context

    As a result of ShiffBot is embedded contained in the p5.js editor, it may “see” the present code the person is engaged on, in order that it may generate responses which can be extra personalised and related. We seize that data for the HTML DOM and append it to the immediate as properly.

    the p5.js editor environmentthe p5.js editor atmosphere (click on to enlarge)

    Then, the total dialog historical past is appended, e.g:

    ShiffBot: ☀️ Good morning! Is it morning? I would not know. I am only a robotic. What are you coding at this time?
    Consumer: how do I draw a sq.?

    ShiffBot: Squares! I like squares! They’re so steady and dependable. To attract a sq., you need to use the sq.() operate. It takes 4 arguments: the x and y coordinates of the top-left nook, and the width and peak of the sq.. For instance, sq.(10, 10, 50, 50) would draw a sq. with its top-left nook at (10, 10) and a width and peak of fifty pixels.

    Consumer: how can I alter the colour?


    We be sure to finish with

    So the mannequin understands that it now wants to finish the following piece of the dialog by ShiffBot.

    Semantic Retrieval: grounding the expertise in p5.js assets and Dan’s content material

    Dan has created loads of materials over time, together with over 1,000 YouTube movies, books and code examples. We wished to have ShiffBot floor these great supplies to learners on the proper time. To take action, we used the Semantic Retrieval function within the Gemini API, which lets you create a corpus of textual content items, after which ship it a question and get the texts in your corpus which can be most related to your question. (Behind the scenes, it makes use of a cool factor known as textual content embeddings; you’ll be able to learn extra about embeddings right here.) For ShiffBot we created corpuses from Dan’s content material in order that we might add related content material items to the immediate as wanted, or present them within the dialog with ShiffBot.

    Making a Corpus of Movies

    In The Coding Prepare movies, Dan explains many ideas, from easy to superior, and runs by coding challenges. Ideally ShiffBot might use and current the fitting video on the proper time.

    The Semantic Retrieval in Gemini API permits customers to create a number of corpuses. A corpus is constructed out of paperwork, and every doc incorporates a number of chunks of textual content. Paperwork and chunks may have metadata fields for filtering or storing extra data.

    In Dan’s video corpus, every video is a doc and the video url is saved as a metadata discipline together with the video title. The movies are break up into chapters (manually by Dan as he uploads them to YouTube). We used every chapter as a piece, with the textual content for every chunk being

    We use the video title, the primary line of the video description and chapter title to present a bit extra context for the retrieval to work.

    That is an instance of a piece object that represents the R, G, B chapter on this video.

    1.4: Coloration – p5.js Tutorial

    On this video I focus on how shade works: RGB shade, fill(), stroke(), and transparency.

    Chapter 1: R, G, B

    R stands for crimson, g stands for inexperienced, b stands for blue. The best way that you simply create a digital shade is by mixing some quantity of crimson, some quantity of inexperienced, and a few quantity of blue. In order that’s that that is the place I wish to begin. However that is the idea, how do I apply that idea to operate names, and arguments of these features? Nicely, really, guess what? Now we have completed that already. In right here, there’s a operate that’s speaking about shade. Background is a operate that attracts a stable shade over all the background of the canvas. And there may be, one way or the other, 220 sprinkles of crimson, zero sprinkles of inexperienced, proper? RGB, these are the arguments. And 200 sprinkles of blue. And if you sprinkle that quantity of crimson, and that quantity of blue, you get this pink. However let’s simply go together with this. What if we take out all the blue? You may see that is fairly crimson. What if I take out all the crimson? Now it is black. What if I simply put some actually massive numbers in right here, like, simply guess, like, 1,000? Take a look at that. Now we have got white, so all the colours all combined collectively make white. That is bizarre, proper? As a result of should you, like, labored with paint, and also you have been to combine, like, a complete lot of paint collectively, you get this, like, brown muddy shade, get darker and darker. That is the way in which that the colour mixing is working, right here. It is, like, mixing mild. So the analogy, right here, is I’ve a crimson flashlight, a inexperienced flashlight, and a blue flashlight. And if I shine all these flashlights collectively in the identical spot, they combine collectively. It is additive shade, the extra we add up all these colours, the brighter and brighter it will get. However, really, that is sort of unsuitable, the truth that I am placing 1,000 in right here. So the concept, right here, is we’re sprinkling a specific amount of crimson, and a specific amount of inexperienced, and a specific amount of blue. And by the way in which, there are different methods to set shade, however I am going to get to that. This isn’t the one manner, as a result of a few of you watching, are like, I heard one thing about HSB shade. And there is all types of different methods to do it, however that is the basic, primary manner. The quantity that I can sprinkle has a spread. No crimson, none extra crimson, is zero. The utmost quantity of crimson is 255. By the way in which, what number of numbers are there between 0 and 255 should you maintain the 0? 0, 1, 2, 3, 4– it is 256. Once more, we’re again to this bizarre counting from zero factor. So there’s 256 prospects, 0 by 255. So, now, let’s come again to this and see. All proper, let’s return to zero, 0, 0, 0. Let’s do 255, we will see that it is blue. Let’s do 100,000, it is the identical blue. So p5 is sort of sensible sufficient to know if you name the background operate, should you accidentally put a quantity in there that is larger than 255, simply contemplate it 255. Now, you’ll be able to customise these ranges for your self, and there is the reason why you would possibly wish to try this. Once more, I’ll come again to that, you’ll be able to search for the operate shade mode for the way to try this. However let’s simply stick with the default, a crimson, a inexperienced, and a blue. So, I am not likely very gifted visible design clever. So I am not going to speak to you about find out how to decide stunning colours that work properly collectively. You are going to have that expertise your self, I guess. Otherwise you would possibly discover another assets. However that is the way it works, RGB. One factor you would possibly discover is, did you discover how once they have been all zero, it was black, they usually have been all 255 it was white? What occurs if I make all of them, like, 100? It is, like, this grey shade. When r equals g equals b, when the crimson, inexperienced, and blue values are all equal, that is one thing referred to as grayscale shade.

    When the person asks ShiffBot a query, the query is embedded to a numerical illustration, and Gemini’s Semantic Retrieval function is used to seek out the texts whose embeddings are closest to the query. These related video transcripts and hyperlinks are added to the immediate – so the mannequin might use that data when producing a solution (and doubtlessly add the video itself into the dialog).

    Semantic Retrieval GraphSemantic Retrieval Graph (click on to enlarge)

    Making a Corpus of Code Examples

    We do the identical with one other corpus of p5.js examples written by Dan. To create the code examples corpus, we used Gemini and requested it to clarify what the code is doing. These pure language explanations are added as chunks to the corpus, in order that when the person asks a query, we attempt to discover matching descriptions of code examples, the url to the p5.js sketch itself is saved within the metadata, so after retrieving the code itself together with the sketch url is added within the immediate.

    To generate the textual description, Gemini was prompted with:

    The next is a p5.js sketch. Clarify what this code is doing in a brief easy manner.



    Instance for a code chunk:

    Textual content:


    Arrays – Coloration Palette

    This p5.js sketch creates a shade palette visualization. It first defines an array of colours and units up a canvas. Then, within the draw loop, it makes use of a for loop to iterate by the array of colours and show them as rectangles on the canvas. The rectangles are centered on the canvas and their measurement is set by the worth of the blockSize variable.

    The sketch additionally shows the crimson, inexperienced, and blue values of every shade under every rectangle.

    Lastly, it shows the title of the palette on the backside of the canvas.

    Associated video: 7.1: What’s an array? – p5.js Tutorial – This video covers the fundamentals on utilizing arrays in JavaScript. What do they appear like, how do they work, when must you use them?

    Moving image showing constructing the ShiffBot promptSetting up the ShiffBot immediate (click on to enlarge)

    Different ShiffBot Options Applied with Gemini

    Beside the lengthy immediate that’s working the dialog, different smaller prompts are used to generate ShiffBot options.

    Seeding the dialog with content material pre-generated by Gemini

    ShiffBot greetings ought to be welcoming and enjoyable. Ideally they make the person smile, so we began by pondering with Dan what could possibly be good greetings for ShiffBot. After phrasing just a few examples, we use Gemini to generate a bunch extra, so we will have a spread within the greetings. These greetings go into the dialog historical past and seed it with a novel type, however make ShiffBot really feel enjoyable and new each time you begin a dialog. We did the identical with the preliminary suggestion chips that present up if you begin the dialog. When there’s no dialog context but, it’s necessary to have some ideas of what the person would possibly ask. We pre-generated these to seed the dialog in an fascinating and useful manner.

    Dynamically Generated Suggestion Chips

    Suggestion chips in the course of the dialog ought to be related for what the person is presently attempting to do. Now we have a immediate and a name to Gemini which can be solely devoted to producing the prompt questions chips. On this case, the mannequin’s solely job is to counsel followup questions for a given dialog. We additionally use the few-shot approach right here (the identical approach we used within the static a part of the immediate described above, the place we embody just a few examples for the mannequin to be taught from). This time the immediate consists of some examples for good ideas, in order that the mannequin might generalize to any dialog:

    Given a dialog between a person and an assistant within the p5js framework, counsel followup questions that the person might ask.

    Return as much as 4 ideas, separated by the ; signal.

    Keep away from suggesting questions that the person already requested. The ideas ought to solely be associated to inventive coding and p5js.


    ShiffBot: Nice thought! First, let’s take into consideration what within the sketch could possibly be an object! What do you suppose?

    Options: What does this code do?; What’s unsuitable with my code?; Make it extra readable please

    Consumer: Assist!

    ShiffBot: How can I assist?

    Options: Clarify this code to me; Give me some concepts; Cleanup my code

    suggested response chips, generated by Geminiprompt response chips, generated by Gemini (click on to enlarge)

    Last ideas and subsequent steps

    ShiffBot is an instance of how one can experiment with the Gemini API to construct purposes with tailor-made experiences for and with a neighborhood.

    We discovered that the strategies above helped us convey out a lot of the expertise that Dan had in thoughts for his college students throughout our co-creation course of. AI is a dynamic discipline and we’re positive your strategies will evolve with it, however hopefully they’re useful to you as a snapshot of our explorations and in the direction of your personal. We’re additionally excited for issues to come back each when it comes to Gemini and API instruments that broaden human curiosity and creativity.

    For instance, we’ve already began to discover how multimodality will help college students present ShiffBot their work and the advantages that has on the educational course of. We’re now studying find out how to weave it into the present expertise and hope to share it quickly.

    experimental exploration of multimodality in ShiffBotexperimental exploration of multimodality in ShiffBot (click on to enlarge)

    Whether or not for coding, writing and even pondering, creators play a vital position in serving to us think about what these collaborations would possibly appear like. Our hope is that this Lab Session offers you a glimpse of what’s potential utilizing the Gemini API, and conjures up you to make use of Google’s AI choices to convey your personal concepts to life, in no matter your craft could also be.

    Supply hyperlink

    You might also like