All right, back to the lab.
Back to our project.
Time to work with tools.
I am in the week two folder in JupyterLab, and I'm launching day four.
It's time for us to bring together what we've done so far to make a customer service assistant for a
fictitious airline.
We start with some imports.
As usual, we initialize a load of key.
We're going to use GPT four mini today, and the OpenAI initialization is there.
The system message.
You're a helpful assistant for an airline called flight I, flight II flight A, however you want to
call it.
There it is.
Give short, courteous answers no more than one sentence.
Always be accurate.
If you don't know the answer, say so.
This, of course, a very good type of, uh, system prompt.
Um, if you're, uh, want to have a strong focus on lack of hallucinations on truthfulness.
So we run that.
Then this is something you're now very familiar with.
This is the chat function in the style that Gradio expects it.
It takes a message, it takes history, and it then builds the style that is expected by OpenAI.
You may notice this looks a bit shorter than before.
And that's because this time I'm not streaming back results.
I think we've done enough of that.
And since we're going with these short responses, streaming is probably overkill.
Let's see this in action.
Up it comes.
We know Gradio so well now.
We don't need to show off about it and we can say hi there.
Hello, how can I assist you today?
I want to go to London, my hometown.
I always want to go there.
Great choice.
Would you like to help finding flights to London?
Yes.
How much is a ticket?
I don't have real time pricing, but you can check our website or app for the latest ticket prices.
London.
So you know it's good to see as instructed.
It does not hallucinate prices.
It doesn't try and go there.
It does what it's told, and you can also see it's giving short one line responses just as we asked.
Okay, back we go.
So it is time to talk about tools, an incredibly powerful feature provided by the frontier LMS.
You can write a function, have it call that function as part of its response.
Sounds almost spooky.
We're giving it the power to run code on our machine.
As I said, it's just a kind of story and that will soon be very clear to you.
So let's start by making ourselves a function, a function that is going to be a useful function that
we want to arm our alarm with.
And that function is going to be called get ticket price given a city.
So uh, it's going to begin by printing.
Get ticket price called for destination City.
And we're doing that so that we can watch later to see when this function is called.
Uh, what we do is we take the destination city and we make it lowercase.
So this works and we look it up in this dictionary where we've got lowercase cities and prices.
If it doesn't find it, it says unknown.
Let's just add one in here.
Why not change things on the fly?
Probably break everything.
Hopefully not.
Let's give ourselves Berlin and a nice, cheap, special deal for for flights to Berlin.
Why not?
Um.
Okay, let's run that.
So we will now try this out.
Get ticket price to Berlin, see what we get.
And it says tool, get ticket price.
Called for Berlin for $99.
Now you might be thinking to yourself.
What does he mean, tool?
This isn't a tool, it's just a function.
And the answer is for now, it's just a function.
We're about to make it into a tool.
I don't know if you actually sound that way, but that's how you sound in my mind.
So anyway, that that is us creating our tool.
Now, the process of putting these tools into our interface with an LLM is a bit storied.
It's not going to be as simple as bringing up a Gradio interface.
Regrettably, uh, it's more involved.
There's good reason for that.
And we'll find out why.
Um, but it is a little bit more involved.
Um, but the good news is it's very much a sort of cookie cutter style that can be replicated for other
function calls for other tools.
So you'll be able to reuse this for your own projects.
And I very much hope you do.
One of the intentions of having these useful projects in here is so that you can then take this as a
resource and use these bits of code for your own projects.
Um, and I'll certainly be recommending that you try adding your own tools.
So you should be closely following this.
Uh, and the first thing I'm going to mention is that we need to build a particular dictionary structure
that's required to describe the function we just wrote.
And this is what it looks like.
Price function, I'll call it.
You call it anything you want.
You give it a name and you describe it.
And the way you describe it is in plain Old English, because this is going to be given to the LLM so
that it can understand when is it appropriate to call this function.
So it says get the price of a return ticket to the destination city.
Call this whenever you need to know the ticket price.
For example, when a customer asks how much is a ticket to the city?
So giving it an example is always a good, good technique.
And that's what we're using here.
And then you provide the parameters in this setup here.
And our function has one parameter destination city.
And that is what the parameter does.
So that's how you describe the function that you're using.
And you can see I say that it's a required parameter.
So that is the setup.
And at this point I'm going to pause for a moment.
And in the next video we're going to keep going.
And we're going to arm the LLM with this function.
See you there.