So we're going to make a call to GPT four.
Oh, that's going to ask it to look through a set of links, figure out which ones are relevant, and
then replace them with fully qualified links.
Um, and it's going to be a great, a great way of using llms because it requires particularly for selecting
which links are relevant.
It needs a sort of nuanced reasoning process.
Uh, so we're going to we're going to not only are we going to to use GPT four for this purpose, we're
going to ask it to respond in the form of JSON in a way that specifies exactly the information that
we need back.
Now, later on, we're going to cover a technique called structured outputs, which is when we require
the LLM to respond with a very specific format.
We effectively we specify the format that it needs to respond in.
We're not going to do this today.
We're just going to simply ask for JSON back.
And we're going to tell it the format that it needs to use to reply.
And it's going to be great.
Uh, this works well for simple requests like this.
When you get more sophisticated, you you might need to use structured outputs.
And in week eight, when we build our Agentic AI framework, we're going to do just that.
But for now, this is what we do.
So we're going to to create a system prompt.
The system prompt is where, of course we describe the task at hand and how it's to go about doing it.
That is where we will be supplying this information.
Here's the system prompt.
You are provided with a list of links found on a web page.
You are able to decide which of these links will be most relevant to include in a brochure about the
company, such as links to an about page or a company page, or a careers jobs page.
You should respond in JSON as in this example.
And then there is an example passed in.
And when I said we're working with one shot prompting, that's really what I meant by giving it a specific
example that it could use with an about page and a careers page, and the way that we're specifying
the format is simply by giving it an example you can see we're asking for a dictionary.
It will have a single attribute links.
And that links will be a list of again dictionaries with type and URL in each one.
And that URL is the full URL.
So let me run this cell.
And just to make sure that this is clear to you, let me just print link system prompt.
So we now have a variable.
And this is what that variable contains.
We print it out.
We'll get the carriage returns as well.
Let's have a look at this.
Here it is.
So this is exactly what we are going to instruct the LLM to do in our system prompt.
And now we're going to write a function get links user prompt.
And this is what it looks like.
It will take a website object.
And it's going to say here is a list of links on the website of blah.
Please decide which are relevant web links for a brochure about the company.
Respond with a full your URL do not include and a few things not to include and then list out the links
by one by one and return that.
So this will make more sense if we look at an actual example.
So let's call get Links user prompt and we'll pass in editor which is of course as before editor.
Is this one up here.
It's going to be looking at these links.
So let's see what this user prompt looks like.
And you should run this to and get a sense for it.
This is what the user prompt would look like.
It's sorry it says exactly what I just said.
Uh, it tells it that we're looking at this website, that fine website.
Uh, and then here are the links.
Some might be relative and you should summarize and you should you should select the ones that are relevant.
Okay.
And now it's time to put all of this into a function which is going to call OpenAI.
And here it is get links URL.
So we'll create a new website object for that URL.
And now we call this.
And I went through this quickly last time, and now it's time to spend a little bit more time on this.
We call OpenAI chat, which is the main API for chats completions, which is the one that we will almost
always use.
Is that the the API, which is the standard API where we're saying your task is to keep going, is to
is to complete this conversation.
And we create something on the completions API and it takes, as before, a model and messages the model
we're passing in.
It was a variable.
We set GPT four mini right at the start.
Messages.
Hopefully this is already starting to be familiar to you.
The format that we use for messages is a list of dictionaries.
It's a list of dictionaries where each dictionary, each dictionary has a key role with either system
or user, a key content with the associated system message or user message.
So.
System system message user.
User message that is going in our messages list.
It's as simple as that.
I hope that this is completely connecting for you.
There is one little extra detail, one tiny thing I'm throwing in there, and it's this here response
format.
So you could tell OpenAI that we want it to provide a JSON object back in its response.
And we do that by passing this in type JSON object.
So that is something which is it's actually Claude doesn't doesn't have this way of requiring a JSON
object back.
OpenAI does.
But OpenAI mentions in their documentation that even when you use this, it's still important that you
mention in your prompt that a JSON response is required.
It will only work if you do mention that explicitly in your prompt also.
So we do that.
What comes back is into this variable completion.
Actually, to keep this consistent with before, I'm going to change this to response because that's
what we called it last time.
There we go.
Uh, and, uh, what we then to to to actually get the final reply, we go response dot choices zero.
So what's this about?
Well, as it happens we can actually in the API request ask to have multiple variations if we want,
if we wanted it to generate several possible variations of the response.
And we haven't done that.
So we're only going to get back one.
Uh, and so those variations come back in the form of these choices.
But we've only got one.
So choices zero is getting us the one and the only choice of the response back.
So that's why you'll always see response dot choices zero dot message dot content is just simply drilling
down to what is actually the text message back.
So basically you get very familiar with these two two things because it's the same in many, many times
that we call the API.
We'll be doing the same thing OpenAI dot chat, dot completions, dot create and then with what comes
back it's response dot choices, zero Message content.
You will get to the point when you'll be reciting it in your sleep.
And then with what comes back, we're going to use the Json.load string function to then bring that
back as JSON.
Let's run that.
Okay.
So we're going to take the plunge.
We're going to call that that function and pass in the website anthropic comm.
So what are we expecting it to do.
We're expecting it to collect all of the links on that page and then call uh call GPT four mini and
say please select from this some links which you think are relevant and respond with them.
So let's see what we get.
Here we go.
It's going off now to OpenAI.
Well it's first it had to collect the anthropic page and back it comes.
And this is what we get type about page.
And there's a link to the about page a careers page, a team page, research enterprise pricing, API
and news.
How about that?
This is all actually great information that we would want on a brochure, and no doubt there are a ton
of links that it hasn't included.
Let's convince ourselves of that.
We can say, uh, anthropic is website and just pass this in.
And do anthropic dot links and we'll see what are all of the links that were on that page here?
They all are.
There's a ton of them like supported countries and lots of others.
You'll also see that there are many of them that are not fully, uh, the full URL, including the the
host name.
And so you'll see that and that our call to GPT four mini has very well selected a subset of these fully
qualified them and explained what they are.
I'd say that's a great result.
That was pretty easy to it's just step one of the two steps that we have to go through to build our
company brochure.
And I will see you in the next video for step two.