And a very warm welcome to cursor.
Here we are.
We are in week four.
Landgraf, we're going to lab two, which is the lab for day three.
It's confusing.
Uh, so we're going to start with some imports as we do.
And we are also going to do the low dot env that always needs to be done.
And we are now going to go and set up Lang Smith.
So there's a link to Lang Smith here.
When you follow this link you'll get to their website.
And the first thing you'll need to do is create an account.
Uh, and it's free.
It's free as long as you stay within some very high number, which we definitely will.
Uh, so you can set that up.
And when you come in, you're going to get this sort of dashboard a bit like this, except it will be
empty.
And the first thing to do is to press the setup tracing button right here.
And this is going to fly up.
You have to generate an API key so that you've got an API key.
And as soon as you press that it will then fill this in down here.
And you just simply then want to copy that to your clipboard, all of your, uh, fields, all of the
key variables that you'll see here.
Um, but just don't obviously don't take the OpenAI API key as well.
You don't need that, But you need this.
And then you will it will actually populate that API key with whatever you generate right here, which
is great.
And then you will go into, uh, back back here into your EMV file, which is just there, and you will
add this in to your EMV file so that we have these variables set.
And then once you've done that come back and run load dot env again so that they load in.
Maybe I should have done that in the other order.
So that's great.
Then you have langsamt configured and you'll be able to see things.
Now before we, uh, go further, I will just just talk through a few of the things we can expect to
see.
Um, so I called the project mastering agents, but you can call it whatever you want.
Of course.
Um, and you can see in here there's there's lots of stuff that I've been doing.
You'll see that it for every time that I've invoked Landgraf, I get some sort of a of an entry here.
I get the input and the output.
If there's an error, which I had a couple of errors, then we will see them.
It tells you when it happened.
It tells you the latency, which is very helpful.
And there's a bunch of other useful stuff here too, which we don't often get to see.
The cost in this column is telling us how much this cost us to make this call to OpenAI.
And for those people that are concerned about about API costs, do have a look at how insanely small
these numbers are.
It just really brings it to life.
I realize that the main problem people have is with the upfront $5 you have to put in at the beginning,
but I hope that you see that that until you get to such point as you are scaling, we are talking about
not just fractions of a cent, but fractions of fractions of a cent for most of these.
Um, it also tells you the number of tokens, which is helpful to know.
I'm not sure the zeros were because I had some bug that I luckily then fixed.
Uh, so you get to see a bunch of stuff in here and this is going to be useful.
And when we actually have things to to look at, we will come back and take a look at that.
Okay.
Onwards.
All right.
So I found a useful function that's in the long chain community folder.
Uh and it's called Google Sherpa API wrapper, which means that it's a nice little convenient wrapper
around the same thing that we set up before the Sherpa API, where we already have the API key in our
env file, which is convenient to use.
And so we can create an instance of this thing Google soap API wrapper.
And we can call Sherpa with something like what's the capital of France?
And if we do this, then it will think for a moment.
And indeed we get Paris is the capital and largest city of France, and with some stuff about it, from
doing an internet search on this, which is great.
And again, this is something that's part of what's free and included in the plan up until some several
thousand calls.
I think unlike OpenAI, which is charging us two and a half cents for each one.
So that is, uh, that is good.
Now, this is showing you some of the nice stuff that's actually in Long Chain rather than Landgraf,
but Landgraf uses it to.
I mentioned to you that Long chain already does sort of simple agent interactions.
It already gives some some wrapper code, some abstraction code.
And here is here is one of them.
I kept the import here so we could see that it's from, from long chains.
Long chain.
So?
So you can say that, uh, you can wrap a function like this with a tool object.
You give it a name like search a function serpent run.
That's what it will actually do when it needs to call this tool.
And a description is what will be will be called in order to, um, when, when building the JSON around
this tool.
Uh, so that's wrapped it in a tool object, a long chain tool object.
And as you can probably guess, this is going to take away all of the gumph about building that JSON
object with all the stuff and the properties and everything else.
It's going to take care of all of that for us, so we can now try out the same, the same question,
what's the capital of France which we can do using tool search dot invoke the long chain way we are
calling this tool and there we go.
We get an answer of the capital of France, same thing.
But now we're doing it by calling invoke.
Okay.
And now let's just show you what it's like to build a tool from scratch ourselves.
It's super easy.
Uh, so we'll use the same old thing that we like to do because it's nice.
It's so tangible.
Uh, using pushover, this is the same kind of function that is able to send a push notification to
me.
So we give it the usual docstring, we give it, uh, the information about it.
Um, and, uh, here we go.
That's that.
I put that into a tool again, the same construct, the long chain construct.
The name is send push notification.
The function is push and that's a description.
And now I can then call tool push invoke with me.
There we go.
Oh, yeah.
Hello.
Me.
Uh, so now we have made, uh, a tool ourselves.
A custom tool.
So now we have an off the shelf tool for searching using the same API.
And we have a custom tool for sending a push notification using the nifty pushover package.
Okay.
And we can put both of these tools in a list of tools.
All right.
Then we actually get to use it.