0:00We're live. How about that? Hi Jonno.
0:04Hello Jeremy. Hello everybody.
0:06Very excited about today. Um though I guess I'm excited most of the time, but I think a lot of people really enjoyed the last lesson and it demystified it for a lot of folks. Um and so I'm really looking forward to continuing that um momentum.
0:26Fantastic. Cool. Well, before we start, one of the things we are trying to remember to do is to feature some uh student work and things that have been shared in the Discord. Um, so I've got one, Jeremy. Shall I start with uh start with that?
0:39I'm busy drinking my kombucha. So, definitely your go.
0:42We've been told to report on what beverages we're drinking. So, I've got pineapple, lime, kombucha today.
0:48Fantastic. I've got some gimma, some green tea.
0:53Um, yeah. I'm not sure why we were told to do that, but seemed like there was a consensus in the chat that that was mandatory.
0:59Um, all right. So, the one I wanted to show here is a dialogue that was shared by Marius and it was implementing this uh paper, this method called recursive language models. Um so to give the smallest possible overview of this idea um looking at language models trying to handle longer and longer documents in context. This recursive language models paper introduced a setup whereby the context itself is put into a ripple
1:28right some sort of environment some code environment that the language model can interact with. And so if you remember our tool loop example from the previous lesson that should start to already sound slightly familiar. Um and then they also enable the model itself to call a different version of itself in the same environment. So you can imagine given an extremely long document as the language model. I instead of reading it all might read the introduction and then I might uh call another language model to summarize chapter one and a second one to look through chapter two to see if there's anything relevant. So it's
1:58this kind of way of piecing apart the long piece of text without necessarily reading it all at once.
2:02So if I can just step back for a moment here. I know you're so used to this that you don't even think about it, but this is uh just to be clear, this is a report on a this is what you'd call I guess an a academic technical report. Um it's so breakthrough new early that it's not even written up in a paper yet. Um but these are from some um academics who are very well known in this space. And um as Jonah is pointing out here, the results of this are
2:32super interesting in terms of being state-of-the-art results. This thing was published less than a month ago um as this technical paper.
2:41Right? So this is a newb breaking technique that people are using and Marius took it upon himself to attempt to dig in and understand this by doing it practically in one of our students.
2:54Mhm. who is a radiologist by trade I believe.
2:57Yeah. Um and frequent sharer of cool things. If you go and search, you know, from colon on discord, you'll see some you'll see some gems. Um okay. So he's gone and laid out a dialogue. He started with a plan. We'll talk a little bit more about our preferred approach and you'll see that this is very much in line with it explaining what he wants to do using le lizette our library for calling LLMs and handling things like tool calls and so on. Um and then he slowly explored through uh frequently checking with the LLM. What do you think
3:26about this? Uh you know, how might this work? And then began implementing it in the very solvity style that you should hopefully start to become used to as we go. Trying a few things at a time, checking that he can create a chat model, asking a question, checking that he can create a shell, running a bit of code in the shell. These are pieces that should be somewhat familiar from the Clawudette version of the tool loop that we ran previous previous message. Um, yeah. So it was just a great example of
3:54working through a problem bit by bit, chatting back and forth with the LLM, getting small, you know, concrete suggestions, implementing them one at a time, looking at the output, and over time he builds up um the mechanisms to let the language model query the um variables that he has in the shell, uh run tools, um and then builds up and up and up until he gets to the kind of uh equivalent functionality to what's described in the paper. And so it's very much just an exploratory dialogue. You
4:23can see like if I if I zoom towards the the end um you know there's lots of like oh there's future things he'd like to try and there's different tests that he ran. Um highly recommend like going and reading through if this particular example um piques your interest but just as a general approach it was so satisfying seeing someone really spend the time to say how can I make it nice to look at the history? How can I make it nice to try out one piece at a time?
4:45What are the different bits I need to assemble before I can start putting those together? Um, and so yeah, just a fantastic little example of taking the ideas that we're showing and building on them and iterating with them to create something that looks like a really nice implementation of a cool new technique.
5:02Um yeah, I feel like you're kind of understating how amazing this is to me at least that um this you know part of part part of the reason I say that is that uh originally this paper was implemented in a super sophisticated um system called DSPI um which is literally the result of a PhD by one of the authors of that paper.
5:29um and Barius has reimplemented it without any of that machinery and I think in a way that's actually probably ended up more clear and readable and I think it really shows that um again it's demystifying these things you know these like wow amazing breakthrough from MIT things are actually stuff that you can absolutely understand you can read the paper you can have solve it help you work through it put the paper in the context ask questions and you
5:58know maybe we'll do a bit more. We will do some more of that kind of like um reading technical documents and papers and working through them with solver showing some tricks for doing that later. Um yeah, something else I'd like to share I think Jonno is um just some comments we got from the Discord that I found interesting.
6:25Um uh so I just uh yeah interesting to see some of the um comments we were getting uh were very consistent about the homework um which is uh oh yeah doing the homework. Wow, that understanding I thought I had was an illusion uh by doing this assignment. We, you know, had
6:54to come to terms with the concepts, but we could get help. Um, and so it's kind of nice, um, clicking through on these to see, um, how folks solved it. Um, I have the same feeling. It's easy to think you've understood, then you have to do it. I like this one, Jotto, your reference to advent of code problems. If you remember you said like oh look doing building an agent's actually like
7:23solving advent of code. It's like yeah you're just creating converting some structure into some different structure. It's that's basically what computers do. Uh I I was thinking I was solving problems of elves. I was actually solving agentic AI. Um and so they tried making it in Gemini which is nice. I like this idea of like do it in a different platform that really tests things out for you.
7:46Um, yeah, your message resonated so much with me. I thought I'd understood it. Sat down to implement it. Couldn't believe how little I knew or remembered.
7:55So, congrats to everybody who has I'm not going to say completed the homework, but just um had a go at the homework. Um cuz even if you don't finish it, working on it is helping you learn some of those concepts and and be aware of the ones that you thought you knew, but actually you you didn't. And if you do get stuck, of course, feel free if Solvent can't help you, come and ask on the on the Discord.
8:23Cool. Before I forget, Jeremy, so that homework that you'd assigned of the tool loop, um, if you're interested, I think we'll also at the end of today's lesson, have Jeremy walk through finishing that out the way he might do it and show some things of that approach.
8:38It'll be like very much like how to do the homework in general, where the homework includes like make sure you can fully understand everything that happened in the lesson.
8:48So, if you still are really want to try it yourself and you haven't done it yet, you're welcome to pause towards the end of this. we'll give a spoiler warning.
8:54Um but yeah, that'll be coming up.
8:56Um fantastic. Okay. Uh before then though, the plan for today's lesson is to slow down a little bit in terms of trying to do brand new things, although we've still got plenty coming in the pipeline and instead to dwell a bit more on the solve it approach and the problem solving technique behind it from George Polia. Um going back to an advent of code problem. And so I'll talk a little bit about the general approach. I'll show some fun tricks around it and then we'll start working through the problem.
9:25And the way it's going to go is that I'll be um staring and I'll be doing the actual coding and trying little pieces.
9:31But hopefully um Jeremy will be able to chime in at different points and show us maybe some different ways of doing things or have some discussions about um the thought processes that are going on behind the actions and why we might want to do something slightly differently. Um so there'll be a bit of back and forth.
9:48All right. too clever then it'll be hard for me to add anything.
9:52Yeah, I'll try not to I'll try not to just uh do the perfect solution right off the bat. That's my excuse everybody. If you see me making a mistake, it's all part of the plan. Um all right, so um who on earth was George Paulia? Um I've shared this link once or twice already. It's a gift that Jeremy made a nice summary of what is a fantastic zoom in didn't zoom in I don't think.
10:12Ah yes I'm zooming in on Zoom instead.
10:15Um okay so this is George Pier's how to solve it and at the core of this approach which he develops for mathematics but which applies really well to coding and many other things as well is this kind of four-step framework. So step one is to understand the problem and in software this can mean um getting specifications externally. So like for advent of code we'll get a problem about the elves and we'll need to solve that or it could be figuring out for yourself what it is you're trying to achieve. Um, then devise a plan. And this could be I know
10:44exactly how to do this. Or it could be at least I can see some first steps. But before you start diving straight in, having that thinking about what am I trying to do? What pieces might I be doing along that journey? Uh, then executing that plan, verifying each step, keeping track of what we're trying, ready to start over, and retweak it if we need. And then finally, when we think we finished, um, rather than just stopping there, spending some time looking back, reflecting, uh, checking
11:13our results, seeing if there's other ways we could have done it, and picking out lessons learned that'll help us for next time. So, this four-step plan is something that I'd like you to keep in mind. I'll also bring it up again as we work through this. Um, but we're going to try this out in a in an Advent of Code problem if that sounds good.
11:31All right. So I'm over here in solve it now and I've got a almost blank dialogue um with one somewhat magical little snippet of code. And so I'm going to run this and then spend a bit of time talking about how it works and then we'll get into the problem proper. And the piece of magic here is that we want to practice what we're doing on advent of code problems and there's a number of them. And so I've made something to make it just a little bit easier for me to get started. I've executed that code and I now have the bones of a dialogue. It
12:01has a title for the day that I'm working on. It has an introduction note both telling solve it a little bit about me. I'm Jonno. I'm working through this for practice. Uh this is my level that I'm at. And then also a note to myself. These are the four steps from Polia that we're trying to practice and ingrain into ourselves. Understand the problem.
12:19Devise a plan, carry it out, and then reflect. And then I also have the um pieces of code that I would like here. Um, so hopefully you can see my key caster showing that when I run these I'm holding shift and then hitting return. Um, but maybe not. Um, okay. So, it's not all um keyboard shortcuts, but a number of them.
12:41If you go into your keycaster settings, um, you can um, tell you what one you want.
12:50Oh, yes. This all keys are all modified keys.
12:53all keys because modified it doesn't think shift and alt are modified keys.
12:58Cool. Um, okay. So, to step back before we dive into today's problem that we're going to be looking at, I wanted to show you how this little piece of magic worked, right? Because I was able to get this scaffold up and running. Um, and so you could do this just by having a dialogue like this. And when you want to work on day five, you could use the duplicate functionality. Um, but what I've done instead is create this dialogue called AOC utils. And this is a place for me to just put the pieces of code that I think might come in useful
13:28and that I want to use again all in one place. Okay, so the way this works, we have some exploration of the kinds of things I want to do. Right? So in this case that's getting a puzzle, figuring out how to create a link to that puzzle, figuring out how to get the description of the puzzle, and then um checking can I add a message to a dialogue, right? So you can clarify normally like something like this you wouldn't start by saying like let's write AOC utils but instead
13:56you would like solve an AOC problem and then at the end you might like duplicate it rename it to AOC utils and then delete the bits that are problem specific and you kind of end up because I think a lot of people think like oh J is so clever that he could design ahead of time exactly the utilities you'll need in the future but generally these come come out of this process don't they?
14:16Yeah. Yeah. Exactly. So this is not something that you would necessarily construct all at once. It's like I started it as just a scratch pad. So I'm testing out can I get the puzzle data?
14:25Can I add a message? Then I started um trying out one piece at a time. Um but then slowly I've grouped these back together into um sharable pieces that I would like to use elsewhere. Can I mention a trick Jonno that a lot of people might not expect to work but in the future if you do another AOC problem and you like oh that's another cool thing I'd like to add to AOC utils you can click on the message press C to copy
14:52it and then go to the other dialogue and press V and you can actually paste it to a different dialogue um that way and so that way you can add it to your AOC utils.
15:05Exactly. Um, yeah. So, this is my setup function. It's adding those various messages that I wanted. And you can try this one at a time and check that they're working. I've just grouped them all together. Um, and it can also describe can also define certain functions that I'd like to use. Right?
15:22So, this describe function here takes an input, shows how many characters, how many lines, and you can see importantly, I've clicked this little um icon here. This will be exported. I could also use the keyboard shortcut E. Um, and I've done this for all the pieces that I'd like to use.
15:38Yeah. Um, so this little um the import section and then these definitions of describe and setup. And behind the scenes, what this does um is it creates a Python file on the disk. Um, I might also have to reconnect. I wrote this all earlier today. Let's just double check.
15:58There we go. So this dialogue here is called AOC utils and that's stored as an IPython notebook. Um but because I have some messages exported, it also creates this AOC utils.py file. And if we look at what's in there, um you'll see that it's just those functions that we clicked to be exported. The imports defining the intro and then our two functions. So behind the scenes what happens is basically
16:26every time you uh run a message or change whether a message is exported it automatically resaves that.py file um which Jono will then be able to use later.
16:37Yeah. So I highly recommend um fiddling around if you start to find yourself using the same piece of code over and over again. try chucking it in a utils or a my cool code dialogue and then you can import that by making sure that whatever folder it's in is in your path and then importing the functions that you defined.
16:56Okay, so just go a bit slower there. So that's that's a key point there. So in this case the AOC utils.py file is in the same directory as AOC 2023d4 lesson.
17:07Um and so therefore you're saying I want to be able to use modules that are in this path. So cy.path path contains the list of all of the folders where modules can come from. Um, and so that's why you added it to CIS.path. And that way you were able to say import, sorry, from AOC utils import star and AOC utils then is going to find that AOC utils.py.
17:34So you could put it in a different folder and you you wrote slash app data because that's actually on solver your that's your home directory.
17:43Exactly. Um, all right. I don't want to run this again, so I'm going to hold mention um, uh, I often use a slight different approach, which is I have a for my advent of code, I just have a dialogue, which I call kind of AOC template. And, um, I just hit D, which duplicates that dialogue. um rather than having that kind of setup process. I don't think either is better or or worse, but having a template is quite an easy way to kind
18:11of keep the notes, prompts, and code that you want to reuse. Then you can just edit the template and hit D again to duplicate it and then rename it.
18:24Exactly. So um to describe the problem I have as part of my um setup added this can you describe the problem concisely and can you put the sample data in a variable for me. This is extremely lazy.
18:39Um we could also just read the background and the problem here I will spend a bit of time uh attempting to describe it. We can skip a lot of the preamble about the islands, but the idea is that we have um some amount of cards, right? You see here we have six cards. There's a list of winning numbers and then a list of numbers for that card.
19:02And they would like us to say um which of the numbers appear in the list of winning numbers. And then for every match within our numbers that appear in the winning numbers, we're going to get a point. Then the next one is going to be two points. The next match is going to be four points. there's going to be some sort of doubling value there. Um, and so they show exactly for that sample what the scoring looks like and what the expected outcome is. So for the first card, we expect that to be worth eight points and after adding up all of them, we expect 13. Um, so this is our overall
19:31problem. And if I go back to solve it description looks very similar and so this is relatively easy to understand at the algorithmic level. I think a lot of the trickiness in this problem is going to come down to extracting those pieces of data efficiently and then implementing what we can already kind of understand from the description. So I'm going to hit W to take all of the code blocks out of the prompt response and put them as a piece of code.
19:55So I'm not sure that much before, right?
19:56So that W thing, it specifically refers to outputs. So either prompt or code outputs and it's specifically referring to those kind of gray background areas which um uh are actually fenced blocks. So they pull the fence block out and put it in a new message for you.
20:17Right. Um okay. So we've got a bunch of data here. My plan I'm thinking through is to extract the card number, the winning numbers, and then the cards list of numbers. So I'm going to do those one by one, and I'm going to do those using just some very basic pieces. So I could start by saying, okay, let's get one card, right? So I'm going to get my sample and I'm going to split it and then I'm going to check that I have what I expect. I have a list of one line for
20:47And then I'm going to work on one example first. And so this is a piece of notation that we use um to be consistent throughout all the advent of code problems and many other problems that we're working on. We want to just test it on one example first and then we want to work through on that and once we're happy we can do it to all the examples and and we can work with the rest.
21:08Right? So I've taken my larger problem. Here's my list of cards and now I say just for this one card or this one X I want to see can I get the card number.
21:17Right? Right. And so I'm hitting slash to focus the editor at a new cell at the bottom of the dialogue. And I can start by saying x.split. Uh let's see. Let's split on the colon. Um and then let's get the first item in that list. Okay, that's looking promising. Then I want to split out um just the second half of that to get just the number. And then I want to turn this whole thing into a number. So I can
21:46turn it from a string to an int and then I can call this the card number and take a look at. So in my head my larger plan is pull out the card number, pull out the winning numbers, pull out the total all the set of numbers for that card. Um we're making progress, but we're doing it very iteratively. I could have done each of those in a new um message if I wanted to string it out, but because I'm seeing at each point, first let me look at X, then X.Split,
22:14split then x.split split zero. You know, I'm building up this expression. And at the very end, I can see, okay, is this what I wanted? I wanted this number here. That's what I got. Ready to move on. And so, we can do the same thing for It was interesting the way I like like I I think we discussed this last time as well, the way you kind of like created the first little bit, you know, of like dotsplit. And then you just edited that out, you know, edited that to add the zero and then edit that out to at the end. So you're just hitting enter, shift, enter, enter, shift, or command
22:43enter to kind of build it up on a single line. And so I guess there's, you know, the you then you then you stopped and added a new line. So you don't want to like build up too much into one thing, but just until you got to a point where you've got a kind of one nice working piece.
23:02And some something here like, okay, I want these to be integers. Um, okay. Okay. And one other piece of polio wisdom that was one of his many heristics was looking for pieces that you can reuse and a lot of this here is going to be very similar for getting these numbers versus getting these numbers. So I can copy that whole cell with C and then V. And then I'm going to use these to just get the numbers. So I'll be a little lazy with my naming here. Um
23:31and it's fine to be lazy lazy with your naming because there's no way you're going to forget what ends equals. You know, you just did it. So Mhm.
23:39you don't have to write enterprise code when you're doing stuff like this or indeed even if it is enterprise code if it's within you know one function and it's only used in that function. Keep it concise.
23:51Also you got duplicate code which again is totally fine right because Mhm.
23:55it's only there twice. It didn't take right. If it was there five or six times maybe I'd start thinking like oh I should uh do something else. And like as soon as you had like a weird bug in one of them or something, you know, and you had to keep changing it lots of times, you might consider factoring it out. But yeah, there's this kind of view of like don't repeat yourself, DIY, but actually don't repeat yourself too much should be the rule.
24:24So I'm going to now combine these into a single function, and I'm going to be extremely lazy and ask the AI to do it.
24:30Um, and you might say, well, isn't this going against what we just said of not having the AI write all the code for you? But if you take a look at this code that the AI has given us, it's not. It's exactly the code that we've already written. We've already executed those pieces in parallel. Um, and so it's not doing any thinking for me. It's just tidying up and redoing and combining.
24:50And um, Jeremy, you know, this was a extreme extremely lazy case. You could just as easily have copied the cells and merged them. And we can show that, too.
24:58Yeah, I just wanted to show I tend to like use the the comma shortcut which which copies the code and then I kind of go paste and then copy and paste, copy and paste. But um I definitely agree it's a great use of AI as well. And something that I would tend to do there is I would hit on that um that prompt you just had on that split card prompt and I would hit O to kind of collapse out the output of that because it feels like something I just we don't need to see again, you know, we don't need to see the duplicates.
25:25Yeah. So that's in fact if you wanted output or toggle collapsing output and I to toggle toggle collapsing input and if you combine that with shift shift O collapses output a bit. It collapses it to about half the screen and gives you a scrollable area. So you'd have to first of all uncolapse it Jono with O and then shift O. But that's so small it won't you can't see.
25:48But that's for like So those are the options I shift I shift O to help you be able to see more at once on your screen. And if you wanted to, you know, pretend that you never had that moment of laziness, X to delete or cut. And then it looks like I wrote this uh beautiful function by myself.
26:05A lot of people are using shift D to delete, which indeed you can. So if you click on the little I with a circle, Jonno, you can actually see all of our keyboard shortcuts. Um it's just to the left of the upload button. Um so it's behind the zoom.
26:19Um and so shift D there will actually say delete. We're seriously thinking of actually getting rid of it because there's really no reason to not use um X all the time because uh X is not only does it delete it, but it's now in your clipboard buffer. And if you're like, "Oh, I didn't mean to delete that." Then you can just press B to put it back again. And it's a bit easier to press than shift D as well.
26:40Cool. Um Okay, so Jeremy, I'm happy to keep on working on the solution, but I also wondered if you wanted to show maybe some other ways we could have gotten the same amount of data out of that string. Okay, no pressure. Um, while you're doing that, I actually did pop the same thing uh into a variable um and I've even imported something that I think we're going to want. Um, I mean, a couple of minor things I would say. So, I really
27:08what you did was yeah, ideal. Um, so I'm in concise mode here. And in concise mode, it automatically gives me these um called ghost text. Um, um, and it's doing a good job of guessing. Um, and yeah, just like Jonno, I would always immediately have a look at it. Um, and I would immediately just grab one of them. And
27:37again, it's pretty good at guessing what I want to say.
27:41Um, and what I'm doing here is I'm actually pressing um, alt enter. And so alt enter is actually um, showing me my results straight away. And you can see here it's like this actually looks like I intended to show you this. I didn't I did have a bug and I've immediately found it. And the issue is that after my triple quotes, I had a a near line, right? So um, it's like, oh, okay,
28:07great. So I could do a um strip. Um and the nice thing is like you see Jonno and I know Python very well. So we just write what we think. Um but it doesn't matter nowadays like syntax is pretty easy. You can just say how do I remove the space from the start and the end and it'll say use strip. How do you split it into lines? You split lines. Um so now I rerun those. So one minor thing I would have done differently here is I tend to
28:34kind of say like you know first bit second bit uh equals um line.split split, you know, um, uh, probably even on the space as well, you know, FB, SB. And that just saves me a little bit, the kind of I like to just the way I think about it is how can I make it a little bit simpler than it was before. So, I wish those were in two
29:04pieces, you know, and so then I'd kind of have like, oh, you know, second bit one, second bit two, because I don't want to think about the semantics too much yet. So, I'm just going to write it out here. Um, and yeah, it's exactly what I want. Might as well pop the space around it as well. Um, SB1, and it's it's just right arrow to accept the ghost text suggestions. And so as I do it this way, it's like each time I'm just like that's slightly more
29:31convenient than before. And now I think I'm ready to do what Jonno had, which what did you call them? W's C's.
29:39Yeah. W's for the winning numbers.
29:42So now W's is just the second bit. One dot split. Um and the uh numbers equals. And here I'd probably just press um command shift full stop and um it might even yeah just do the whole it didn't quite do everything for me. Uh try it again. So command shift full stop is like ghost text but it's the I feeling lucky version. So I hit it again and the nice thing is it sees my whole dialogue.
30:09So at this point it it gets the hang of how I like to write things. Um okay. So there's a few things I can do.
30:18Um, one thing I might introduce at this point is to say um there's a nice thing called um capital L which um comes from um fast core which I imported at the top here. Um and if you're wondering by the way why do we leave this at the bottom rather than like having edit in place, this is why is like I can grab stuff and copy stuff from other parts of the dialogue and pop it into my active
30:46thing. the active thing's always sitting there, right? Um, so I'm going to go um L.Split.
30:54And if I press um alt full stop, that forces the ghost those text to pop up if it didn't pop up for me. Um, so then here I'll just do the same thing. There you go. It's guessed it for me. And um, it it does basically L is just a normal list but with some special features. One thing is it it prints more nicely um as you see here. Um and another thing is it has some nice little
31:22additions. Um one of the additions it has is map and it already guesses what I mean. Um now mapping this is just it's this is not some like minor arbitrary thing. The idea of like taking a list of things and doing something to everything in that list is like a fundamental part of a type of programming called functional programming. Um, and it's one of the key ways I tend to work. It's
31:51like do something on one little bit and then map it over all of the bits. So map means apply it to everything in that list. So apply int. So just if you're wondering what is int, um, you can just try it, right?
32:05It's a function that turns a string um into an int. So here we split this into a capital L which is a kind of list and then each item in that we map the int function over it and we end up with a list of ins. So that's like one thing that I would kind of do slightly differently. In real life though I probably wouldn't do um any of those
32:30things. Um, instead I'd probably have a look at this data and say like, "Oh, that's interesting.
32:41They all kind of have a certain pattern here, right?" And um, I'd kind of copy this, right? And I'd say, well, what if we used regular expressions?
32:53Um, so there's a thing called find all in the uh regular expression. And so I just hit tab there to select one of those suggestions. Um, and if I uh, and so if I'm not sure what find all takes, I just hit shift tab and I can see, okay, it takes a pattern and a string.
33:11So the pattern is what I'm going to um, uh, look for. Um, and I'm just pasting this. You'll see why in a moment. And what am I looking in? I'm looking in the data. And then it's like, okay, I'm looking for a card, but I don't want just card one. I want card followed by actually any digit at all.
33:37Um, now that backslash in Python has a special meaning in a string. So like back slashn is a new line. So if we make this a reject string or a raw string um then it's basically saying okay don't don't treat backslash specially right. So okay look for a backslash d and then look for and then square brackets means um anything I'm typing in here. here. So, I want a back slashd or a space.
34:08Um, and so I want a whole bunch of those until I eventually get to the um pipe sign and then all that. Again, I'm going to explain all this in more detail in a moment, but I'm just going to give you a sense of how I tend to kind of build this up, right? Um, and then finally I need to say like, okay, I want to kind of save some of those sort of. So put things in
34:37parenthesis to save the bits that I care about. Um, and you'll see here when I ran that, um, absolutely nothing appeared to happen. So the reason that absolutely nothing appeared to happen is because my uh regular expression didn't match. So this is a really common problem. And so what I tend to do then is I go back and I make something that is as small as possible that I'm pretty sure will match. So if I
35:18run that, you can see how my regular expression works, right? It's looking for the word card followed by a space and then a digit and it's found in my um oh sorry my regular expression did work. I just realized it printed all out. What did I say it didn't? That's so funny. Somehow I imagined it didn't work. Anyway, if it didn't work, this is what I would have done. I was hoping it didn't work the first time. Uh, so if it
35:46didn't work, so if I put for example a X here, okay, that's what it looks like when it doesn't work. Um, and so the way I fix it when it doesn't work is I create the smallest version I can and then I gradually add more and more to it, right? So then I'd be like, okay, then I'd add this. I'd be like, oh, the X was the problem.
36:08Okay, so let me explain a bit about regular expressions. Um, and I'll also point out something interesting here, which is that if I add a message above this one, then the AI can't see the one below it. And if I type refind all and then I write data and then I write like parts equals and then I like hit uh alt full stop.
36:35Um, look what it's done here. Um, the the AI's actually done it for me. Um, and it looks like it's basically done the same thing as I did. It's just been a bit clever. Instead of typing space, it typed back slashs. Um, if I change theirs, does it look basically the same then? H, it's a bit more clever, but on the whole, it's basically the same.
37:03So actually, you know, this is a really good use of AI as well is just to save you the bother. Um, but I'm still going to teach you a bit about regular expressions, even though AI is pretty good at writing them. Why is that? Um, because regular expressions appear everywhere all the time. Um, and um, for example, if I wanted to do a search and replace right here in this
37:30editor, I can press command F, and that button there means to search and replace regular expressions. Uh, or if you use Vim or if you use Emacs or if you use VS Code, they all have set regular expressions. In um, Linux, you can put in the CLI rename space and use a regular expression to describe how to rename your stuff. they just appear all the time.
37:57So I would say knowing the very basics, which is what I'm going to teach you now, um is super convenient. Um and Jono is somebody who keeps claiming to me he doesn't bother spending time learning regular expressions, but actually he does. And I'm like, well, do you know what dot is? Do you know what star is? Do you know? He's like, yes, yes, yes, yes. So I'm like, yeah, you know, you definitely know enough. We we we had some really interesting conversations around this as a group
38:24with answer AI because on the one hand it feels like I never need to write one by hand again, right? So I was saying to Jeremy like, "Oh yeah, I can just describe I'd like the card number and then the numbers on the left and then the numbers on the right and AI can reliably write a regular expression for that." Then in the other I do benefit from knowing when I see a regular expression what some of these symbols do. So it was this weird thing of like should we teach this because we'll still get value from having this knowledge.
38:51You could argue that it's feels obsolete like knowing how to calculate by hand.
38:56Um but then you know you end up either throwing up your hands and saying well we won't teach anything because we have calculators and computers or you say hey this comes up enough right addition comes up enough that it's worth knowing how to do addition. regular expressions for a lot of us coders come I use it multiple times per day just in my CLI in my editor in my whatever and um one person commenting out commenting in the chat is like oh I find them write only I
39:23can't read them um so just another perspective I can read them instantly so like they don't have to be right only that's just practice um and so I can immediately say oh look for card just reads left look for the word Then look for a space. Oh, one or more of them. And then save one or more digits. Then look for a colon. Then look for one or more spaces.
39:49Then save a bunch of digits or spaces. Like you just go left to right slowly. Right? So these are the bits you you need to know.
39:59Um, in fact, if we head over to Reax 101, um, you can actually type in a regular expression here and it will explain it to you. So, if you get something from your AI that you don't understand, you can send it over here and it'll explain like with color coding what each bit is. So, there's a capturing group. This is something that's saved and this here colorcoded
40:28matches a digit plus matches the last thing. So a digit one or more times. So this is quite a nice way to get a a visual thing. Um so basically the pieces that I think you want to know would be so let's create a string here maybe see 959
40:54A a Z zed. Okay, so reind all is a great way to learn regular expressions. So shift tab shows me again what my options are. So shift tab uh find a pattern. Okay, the most basic one to know is dot. Um and so this finds everything that matches dot. Now dot actually in regular expressions means anything at all. So everything matched.
41:25Uh or let's put an R here. A digit. The digits matched. Or um oh let's add a space into here. Okay. Or um basically anything if you capitalize it pretty much becomes the opposite. So not a digit or s a space. Um so I can say a digit and then plus means one or more times.
41:57So it tries to clap them all together, right? Um so yeah, this is uh these are the key things I think I would want to know would be dot plus also I would want to know star which means um zero or more times. Okay, so in this case we've had a bunch of zero length strings. Um, and then I'd also want to know square brackets, which means just a list of possible things. So, find anything that's either a C or a Z one or more
42:28Okay. Um, and you can put things like back slash D in there, too. So, find either digits or Z. Um, so those are the pieces. Right now, I went pretty quickly because you can rewatch this and you can play around with it. But um so just to list them out, I reckon you should know dot. Um you should know back slashd, you should know square brackets, you should know round brackets, which means save it for later.
42:56Um you should know star, you should know plus. Um oh, we didn't mention this, but back slashd basically means like a word character. So a number or a letter. Um, oh, also in square brackets, I didn't mention this, but you can also put ranges. So, to find any capital letter, you could say A to Z. Would there be any others that you feel like are worth knowing for most people?
43:23What comes up pretty often is all like spaces or new lines or tabs. Yeah. So, that would be back slash s, which is any type of white space. Yeah. or s back sl any type of new line or space or tab character. Yep.
43:39And you might have noticed they actually used the AI used back slash s instead of space. I find space easier to read and everything here is a space.
43:46So often AI gets a bit overenthusiastic about making regular expressions too complicated.
43:53Um anyway, the nice thing is now um is that I can now say parts equals this.
44:00look at my parts and then I can say, "Oh, cool." So, what I can now do um is I can say, "All right, let's grab a single part." So, I'm going to do exactly what Jonah did before, right?
44:20Um and we can kind of work through it quite slowly, right? So we can say like okay uh card number comma win comma you call this uh n yeah equals part right and so then I could say like all right CN actually is uh int c
44:50um and then let's remind me w so now cn comma w just to remind us where we're up to. I have a pretty bad memory. So, just kind of like to look at that. Cool. Now, I'm basically up to where I was before, right? So, I could then say, cool. Uh, L do split W do map int. Um, and we got it back up and running. So, back to the same place.
45:22Yeah, I think that's about all I have to mention. Jonno, was that position? Yeah, that was great. Um, a couple of pieces to add. One, this was using a specific library called Reax, which is in many ways better than Python's built-in library. So, if you didn't see Jax here, I just the default one.
45:42Yeah, I can show reax. So, reax would be like rejax dot uh find it. Um, and so yeah, you can do something a bit more fancy with that. You can say like uh um
46:00um no maybe I won't do it now. We can come back to it later. Yeah. So with with rejax if you want to play with it at home we could have we could have avoided the whole split thing and basically done the whole thing in a single rejax which would be and actually maybe we can just refer people to I think it's lesson four of last year where we might have done the same problem using rejax. Um, okay. But there's a good library this because this is an L. That's that's the count, right? So, the reason this is super nice, for example, is when you then print it out for all of them, you
46:30can immediately see that they all have the same count. It's really I found that really handy.
46:35And Jeremy, is it fair to say that fast core is in some ways your utils.py developed over many, many years of Python programming with lots of other people contributing and building up pieces. I mean feels like but it's also so I wrote the um kind of main functional programming RFC's for PEL back in was that late 90s early 2000s mid early 2000s um like it's it's
47:05also kind of like and it's not me it's like much smarter people than me over decades have figured out kind of the core components of a programming language which make it easier easier and more ergonomic to use.
47:18So, it's largely me trying to bring those into Python. Um, uh, but yeah, probably some parts of it are, you know, quirky Jeremy idioms, but on the whole, it's all stuff that comes from, um, people who are, yeah, much smarter than me and have figured this out over a long period of time.
47:39Fantastic. Um, okay. So that was a good diversion, but I think the whole point of doing these advent of code problems in some ways is to embrace those diversions, learn about something new, say, "Hey, could you teach me about reax?"
47:51Um, I'm going to drop back into the problem now and um ask um just remind ourselves what we're working on and what we want to do next. Um but I think it was something like we have these winning numbers and we want to count how many we want we of of those winning numbers we have an R list of numbers um how many numbers match winning numbers for a particular card
48:16um okay so let's let's do that then um so I could say I like it suggestion of using a set and again this is something where maybe people some people haven't used sets and set operators before and this is a whole interesting rabbit hole. Um, worth diving into, right? Okay. So, shall we spend a little bit of time on sets?
48:42Curly brackets to be a set.
48:44I want to show a list. Oops. Right.
48:46Um, so I could do this. So, we have regular lists in um, Python can have duplicate entries. Um whereas if we made a set of that we would see that it only has one occurrence of every element in and it's been sorted too.
49:04And it's been sorted. Yeah. So I'm going to call this um S1. It's one set. And if you would like to just create a set straight away, you can type um like Jeremy said, the curly brackets. Um so here's a set that has two like a dictionary but without the colons in.
49:20Um, and then this, um, and I should have actually printed out set one just so that we could have a visual reference for what's in there. Um, yeah, sets have a number of useful operations. We could check if something is in a set. Um, so we can see if one element is in there. Um, but we can also start to do operations on them.
49:47So list as well, by the way. And I'll just mention it's which is fine. It's um it is faster if you make it a set. Um but both would work.
49:56Um but if you wanted to ask a question like uh what are all the elements that are in S1 but not in S2 uh sets let us start to do these kind of um you might remember from maths sets with the intersection and the union and the difference. Um union would be um all the elements that are in Excuse me. Um, in S1 and S2, like what are the ones that are common to both?
50:26And then pipe is union.
50:28Yeah. If you wanted S1 or S2, so anything that's in either one of those two, we'd get the uh the full list. It's a very very useful data structure. Okay.
50:38I was just going to say it's it's like this is another of these places where it's like, okay, this isn't just some kind of arbitrary list of things that somebody decided to do. Um basically the entirety of modern mathematics is founded on set theory and this is implementing set theory and um so to give you a sense of how important this particular set of operations is. Uh it's in some ways it's the most important set of operations we
51:09Um fantastic. Okay. So let's see how to use this. We want to say how many of our numbers are in the set of winning numbers. So I could say um create my fine to just rename this.
51:25Um and then let's test 83.
51:37Okay. So now we want to do something for all the um items in our list, right? So or ns and I'm going to start just by looking at it. Um and actually yeah, let's go. These are each number for the set of numbers that we're wanting to test.
51:56So let's just talk a bit about list comprehensions. Um so so this this notation is kind of an alternative to the LM map kind of thing.
52:07Um the list comprehension notation um allows you to loop through what's called an iterable. So a list for instance and for each thing in that l iterable you can decide whether to keep it and you can also change it in some way. So in functional programming they're called the map and filter operations. So the list comprehension is Python's built-in way and it's very elegant and very neat to do list and
52:36filter. So here Jonno's done a filter and the way you do it is you write blah for blah in blah if blah. And so each of those blas is a thing. So Jonno's written n greater than 50 in the blah section there.
52:54That's very confusing because you got in twice even though it's quite correct. So those two ins are totally different.
53:01Yeah. Yeah. So this is the condition that we're checking and this is the kind of a loop that we're doing.
53:07Yeah. First n is where you put the map if you wanted to. You could like add one to it for example. Maybe Jonno. Yeah. Maybe to go back to that if n greater than 50.
53:15Uh because that's a bit less confusing.
53:17And maybe put an n plus one at the start.
53:20Um so there's just n and here's now n * 10.
53:24Right? So we could do some operation to everything in this list that matches this condition. Um yeah so it's very powerful and like Jimmy was saying so I could also from fast for utils import list and then say you know end is equal to l um oops we got a colon there and then I have my ends as a list and
53:50then I could do ends dot um filter this takes a function right lambda and lambda. Little moment of dyslexia there. Excuse me.
54:10Um there we go. So we there's many many ways we could um approach this. If you want it to be really fun, um you could I think there's a if you type in and then press um command I just just empty all that out. Started just start again here. So empty out your whole editor and well yep type in and press command I. That will give you a list of possible
54:39matches. See there's an in underscore.
54:42Um this is quite fun. So another cool thing from from um functional programming from a guy called Haskell Curry um is this idea of currying. Um so we actually have these what's called curried version. So if John if you type in open bracket and then what are you searching in is it uh we're checking if it's in W's but we're searching in actually wasn't it searching in Yeahs.
55:06Yeah. So if you do W's and then close parenthesis and press uh shift enter that doesn't actually do anything. it actually returns a function. So you could actually say uh ns.filter in w's that way. So I'm not saying everybody has to follow this but just to give you a sense of like there's a lot of interesting ways to think about programming.
55:32So this is called crying if you want to check it out. And um fast core provides curried operators. Um, okay. So, let's say we have, let's see, we had the card number, we had the winners, and we had the numbers. Um, we want to get the um the I'm just going to do this all in one.
55:58So, we want return leng the number of this except that we need to make sure that we convert W's to a set. We make sure that ends as a list, a fast score l, excuse me.
56:14You don't actually have to convert it to an S w into a set here, but I fine because works with oops. If we feed in our card number and the W's, we should see hopefully the number four. Um, okay. And then the actual um advent of code thing, I think it said if there's one match, you get a score of two. two or a score of one. Two matches you get a score of let's just
56:44Um first matches with one point and each additional match doubles the value.
56:49Um okay you could use two to the power of I guess. Yeah. Two to the power of um this in matches that's going to give.
57:04And I will mention somebody in the chat is going a bit crazy watching you do this. So let's mention that the um much easier way to do this um is to go NS amperand WS because saying what things are in both sets is what amperand is.
57:21Yeah, we we we were doing it a number of ways and this was the uh this was the end of the stack. My apologies to all trying to follow along. Okay. Um so I'm going to do a little trick here and and um ask for some reflection. Um and then I think we can put it together.
57:39Um okay. So this has caught a little side thing which is what if there's no matches? We're going to get a score of 0.5 and in the thing it says one. Okay.
57:51you wrap this um count matches and a solve one a function. Um we've done the individual pieces so I'm going to once again be a little lazy and then we can um work on two.
58:13Now one interesting thing there is you hit W. Right? So, if you press down, you'll see there it's created two cards because there were two fenced books.
58:23I'll just mention, by the way, we talked a lot about tools last week.
58:26Um, I actually don't use tools very much anymore. Um, I find using W nearly always better because I can kind of like adjust the thing that comes out to make it something quite powerful. Um, so this this W idea is it's I've been quite surprised at how my usage of tools has deteriorated to almost zero um instead of preferring this approach
58:57Did we want to just talk about the amperand thing or you going to come back to that later?
59:01The amperand thing like the uh the set operation.
59:04Yeah. Yeah. Might just be nice to show that. So um okay. So we had these um two different things and we wanted to see um the ones from one that were in the other.
59:16Yeah. So that would be NS amperand WS.
59:21And then if you do len on that that is another way of calculating and then that would be two to the power of etc. So just mentioning that to say um you know knowing these these you know reasonably small number of powerful operations you know set theory um map and filter regular expressions you know it turns you into a
59:50you know bit of a superpower machine for doing whole range of stuff quite quickly and also it means when AI uses that kind of thing you'll be like oh yeah yeah I see it's just combined ing these basic principles.
1:00:02Mhm. Um, for this one, I'm not sure if there's ever duplicates in the list of numbers that we want to check. And then if there's two 83s and they both match, I don't know whether we'd want to get one or two. Doing it as a set, we'd definitely only get one.
1:00:16Um, so that' be a good one to maybe double check, but um, definitely like worth exploring. And um I have a feeling the description of the game suggested that can't happen, but that does sound like the kind of thing you might double check ahead of time.
1:00:31Cool. Um Oh, wait. I accidentally um accidentally ran some sort of uh empty thing, but here we go. Okay, so now instead of points, cards now win copies of subsequent cards. If a card has m matches, you win one copy of each of the next m cards below it. Um, so for example, if the card has four matches, you get copies of cards 2, 3, 4, and five, and then those copies also get processed, and it's going to bubble down
1:01:00like that. Um, and so here, another of sort of more maths inspired techniques would probably be to head straight to paper and to draw out our little example. Um, but in the interest of time, I can just explain what I'm thinking is we're probably going to want to keep track of how many cards we have. And at the start, we have one card of each. So, let me just write these down as a note.
1:01:23Just while you do that, I'm just going to um there's a question in the chat when I said I'm using W instead of tools. And people are asking what I mean by tools. Um, when I say tools, I'm referring to calling language LLM tool calling as we did in the Gentic thing last week. So in uh solvit you can use amperand back ticks to make a function at all and then you can ask the llm to use that tool as you wish. Um
1:01:51but instead of that you can not make it a tool and just say to the llm please show me how to do a thing with these functions I've created and it'll create code blocks with the functions. So they're basically two ways of doing the same thing. Hopefully that was more clear.
1:02:15Cool. Thanks, Jeremy. Um, okay. I've done something egregious and um uh yes um interesting also point from the chat which I certainly agree with which is um for AOC you get a lot more out of it if you try it yourself. So, I suggest for folks that they don't now go and do AOC 2023 lesson 4, but do a different
1:02:43lesson. I mean, if you're not feeling that comfortable solving AOC lessons yet, then maybe it's a good idea to try and replicate what you saw Jono do today. Um, but yes, uh, on the whole, practicing on different problems will teach you more.
1:03:08Okay, so now um Jeremy, we come to a question that was relevant to a something that I well something that came up a couple of times in the discord was um okay this like one thing at a time is all well and good but sometimes you just need to write a longer for loop right and so in this case in my head I'm picturing I'm going through the cards and for each one I'm getting the number of matches and then I'm adding one to all of the uh subsequent values and counts Um, and so I just wanted to show like one of the ways that I do that.
1:03:35There's going to be many. Um, but one of the things you can do is print um something, right? Start there. Oops. Um, uh, learn lines close parenthesis plus one.
1:03:53Um, but that's a good it's a good um piece of our point, right? is like if you're doing the whole thing, you might miss that. But if you're doing it one little piece at a time, um you can slowly build up to say, okay, um my matches is equal to we actually have a function for this already. Count matches um does count matches take a line or a
1:04:23Yeah, it does. Just takes a line. Um, and actually line is equal to lines, uh, and I'm just going to look at this print line and then I'll do break. So, this is like ignoring everything after that line. So, I'm actually just doing those. Okay, this is my line. Fantastic.
1:04:44Now, I want to count the matches and so I will add that piece and then look at it. So every addition to this loop, um, we're still doing one small thing at a time and trying it. And in general, as soon as you start to get at all complicated, it's a sign that maybe you should think about going back to doing one piece at a time. Um, but in this case, I know in my head exactly what I want to do. I want to get the line, get the number of matches, and
1:05:11then add one to all of the cards beyond this point. So for adx in range, I want to go from um i + 1 to i + 1 + m. And I want to say my counts here counts idx plus equals 1.
1:05:39And then I'm going to print counts and see how that evolves. Um optimist I don't know why I'm doing my ranges like this today. Um, it's what happens as soon as you're on live stream just definitely a debuff to be uh on camera.
1:05:57Oh yeah, um Jeremy, are there any questions in the chat?
1:06:02No, not really. Other than just like about the more asking just for more information about tool calling versus using the W thing. I mean I just it's just an observation which is that um I was kind of surprised to discover it like I tend to kind of want to do things with tool calling because I love our amperand um back tick thing and it seems really fun and call um
1:06:29but yeah just in practice um I often just find like doing stuff with tool calls just takes quite a lot longer.
1:06:40Um, and often like I need to kind of redo something pretty similar later or I need to do it on quite a few messages or so there are different like obviously web search. Okay, I'm happy just to let solve it decide when to do or really Sonnet decide when to do web search um for me and gives me back the answers and that's great. Um, but there's not that many
1:07:08things I find nowadays. Um, yeah, I don't quite know why that's ended up happening, but I think it's something about just this general idea that like if you're doing something, you're often going to redo it in a slightly different version or you got to do it lots of times on different things.
1:07:23And it's not that often that I call at all. I'm like, "Okay, that worked first time. I never need to do it again." You know? Um, yeah.
1:07:35Were you having some trouble with your solver there? It's I mean we're kind of done.
1:07:38Yeah, for some reason. Um it was uh it was um not running. So I'm happy to spin it up in a non production.
1:07:47I mean we we're or we're kind of done. We probably want 15 minutes at least.
1:07:52I think we would have gotten accounts and then we would have summed the values and that would have been our score. So I'd say like so your way of doing the loops I I would probably have done it differently more like I like to do everything inside the loop more and not add a loop until the inside bit works.
1:08:09Um so I tend not to have loops with five or six things and prints and whatever but either works fine. It's just uh different different styles and it's um I also just wanted to bring it up because we'll see later on the same thing applies to like building larger classes, right? We'll show you methods for adding one small function at a time to a class using pass course patch and building up larger and larger pieces of software.
1:08:36I I get the impression a lot of the questions are like okay this is all well and good for advent of code but when I need to write real software I have to write 20 lines in a loop and I think the outcome that we'll see is that you can pretty much always reduce it back down to one small thing at a time and checking the output.
1:08:53Yeah, exactly. Like it it it feels like you have to because that's what you're used to, but it's almost never happens in practice, you know. Um, I showed some of the stuff from our actual in lesson one. Um, some actual PRs from Solver. Um, yeah, and they were all pretty small.
1:09:18Um, I'm just trying to I might see if I can find other examples, you know, um, of what hours tend to look like. Um, oh, this is a fun one.
1:09:48Oh, I do have the practice version of the lesson I can show as well if you want to see the the final answer.
1:09:54Uh, yeah. Okay, why don't you show that and I'll All right. Um, okay. So the um the way I did it here was um again we're going through our sample we getting the card number the winning numbers the main numbers we have the same sort of idea of account matches function and then just going through and saying okay in this case which ones would I increment I would add one to this one this one this one and this one um and then summing the
1:10:24values of this resulting set of counts the answer the the question calls for well how many total cards do you of we sum the values, we get the answer 30.
1:10:32And then um again, just because it's um we've now done all the pieces, putting that together and running it on the input, we get the correct answer. So we were so close to the end there. Um but yeah, nice to see that it it does indeed work. The the approach kind of comes together. Um yeah. Um
1:10:54yeah, I just looking at like I was just looking through like our list of pull requests over the last month in in solve it and like basically all of them you know were things of like a line or two and so like I just give an example of something here where like uh Kum so we car added something the other day where we wanted to make sure that the attachments that get sent to the AI um uh are actually ones that are referred
1:11:23to in your prompt and so they're in this special little rejax format. So you can see here we're using a reax, you know, um and it's like literally looking for a comment and then followed by a bunch of hexadesimal numbers 36 times. Um and then we remove um some and so we were using a list comprehension. So everything we're talking about today is how we always code, right? So, we go through the attachments and try to find those ones that didn't match. That makes
1:11:53sure we don't send off to the AI stuff that it isn't actually visible on your screen. This is part of our thesis. Like what the AI sees should be what you see. And uh I pointed out to um Kum like, hey, you could actually just go attachments.
1:12:07And pass in the string if only our attachment object knew that things matched, if their ids matched. Uh so then Kum you know like so you can see it's like just one line of code there.
1:12:19And so this is you know this tiny little function that adds a patch that adds an equality check and also adds a hash check. You can see here you know this functions like four lines of code. This line's one line of code small enough we literally just chuck it on the same line because it's so uninteresting. Um, you know, once we do this ability to kind of add equality and hash checks to any database object, we can then remove our special case ones from our database objects. Just add it again. Remove a
1:12:48special case one and just add it. And yeah, you know, our lines of code here are like one, two, three, four lines of code. This is how solver works, right?
1:12:58And in fact all of these were actually implemented in um IP and B files and then exported. Um so yeah it's not just uh bad vendor code um by any means it's you can use it for everything.
1:13:16Fantastic. Um okay so I think we're about done with our advent of code example. Although the chopad among you will have noticed that I've only so far done three out of the four steps from polia. So the fourth one would be reflect and in fact um yeah there's there's a number of questions you can ask yourself and for homework what I would suggest you do is if you like the idea of having an AOC utils file that's able to add messages make a function called reflect which
1:13:44adds a prompt that says hey solve it how am I doing and then enumerates out the things that you're trying to do I'd like to work on things in small pieces one or two lines at a time every time I do something I'd like to print some output that helps me see if I'm doing things correctly. If I find better ways I'm going back and refactoring. Just like list out the pieces that you're trying to work on and see if you can make a little reflect function that'll automatically help the AI help you look back over your dialogue and say, "Okay,
1:14:13yes, we're doing it the right way." Or, "Oh, I actually solve it to just do all the code for me. Maybe that's not quite in line with my goals." Um, yeah. So, go and create a little um reflect function for yourself. Might be a fun piece of uh homework. But then speaking of homework, I think Jeremy, the next thing we're going to do is go to as promised your completion of lesson 2's uh tool loop implementation.
1:14:36Yeah, we're going to do a lot more than that actually. But yeah, so just before we do, I say so that little bit of homework, maybe we can pop that into the Discord and we'll also add it to the YouTube lesson description. Um I think hopefully people will find that pretty interesting.
1:14:49Yeah. Um thank you, Jonno. Um so folks who have done fast AI before are pretty used to the idea of like what does fast AI lesson homework mean? Um but folks who haven't this will be a bit new and so I wanted to kind of show you how I would tackle you know where I student the homework and there was a specific piece of homework um uh so this is not a solution to the homework yet I will give the spoiler warning before we
1:15:19get to the spoiler um so there was a particular piece of homework which is like finish this notebook to complete this feature but implicitly it's also make sure you fully understand fully understand the whole um dialogue that we went through. Um and so let me show you what that looks like. Um so let's share here. So I've just um
1:15:46uh created a new um dialogue called uh HW listen to actually kind of think we're going to be uploading it. So why don't I go back here and delete that? So remember if you put a slash in a file name it creates a folder for you actually. So I'm going to delete that. So instead let's we're going to upload. So here um here is the here we go. Here's the lesson from last week. Cool. Here's the dialogue from
1:16:12last week. So step number one will be um pretty much always to to grab a copy of this. So, I'll just copy the dialogue and I'll hit upload and I'll paste it into here. Okay. And it's given it the same name. So, it's called aentic. No worries. So, that's step one.
1:16:36And then I want to um make sure that the AI knows what I'm doing. Um so, I might want some help with solver um as I go as well. So here's our guide to solve it features which you can just grab from fast AI. Um and um you can always just click on this little common mark button.
1:16:59That's a type of markdown and to get the markdown version. So what I would tend to do is I tend to just grab all of that and then open up my dialogue which I just uploaded. Um okay, no worries. And I'm just going to hit A here and um create a note. Command shift K. I don't have to tell you. It's showing me in the bottom right. Um command V. Okay, no problem.
1:17:27Um and I guess we don't need all the table of contents. So we'll quickly just get rid of those. Instead, we'll say um solve it guide. Okay.
1:17:41And I I don't tend to like things taking up too much space. So I could either hit um shift I to turn this into a little mini scrollable thing. But I'd probably just hit I to get rid of the whole thing there. Um um so if we want to be able to see the start, we can just go to the top. Um no, it's not doing that. Never mind.
1:18:05Okay. So we've got our um and remember as we do that our you know we can jump around we can have a look at the guide anytime if we want to but I'm just putting it there actually for the for the language model so I can ask it hey help me I don't know how to do this in solve it so I'll close that and then the second thing I'll do is um grab the transcript because I want it to know what I'm meant to be doing. So again, I'll just grab the whole thing and I'm
1:18:34going to paste it in. Let's see. Probably more interested in the transcript than the how to do solve it. So I'm going to put that second so it'll be kind of closer to where I'm doing my work. So I'll paste that in here. And again, let's just pop our heading so it's easier to jump to later. Lesson transcript.
1:18:56Okay. And again, I'll just hit I to compress that down there. Um, so a lot of people are in a bit of a hurry. Um, but it only took me a minute to actually organize myself here. And you'll see that this tiny amount of um, uh, organization is going to make life a lot easier for me. So, okay, here's Jeremy's. Um, so I'm going to use my third person to describe the Jeremy who
1:19:25taught the lesson as opposed to me who's now learning it. So I want to make sure I understand everything. Okay. So I need to at least be able to run it. So um, shift A um, or hit on this button um, means run everything up to here. And when I do that um, you'll see that the time updates. We should fix this to be in my local time zone, but it is currently 10:24 here. So 12 24 probably UTC. Um
1:19:54um and uh yeah, I'll make sure that I can actually run this prompt. So I hit shift enter.
1:20:00And so let's see. It says, can you tell me the email address for customer C2?
1:20:05And so like, okay, what does that mean?
1:20:06So I want to go back and make sure I understand like I don't really know what's happening. So here I'm going to hit B and I'm going to introduce myself. Um, guess I'll be Jimmy instead of Jeremy. Hi there. My name is Jimmy and um I am working through this dialogue that my teacher prepared for me and I want to go step by step, make sure I understand all of it. So, I'm stepping in here.
1:20:37Everything before here is from the lesson. Uh, I've also popped in the transcript and a description of how to use solver because I want to learn how to use solver better. Um, but first of all, can you explain to me what the teacher was was doing here? Why why did the teacher set up these functions and have this prompt? What am I meant to be learning at this point? So, that's the key thing, right? Is throughout the lesson, I'm trying to teach you something, right? So, if you don't understand what it is I'm trying to
1:21:06teach you, um, just just ask, right? Um, okay. So, again, you know, using voice is such a good idea and I want to get a really thoughtful response here. I'm not not in a hurry. So, I hit um command shift D to get my thinking mode. Um, it's like, okay, showing you how to build an agent giving you the ability to use tools. Okay, so it's set up a database. Okay, let's go and have a look. Is there a datab? Oh, okay. This
1:21:35is my database, right? And so I can just double check things here, right? So it's like, all right, so make sure you understand and then double check your understanding, right? Oh, I see. So when you say a database, we're kind of mocking a database by just using dictionaries and lists. I guess the teachers doing that so we don't get distracted by like having to learn databases as well. Is that the idea? So really double check that you fully
1:22:02understand what's going on. Okay. Okay. The key learning point is by using amperson back tick, you're giving the AI permission to call these functions.
1:22:15Okay. Yes, you've got it right. So, this is just like a real customer service system where you would cancel where you would query the database. Um, so like what's interesting here is that um we're actually learning to create something that's really would be just like a real customer service agent. Um, and this is actually how they would really work.
1:22:40Okay. So then the teacher went, "What's the status board? O2, please cancel all." Uh, okay. Please double check the status. Okay. Um, all right. So then again, I I would want to make sure I fully understand like what's what's happening here and why. Um, okay. So I guess the teacher is just showing more examples of questions here.
1:23:06Um, although that last one I see like it's got multiple calls or something. Uh, in fact, the last two of them both have multiple calls. Um, can you explain how it knew how to cancel all of the orders for customer C1 here and it kind of did it all at once?
1:23:28So, kind of again, we're looking for these little um steps here. So, you can see here it said please cancel all orders and it like did it in multiple steps. So this is a really key idea that you want to make sure it's like ah okay you found the difference between a cool call and an agent right um so you know let's make sure you understand it so this is where you should get it to give you homework right
1:23:57okay I think I understand um but I want to make sure I do could you give me like the smallest simplest possible little problem for me to solve um to see if I can do a really simple version of something like this.
1:24:17So, this is all about like this is very different to going to school, right?
1:24:21Where the the teacher tells you what problems to solve. But the difference here is like you should ask for problems to solve at the exact point where you're not 100% sure or if you're not even sure if you're sure, right? Um so said like okay create a simple greeting system. Make a function called greet. Okay. So I'll hit command shift um J to go into code and
1:24:49I'll create a function called greet. It takes a name parameter.
1:25:06Okay. Oh, exclamation mark. Okay, great. Um Okay. Uh use the text. Make it available to the AI. RCA. Okay. Hey, can you please greet
1:25:28Jimmy using amperand back tick greet?
1:25:38All right. And that needs to be a prompt. Okay. So, I've got a problem. I can't do it. And I can't even ask for help. Oh, all right. So, it was working and now it's not. So, it stopped working at the point I added this to my dialogue. So, you can pretend that um it's we're earlier in the dialogue by simply moving it above where it went wrong.
1:26:12Um so, I can say help, right? And then I can say uh I tried this but it didn't work. Okay. And I pop it in triple back ticks. This is an unusual situation where we can't even ask it about something because we can't even prompt. Right. Uh so just say what happened.
1:26:54For the function to work as a tool, it needs type hints. Okay, no worries. So that is a string. Okay, so again, you want to understand why, right? So if you're not sure, okay, let's try this now.
1:27:08Okay. So, um uh why do I need type hints?
1:27:21Um copy also. Now I get that.
1:27:50Okay. So explains the AI needs to know what kind of data to send. Uh okay. So then I need a dock string. All right.
1:28:01Great, great someone.
1:28:10So, there's a great comment in the chat which is Tim saying um anytime they take the time to explain more about like their problem or what they're understanding, even if they feel like they're just restating, the language models in general seem to be much more helpful after that.
1:28:25And that's definitely something that we've seen, right? why we have it so that they can see all of solve it like all the things you're trying all the plans that you put in notes that's all additional context that helps it be more useful and so here having your you know taking the time to say I'm trying to do this this is the error that I'm getting this is the problem that I'm seeing anything any extra info that you can add and anything that you can do to make it easier to add that like using voice that's a big help for and in solit you you'll hardly ever have to describe what you did and what
1:28:54happened because as long as prompting works this is the only time it won't work, right? And and there there are only two things that can go wrong. Missing a type or three things or missing a dock string or you forgot to even um run the function in which case it'll say like the function's missing. Um so as long as that it'll work. Everything is going to just work smoothly. It'll see what the problem is.
1:29:17And so after this it's seen me fix it all up. That looks pretty good. So I tend to hit like um command shift slash at this point which just like add it actually sends a prompt with just a full stop but the AI generally knows like to just it sees how how we've gone and it's like giving me a little summary which is nice and I find that useful to be like okay Gizbury you're up to you've made your first tool um okay so it's happy
1:29:43right so um then I would kind of move on Um, so now we've got a new section and again I would kind of go through the same thing, right? I'm just going to speed up a little bit, but basically we've got a bunch of tools listed,
1:30:10got some imports, a question mark. Um, then it kind of asked how to loop works. got a big long explanation.
1:30:20All right. Um Okay. Um so then I might just hop in again and just make sure I understand what's going on here. Um okay. All the stuff above this in this section comes from the teacher. I don't really know what's happening here. What do you think the purpose of this section is meant to be about? Um what should I be trying to understand here?
1:30:48So again the nice thing about this is that um it's you can just ask when you need right so it's kind of if you know all this already and it's like okay well I wouldn't want to ask all these questions right so this is the final version I told you about that can go wrong which is this did you run it and so the question's asking did you run the line of code to import or create that and the answer is we did not okay so um there was um one line here, one line
1:31:17here. And so these functions, as it's going to take, as I mentioned last time, are interesting because they're the most important kind of set of functions for agents that can work with files on your on your disk. Um so now that I've imported them, I can run it again and this time it'll work.
1:31:41All right, so it has a bit of a think about that. Um, and again I wanted to use thinking here because this seems like a pretty key question, right? So, okay, your demon teacher is demonstrating how to use AI to explore and understand libraries. Instead of just reading docs, you can have an AI agent help. Um, okay.
1:31:59Um, okay. But why those particular tools? Is it just some random bunch of tools that the teacher happened to think is interesting or or what? And how come we didn't have to write them in this case?
1:32:16Where did they come from?
1:32:23Um, okay. So, we're just kind of making sure that we understand exactly what's happening and why. Um, and then okay. So, and so again, if you don't know what RG is, you could start asking about that. Um, all right. So, make sure we run these bits of code. Make sure that they run. Uh, get weather not defined. Let's go back and run it.
1:33:02Um, make sure we can ask questions.
1:33:09Um, h all right. Um, what's going on here?
1:33:17What's this question mark business about? And why are we using it on this function? What am I meant to be learning from this part?
1:33:47Okay. So, I didn't I forgot to mention that um the teacher said this. Um the teacher had this at the end of this section. I don't get it. So yeah, sometimes if it answers not quite the way you want, it's it's often better to just reask um rather than try to correct it. You don't want him having lots of corrections or it kind of starts thinking that it's always wrong about stuff as we've discussed before.
1:34:27So yeah, so you know that's trying I was really trying to show here that exactly this right that that you can nothing needs to be mysterious. You can look inside that these incredibly powerful agents that can literally download everything necess you know that can basically like explore an entire codebase and figure out exactly how it all works. Um you know it's actually really simple.
1:34:53Um how are we doing for time? 1039. Okay. So I might um skip over how I would learn about the rest of this and instead I'm going to share later a dialogue with this for the whole thing.
1:35:08So for anyone that found the agentic um thing a little confusing and maybe not quite comfortable yet knowing how to ask for details, this is going to end up being an extremely detailed dialogue um with this throughout. Um, so let's go all the way to the end and do the homework. So this is the spoiler. Um, so I'm going to hit shift A um to run everything up to here.
1:35:45It gradually scrolls through and so it takes a little while to run because it's actually calling Claude lots of times, but that's good. If hitting shift A does make sure the whole thing works, Jeremy, maybe while this runs, do you have any advice for knowing?
1:36:06You know, I think there were some people who kind of found, oh, I dived into this and got stuck in the internals of Cordet and should I figure out what make messages like how do you know, okay, I should keep uh digging in a little further or maybe I should put this aside for later and go to something more simple or like how do you gauge this is going to be a two-month, you know, effort versus I think I've got this versus this is easy. like how how are you figuring out when you're embarking on one particular deep dive like this
1:36:35homework whether it's at your level or whether you should be pausing and picking something simpler what's your sort of like heristic for so I would navigating that yeah go top down so top down means like make it as simple as possible you know and and really incremental and that way you can use the time that you have um basically so if you don't have much time, then you've ensured that you've made some progress
1:37:04with the time you do have. Um, if you got lots of time and you're really interested, you can keep diving deeper.
1:37:10Uh, because, you know, for this kind of thing, there's always an infinite amount of thread you can pull until eventually you're working at Anthropic, uh, training their new model and tuning their CUDA kernels. At that point, you've pulled the thread as far as it's going to go until you then do new research to find a new replacement for attention. uh or you can stop a little earlier. So yeah, it's it's really easy.
1:37:35So you could say, look, I learned how tools work and solve it, and that's kind of like as much of an agentic loop as I want to do, and maybe in the future, I'll look at using like chat's already built-in tool loop. Or you could say, actually, I'm happy with, you know, Leette tool calling. That's where I'm going to stop. Or you could say, yeah, I really want to go. What if I couldn't use lizette? But if I could only use the raw anthropic API library and I wanted to do this all from scratch. So it's really like a choose your level.
1:38:03I would definitely like if you unless you're pretty confident it's beyond you, which is fine. I would definitely try to finish the homework at the bottom of the dialogue.
1:38:11Um um yeah, but I mean definitely some people be like, "No, no, no, that's not where I'm at." Which is fine, too. Mhm.
1:38:19Um, okay. So, uh, I want a bit more space here. Um, hopefully if I do that, you still able to see my screen. Okay. Now that I've full screened it, J.
1:38:34So, um, our job was well is to kind of finish off this, right? So, I'll be like, um, uh, hi Jimmy again here. Um, everything above this was all part of the lesson created by the teacher, um, since I last chatted to you. Um, and I think it makes sense. Um, but the teacher wants me to now finish this off myself. Um, which feels a bit intimidating. Um, so like what's the
1:39:03smallest step I could do now? Or could you kind of give me a sense of basically what I what I need to do to finish off this um, this homework?
1:39:13And back to Polia, this is you understanding the question and starting to maybe begin on the making a plan, right? This is like going back to those steps that we do for solving any problem. What am I trying to do? What are my steps to do it? And then we'll start working on one small piece at a time.
1:39:29Yeah. And I'd say like where I differ a bit from Polia is I often don't quite make a plan, but I just try to find one little thing. I mean this is part of polio's approach as well is like can you just simplify it a bit you know but actually there is a way of solving problems which is doesn't involve a plan at all but you keep simplifying it until it's finished which is often my approach so I tend to use a bit of a combination
1:39:58of those things um and it depends a bit on how much I can how much I have to keep in my head and often there'll be like mini things which is a plan to make it a bit simpler and then a mini thing to plan to make it a bit simpler I definitely a on the side of not planning. I don't know if it's an like it works well for me, but I did do a like a personality quiz once, which is actually unusually scientifically backed personality quiz. And on the like what percentage of people in the world plan more than you, the answer was 100. So,
1:40:28you know, I'm particularly like small steps oriented. Um, so here, yeah, I just want to kind of check in where we're at. So, we're meant to create a tool loop ourselves. Um, the teacher's already called one tool. So, I double check that I understand that. So, yeah. So, we've got adder and molter are our tools. Our prompt was to solve this math puzzle. Um, and we called our client, passed in the tools.
1:40:59Um, there was a sample history. Um, okay. So, you know, again, you need to understand why is there a sample history here? Why did Jeremy add a sample history? Like that seems random. And if that seems random, okay, then there's something you don't understand. You would add it and I'll put this in the dialogue that I'm going to share.
1:41:16The question like why is there a simple history here? So the answer is we have to replicate this. Where did it come from? Well, it came from earlier. I copied it from the history that we got when we did it automatically with Tuloop. So we're trying to replicate to loop. Um so um great. So we want to create this sample history. And then we kind of confirmed here that we got our tool use block. We got the content. We found the function in globals. We called the
1:41:44function. Again, make sure you understand what all that syntax does because some of it's pretty unusual, but actually this is showing you how Python actually works under the hood. This is actually, you know, function calling is just syntax sugar for looking up a function in a dictionary and then passing a dictionary to the function. So this is actually all you need in Python strictly speaking. Uh we had to get our tool result back. Okay. And then we put it all together into some messages.
1:42:11Okay, great. Um so um this is where I would go back and redo this, right? Kind of in more of one step. So this is where it's very nice that I can say like okay I just hit comma to copy that and then I press commandV to paste that right and so that's my first step is to call that and then we got top funk funk res blah blah
1:42:38blah okay so then I'd probably say like all right so comma command v comma command v comma uh nan v. All right, so just going through all my steps because they worked well last time. Comma nv. Um all right, that seems like a reasonable place to stop. Um so then we might have a look uh at trc.
1:43:10Um and I probably need to run Oh no, actually I did run some things, didn't I? Um oh, and I accidentally made it a prompt. Okay, so that's fine. So, I'll press command shift J. And you don't have to go into edit mode or anything. You can just do that straight there. Okay. Um, so we've got our tool result with a particular ID. It's got some particular content. That sounds cool.
1:43:35Maybe it's worth also printing out our TU as well. T U B um P R. So, we're trying to solve this equation. So, first of all, yeah, it's trying to multiply together those two pieces. So, that makes sense to me. Um, so here's where, you know, we could um either turn this in, you know, turn some
1:44:02of this into a function um ourselves or, you know, as Jonno mentioned and I I very much agree with it seems like the kind of thing that an AI can do. Um, could you wrap these steps up into a function for me which um I guess it's going to take the result object and run the tool call and return the result.
1:44:43It's actually kind of nice having the thinking. I was I was thinking about how you know when we said if you're writing a piece of code, think what the output's going to be before you actually run it, right? So you have this kind of like I'm expecting a list of numbers and then it's a good way to check. Kind of fun to have it when the AI is thinking. You're kind of thinking like, oh, okay, what am I expecting to see in the output?
1:45:00Oh, I'm expecting a tool that looks kind of like this. It's another way to check that you're understanding what's going on. Um or at least you know take a guess of what it's going to look like.
1:45:11Yeah. I like that.
1:45:15Yeah. I kind of like to squash things down a little bit so I can kind of read it a bit more at once.
1:45:25So then again, I would immediately try it. Run. So we're going to need to This is where I'd go up here. press C and then I'll press uh B. Okay, so that way we can get our R and then I would probably press um shift M to merge those and then we can go ahead and um could even press alt enter because it's pretty obvious. Sorry, alt full stop. Pretty obvious what I want to do. Um so that's
1:45:53going to be our TRC, right? So, TRC TRC. So, we're just kind of making sure I can reproduce the things that Jeremy showed.
1:46:07Um, and that all sounds pretty good. So, then, um, yeah, and I don't need to keep this prompt anymore. So, I'll just press X to get rid of that. Um, all right. So, the teacher called one tool got its result, created the history. Okay. Then sent it back. So, this is kind of where we're up to if we want to replicate what the teacher did, right? So, um we've got the PR, we've got the
1:46:35response, and so if we go back to the history, you know, um we've got here make messages. Okay, so past pr.content TRC.
1:46:52That's interesting.
1:46:54So that's our history. H equals. Okay. So I haven't even done anything new yet. I'm just repeating what's at the end of the dialogue. And so in theory, if I pass that to my client, oh, and I have to do make messages. So it knows which one is user and which one is assistant. And then pass in my tools. Okay. And then that's going to be my new response. Right.
1:47:44So you're expecting this time to have the next step in the process because it's got the history of the first tool call that it did and the results.
1:47:52Yeah. And we can see here promising hopefully here we are. It's going to take that number that it just calculated and add it to the other one. That's good. Okay. So we've replicated that. So I just keep going through this process here. Um great. So now we've got the prompt. Um we got its answer. We then told it here's our tool call and we got its answer.
1:48:20Uh so we're going to need to run the tool again. Right. So we got a new tool call response. Is that tool? Why do we call it TLC? I don't know now. Tool request something. Never mind. Now forgotten. Uh so we will call run tool again. Um
1:48:45and so that's I mean we'll just take a look at it. So again like Jonah was saying before it runs have a think about what it should say and it's given us a tool result with the result of adding those together. So now we need to pass in the whole history plus its response and plus our tool core result. So H plus equals uh R comma
1:49:13RC content I see above it's our content makes sense um and this and we put that in a list and all right so then hopefully we got a new uh which is going to be the result of calling um passing in our messages messages H. And I wonder if I press alt full stop.
1:49:43No, I meant to say tools. Yep. No, I mean tools equals tools. Um, so this is where you can like use little bits of AI just to save you from having to do everything. And oh, it's finished.
1:49:54Ah, okay. Great. Um, so Jeremy, that was a that was a for loop that you just ran the steps.
1:50:02Five times, right? Or or two times. Um, so you didn't even start by writing for, you know, or while stop reason I'm I'm very rarely clever enough to do that. I find, Jonno, I normally find I kind of have to do everything pretty slow. I'm like, yeah, I'm like really slow at everything. Um, but I find if you go really slowly at everything, then you kind of end up finishing faster because it turns out correct the first time. So, I'll just double check here.
1:50:28Um, I guess I finished doing everything manually. Does that all look correct? So now I'm just meant to like automate this with a for loop or something. Can you help give me some guidance?
1:50:51Okay. Just about on two hours now. 90minute lessons keep end up being two hours.
1:50:58Okay. Great. So we want to function. So I wouldn't probably do it with a function just yet. Um because you know and and AI doesn't know really anything about software engineering much because AI's never seen software engineering. Uh it certainly doesn't know this style of software engineering where we make everything work before we put it in a function. So um I think so first of all um
1:51:26we are going to look at our setup here. So we in fact this should be quite straightforward I think if we take the stuff that we did manually and it all worked right
1:51:52I haven't quite tried it this way before but I think ah right actually I started R= P and Then we did run two. Okay, so let's get rid of that. Okay, so I went a bit too fast. So this is actually where we started. R= CPR, TRC equals run tool, H equals blah blah blah. Cool. So that's what we just got to TRC equals So we did H, we did R. Okay.
1:52:25And then we ran the tool.
1:52:30And then we did H+. Okay. And oh, and that was finished. All right. So, there it is without a loop.
1:52:38It's kind of nice to see it all on the screen at once, right? And I don't know like we could have maybe got AI AI to do that, but I actually found it quite useful to go through. So, okay, this first step is not really part of the loop. Let's see. We got the R. We do it with PR. We don't have H yet.
1:52:57Uh then we go check R equals C make messages H run tool. Okay, so we've got a few different ways of doing it, but we basically go run tool and then we've got H plus equals. Okay. So, I'm just going to leave it all there, but I'm going to go like do while and I remember it's like while
1:53:24uh dot I don't quite remember, but I bet if I full stop this, it should No, wasn't it a stop reason or something?
1:53:34There we go. Uh, and it's No, it's while it is um equal to um wonder if it's all use. There we go. Yeah, just give it enough guidance. Um, yeah, the ghostex model is not super smart, but it's not bad once you get close. Um, all right. So, basically, we would run the tour. Okay. Now, we need our H going to go H+ equals in the loop clearly each time. So, there's our H+ equals.
1:54:13Um, okay. So, uh, yeah. All right. You know what we could do here is even like let's get our H going, right? Because then we can really make everything consistent. So, we like H is actually starts is just let PR, right? So, R equals and then we could be like make trying to make everything consistent.
1:54:39All right. Then while stop reason is not equal to true use. Um and so then what we're going to do is we're going to say to result is run tool on R. Okay. Let's see. Yep. And then we go H+ equals. Okay. And then we do R again here. Okay. By the way, Jeremy, you're editing as a prompt, which is why some of the highlighting and completions is a little strange.
1:55:10Oh, that's why it had a lot of trouble with my R equals stop reason. Yeah. So, yeah.
1:55:13Okay. So, just to explain the ghost text um knows what um type of message you're in. Um and so that's probably why it took a little bit longer for this top reason thing to work correctly is because it didn't think it would expect to see that in the prompt. Um so, thank you. All right. So, create a history. uh call it with just the prompt. Okay, it should be tool use and so if it is then we run the tool and then we add the
1:55:43content and the tool request here. Um and then we now rerun our client. Uh I think that's it.
1:55:56Yeah, sounds good. Although I guess TRC is more like the result of the tool call and the tool request would be the R.Content. content or the yeah content.
1:56:06Let's see what we go. We go run tool with R is what we did. Did I just So R is like the AI asking to run the tool and then TRC is like the result. I was just just like the semantics I guess of Okay. Yeah, but the loop I think it's right.
1:56:22Okay, the loop looks great. Yeah.
1:56:26Okay. So, while that's happening, it might not be a bad idea to kind of like print uh um and so uh if we've messed this up, it could keep prompting Claude to get it again. So, this is where it's probably a good idea to know that you have a stop button up here or shift S so that it doesn't use up your entire credits. Um, hey, it did it.
1:56:58Okay. So, um, then I would pop that. I just press C and press V. Um, and I would go up here and I'd say defaf, uh, do double, that's weird. do loop. Uh, so we're going to be passed in a prompt. We're going to be passed in a client. We're going to be passed in some tools. That's about it, I think.
1:57:30And then command right square bracket. Oh, my keyboard shortcuts don't appear in full screen. Didn't know that. Guess I didn't see it there. Then return it.
1:57:47Um do loop P R comma C comma tools. I probably could have got rid of that print. Might be nice to have some um visual output of intermediate bits, but yeah.
1:58:16Was it display that we used earlier that the nicer?
1:58:23Wonder if we got that.
1:58:28Yeah. Lovely. Nice. Great. Um okay.
1:58:34What do you think about my solution to the homework? I think I've got it done here.
1:58:42Where the air come from?
1:58:46What do you think about the homework?
1:58:54So, this is doing the I guess reflect step of looking back. Are we satisfied with what's going on? Are there other pieces we wanted to add in?
1:59:03Are we happy with how we built it? Um, are there other things in a more commercial tool loop that I would want to think about?
1:59:15Are there any edge cases or anything like that I'm missing?
1:59:21Um, where should I proceed from here if I want to learn more about this topic?
1:59:28Um, interesting to see because I can see an edge case and I can see someone in the chat seen it as well. In fact, it came up when they're LLMs. Let's see if this one.
1:59:39Okay, this is real reasonable. Um, yeah. So, it didn't actually notice that um we hardcoded something we definitely shouldn't have hardcoded here. So, the tool use request won't always be in position one. And also, they won't always be um exactly one of them. Um, if you remember back up here, um, sometimes
2:00:06it actually I think it had multiple tool requests. Um, yeah, had multiple tool requests. Um, so AI doesn't not find every possible bug for you. Um, so it's still worth thinking carefully and um, testing lots of things. Um, but yeah, that's that's the homework.
2:00:33Fantastic. Thanks, Jeremy.
2:00:37All right. Well, I guess um that's us diving into Advent of Code. We will now be switching gears for the next couple of lessons, I believe, to some more fun web programming and various related things. Um, but don't stop enjoying the advent of code. I might even try and um hang out in the office hoursy kind of voice channels the next few days and spend a bit more time, you know, having fun with some of the older ones. Um but then yeah, Jeremy, are there new pieces of homework that people should be
2:01:06considering besides just continuing to practice the techniques before the next lesson on Wednesday?
2:01:11Um no, I think there's plenty here to be honest. So like I would say like this um how language models work tool use stuff is worth diving deeper into wherever you got to you know maybe try keep going off the edge of that dialogue to create things people have never seen before like Marius did you know he went way off the end of the dialogue to be like hey let's implement this new academic result that's not even written up in a paper yet so you know that's the ultimate um
2:01:40but depending on where you're at just go a bit further than where you're comfortable some do something you're not quite sure if you can uh or try to solve a solve it. So I saw um one of the returning students um went back to day 9 2024 which was a famously difficult one and he could not do it last year and this year he did it. So that's a really good sign. Um, notice also there is now in the Discord a bonus lessons section um,
2:02:09including a thread where you can ask and so maybe if you find Jono in the chat or office hours during the week, he could convince him to uh, solve a interesting challenge that you have. Um, and we will start adding yeah more videos to that section during the week. Thank you Jonno and thank you everybody for watching.
2:02:30Thanks everybody. Bye.