Loading
Conversation 14 exercises
lesson

Build a Prompt Compressor Script

Create a new "Prompt Compressor" script by duplicating the "Add Script Header" script.

Instead of getting contents of a file and passing them in as the input when we make our first call, we're instead going to get the contents of an editor.

So we'll just switch the contents variable from `readFi

Loading lesson

Transcript

00:00 Let's duplicate our add script header. We'll call this prompt compressor. And now instead of getting contents of a file and passing them in as the input when we make our first call, now we're going to get the contents of an editor. So we'll just switch this over to editor. You'll notice that ScriptGate was designed in such a way that these inputs, whether it be files or editors or chats or microphones or anything, were made to be hot-swappable so that as you tweak your scripts you can change how the user interacts with your script.

00:33 So now for our editor we're going to paste in the contents of 1 of the prompts that are probably longer than they need to be like in our TypeScript quiz. This prompt is pretty long. And our continue adventure can probably be compressed as well. So in our prompt compressor we'll take the contents and I'll just paste in this prompt I prepared ahead of time. So I'll paste this in and it basically tells it to compress whatever we paste in but keep the same rules.

01:02 And then I don't want to write to any files once it's done so we don't need to worry about new script contents. All we're going to do is display the new contents in an editor and then we'll just copy and paste it back out. So I'm going to come into TypeScript quiz and I'm going to grab all of this, copy it, I'll run our prompt compressor, I'll paste this in, hit submit, and then watch it compress it down into something that's much easier and much shorter for the AI to understand. So I'll just copy and paste its output. Hit escape, escape, and then if we look at this, you'll see that this looks about half the size of what we had before.

01:43 And then if I run the TypeScript quiz, we'll see how it behaves, and if I need to tweak anything and add anything back. 1 thing it looks like I can fix is format the question with a markdown h2. So I'll try this again. And this looks pretty good. I can still hit 2.

02:03 It should explain it and then move on. And as with any prompt, a lot of the work is testing the prompt after the fact to see if you consistently get the behavior that you expect. So let's go ahead and do that with our continue adventure as well. We'll grab this, select it all, then run our prompt compressor, hit paste, submit that, let it generate the new prompt for us. We'll copy that and then paste this in.

02:32 And I'm going to manually add some line breaks at the periods just for readability sake. Then we can test it. I'll select a file, hit enter, and you'll see it's working as it did before. Then let's clean up our prompt compressor by getting rid of the markdown. Name it prompt compressor.

02:51 Change this to compresses prompts to save on tokens. And we can run our add script header to our prompt compressor. Let that generate a new header for us. We'll submit that. Let's fix that formatting.

03:06 And then that looks nicely formatted in our main menu.