Wrapping the Model in a Harness
00:00 Now let’s start to make this a bit more sensible. So let’s first define the model here so that we don’t have to hard-code it anywhere. And then of course, if you want to change it, you can easily change it.
00:10
So our model there becomes the global MODEL. Good. Let’s also create a while True loop. Now, what I’m building here is the harness.
00:20
So the infrastructure I’m going to put around my LLM. Instead of hard-coding the inputs, let’s say the user_input is equal to you are sending information to the harness.
00:34 Notice that I’m not sending information to the model yet. We’re going to see that the harness is going to be the in-between, between me as a user and the model and some other things.
00:44
So I’m going to be communicating with this while loop, which is the harness. Then let’s create our messages, if I can spell it, especially.
00:52
And this is what we had before, right? So I’m going to copy and paste that and I can simplify things here. And my content is no longer going to be that string.
01:04
Instead, it’s going to be the user_input. In the same way that I’m going to show the flow of information, you to harness, I’m also going to want to show this in several places.
01:15
So I’m going to define a bit of a helper function. This is just to help us see what’s going on, right? This is not needed for the harness itself. And I’m going to say there’s going to be a sender and the receiver, because we’re going to be sending and receiving information throughout the system, such as here, right?
01:31
I am sending information to the harness. And there’s going to be some text. And all I want this to do, this is just a helper function. I want it to tell me the sender is sending information to the receiver.
01:45
And here is the text. So nothing too exciting, but this means that I can now, for example, here say I want to show the trace() where the harness is sending information to the model.
01:58 Why? Because I have sent information to the harness. Now I want the harness to send it back to the model. And it’s going to, let’s say, sending a message. And now we can go back to what we had here and we can now say, let’s tidy it up.
02:15
That’s the MODEL. And the messages now, we can get rid of all of that because we have created messages. Now, we’ve already seen that response.
02:26
So let’s call it reply. Our response can give us our .choices. And we’re always going to take the first one. Typically, it’s going to be only one.
02:34
And that’s the .message. So that’s the reply. And now it’s the time for the model to send the information to the harness. And it’s going to say, here’s the text reply.
02:45
And instead of actually showing the reply, let’s simply show how long it is. reply.content characters. This is going to be text. We’re just getting a sense of how many characters there are.
02:56
And finally, we don’t need this anymore because now we’re going to replace it with, let’s print(), the harness is now going to pass on the message to me.
03:06
And it’s going to say, here’s the reply. Now, at the moment, the model is sending information into the while loop. Remember, the while loop is the harness.
03:16
And that’s what I’m showing here with this trace(). And then I’m sending it straight to me. And we’ll see that stuff can happen between the model sending information to the harness and the harness sending information to me.
03:28
But for now, let’s stop at this. So let’s run this code now. So now it says you to harness. And I’m going to say, what’s in the habits folder? And you can see that the harness has sent the message, sending a message.
03:43 The model then sent a message back to the harness. It’s 128 characters. And the harness gave it back to us. And it tells us something quite similar to before, right?
03:52
Of course, it’s not going to be exact because the LLMs will always give us something different. It says I can’t access the file system in this chat, so I can’t see what’s in habits.
04:00
It helpfully says you can list its contents with ls -la habits. So I’m going to say, can you run that for me? So once again, the harness, I sent it to the harness.
04:12 The harness sent it to the model. The model replies back and says, what would you like me to run? Paste the command or code here and I can help you with it.
04:21
And you’re like, what do you mean? You just told me you can list its contents with ls -la habits. It should be obvious. So what have you done in this lesson?
04:32
You’ve wrapped the model in a harness, a while loop that sits between you and the model. You’ve added a trace() helper so you can see every message as it goes from you to the harness to the model and back.
04:45 But the model still forgets what it told you a moment ago. In the next lesson, you’ll find out why and you’ll give it a short-term memory.
Become a Member to join the conversation.