WEBVTT

00:00:00.340 --> 00:00:04.300
When using the OpenAI API,
the official recommendation

00:00:04.320 --> 00:00:08.119
in the official OpenAI documentation
is to use its

00:00:08.180 --> 00:00:11.580
Responses API. So when using the OpenAI

00:00:11.640 --> 00:00:15.560
package,
you wanna use this Responses object on the

00:00:15.600 --> 00:00:18.720
client to create responses with the AI.

00:00:18.760 --> 00:00:22.220
You can see that throughout the entire
OpenAI documentation.

00:00:22.260 --> 00:00:26.000
It's this more modern way of using the API
you wanna

00:00:26.060 --> 00:00:29.800
use. Now, since this is a bit more modern,
chances are that

00:00:29.840 --> 00:00:33.460
when you're following along,
this method might not be used.

00:00:33.470 --> 00:00:37.310
And for me here,
it did use the older approach using the

00:00:37.340 --> 00:00:41.140
which will also work, but
which does not follow the recommendations

00:00:41.180 --> 00:00:44.629
official documentation and
which does not support all the features

00:00:44.940 --> 00:00:48.630
OpenAI's API has to offer.
So I wanna switch.

00:00:48.720 --> 00:00:52.520
And of course,
we could make those tweaks manually,

00:00:52.560 --> 00:00:56.520
would probably be faster in this case,
because it simply means that

00:00:56.580 --> 00:00:57.800
we say

00:00:58.860 --> 00:01:02.760
client.responses.create
and we replace messages

00:01:03.060 --> 00:01:06.240
with input and just pass our prompt as the
text for

00:01:06.280 --> 00:01:10.040
that. But for demo purposes,
I'll not do it manually and I'll

00:01:10.080 --> 00:01:13.240
instead use AI, because I wanna dive

00:01:13.320 --> 00:01:16.580
into providing context to Cursor.

00:01:16.590 --> 00:01:20.160
And for that, I'll open a new chat so
that we have a

00:01:20.200 --> 00:01:24.130
brand new context window.
So all the information from

00:01:24.160 --> 00:01:27.480
the other chat is lost now in this new
chat.

00:01:27.500 --> 00:01:31.380
And I now want to instruct Cursor to
convert

00:01:31.390 --> 00:01:34.460
this code to use the new Responses API.

00:01:34.470 --> 00:01:37.790
And for that,
we'll do some more advanced context

00:01:37.800 --> 00:01:41.780
And I'll say instead of using the
Completions API,

00:01:41.840 --> 00:01:45.300
I mean, which we're currently using,
we should use the more modern Responses

00:01:45.620 --> 00:01:49.540
API. However, this is an instruction
that can

00:01:49.580 --> 00:01:53.100
be improved. First of all,
when specifying a

00:01:53.160 --> 00:01:56.850
file name like this, chances
are very high that Cursor will find

00:01:56.860 --> 00:02:00.410
it. Nonetheless, to be sure
that it knows what you're talking

00:02:00.480 --> 00:02:04.140
about,
a better way of referencing a file in this

00:02:04.240 --> 00:02:07.720
chat is to type @
and then this window for adding

00:02:07.800 --> 00:02:11.460
context will open.
Another way of getting there

00:02:11.470 --> 00:02:15.049
this add button here. Now,

00:02:15.080 --> 00:02:18.380
when you click that,
though the advantage of

00:02:18.440 --> 00:02:22.080
using the add key is
that you can control where it will be

00:02:22.200 --> 00:02:26.040
when you use that,
you'll have different kinds of context

00:02:26.120 --> 00:02:29.560
added. First,
you will typically see some files here,

00:02:29.620 --> 00:02:33.310
type, this also gets filtered. But besides

00:02:33.420 --> 00:02:37.079
files,
you can also reference documentation

00:02:37.160 --> 00:02:40.940
Cursor or terminal sessions,
different code from

00:02:41.000 --> 00:02:44.360
other branches,
or you could tell it to use the web

00:02:44.380 --> 00:02:47.800
Here, I wanna use the main.py file
and therefore I'll click on it,

00:02:47.820 --> 00:02:51.580
will do is it will load the content of
that file into this

00:02:51.600 --> 00:02:55.290
chat session and also add a clear
reference to this

00:02:55.320 --> 00:02:58.520
file,
so that in cases where you would have

00:02:58.560 --> 00:03:02.420
main.py files in the same project,
for example, you could make it very

00:03:02.460 --> 00:03:05.329
clear to which exact file you're
referring.

00:03:05.360 --> 00:03:08.840
So whenever you're adding some file
reference in your

00:03:08.880 --> 00:03:12.320
chat,
you wanna do it like this instead of just

00:03:12.420 --> 00:03:16.320
This will make sure
that the right context

00:03:16.329 --> 00:03:20.200
and Cursor knows what you're talking
about.

00:03:20.220 --> 00:03:24.200
Another problem is
that this instruction down here

00:03:24.260 --> 00:03:27.930
is not very clear. Since Cursor,
or to be more

00:03:27.940 --> 00:03:31.760
precise, the AI it's using,
does not know about

00:03:31.769 --> 00:03:35.200
this Responses API,
otherwise it probably would have used it

00:03:35.260 --> 00:03:38.020
already,
this instruction won't be very helpful.

00:03:38.100 --> 00:03:41.440
So what we could do here
is we could write something

00:03:41.450 --> 00:03:45.200
like,
"Search the web to learn how to use the

00:03:45.240 --> 00:03:49.140
Responses API," because Cursor has
built-in

00:03:49.180 --> 00:03:52.640
web search. You can see
that in the Cursor settings under

00:03:52.720 --> 00:03:56.490
Agents. There, if you scroll down,

00:03:56.540 --> 00:04:00.480
under Context,
you see the web search tool is enabled,

00:04:00.560 --> 00:04:03.960
and it must be enabled in order to unlock
web search.

00:04:04.000 --> 00:04:07.780
You can then also turn on auto accept to
make sure you're not getting asked

00:04:07.820 --> 00:04:11.570
before Cursor plans to search. If that
is turned off, Cursor will

00:04:11.570 --> 00:04:13.480
ask you if it is allowed to proceed.

00:04:13.520 --> 00:04:16.540
If you turn it on,
it will automatically proceed.

00:04:16.579 --> 00:04:20.200
So by adding this instruction,
you could increase the chances of

00:04:20.220 --> 00:04:24.140
Cursor doing the right thing,
of searching the web for how to use

00:04:24.200 --> 00:04:27.920
it. But since I already know how
that usage should look

00:04:28.000 --> 00:04:31.620
like,
it's much better to just provide

00:04:31.630 --> 00:04:35.510
So here I'll say,
"Here's some example from the official

00:04:35.540 --> 00:04:39.410
to use the Responses API."
And then what I like to do is

00:04:39.780 --> 00:04:43.320
I like adding some XML tags here, which
is not strictly

00:04:43.360 --> 00:04:47.140
required,
but which can help with structuring your

00:04:47.180 --> 00:04:50.620
very clear where an example starts
and ends, for example.

00:04:50.640 --> 00:04:54.540
So here I'll have OpenAI docs opening
and closing XML

00:04:54.580 --> 00:04:58.080
tags. And between those tags,
I'll just paste

00:04:58.160 --> 00:05:00.880
some text from the official documentation.

00:05:00.890 --> 00:05:04.620
And actually here,
I'll just click Copy page, which

00:05:04.660 --> 00:05:08.620
see on some pages, which gives me
that page content in Markdown.

00:05:08.660 --> 00:05:11.880
If such a feature does not exist,
we can also just copy and

00:05:11.960 --> 00:05:15.260
paste. But here I'll click Copy page.

00:05:15.760 --> 00:05:19.460
That gives me the Markdown, and
if I paste it in there, that was now added

00:05:19.500 --> 00:05:23.150
here. So now my message
is a lot longer because now it includes

00:05:23.200 --> 00:05:27.000
that complete extra example,
which should be some

00:05:27.040 --> 00:05:30.960
useful context. Again,
we could now switch to plan mode, but I'll

00:05:31.100 --> 00:05:34.840
actually run this in agent mode right away
because my instruction should be pretty

00:05:34.880 --> 00:05:38.570
clear here. And that
is how we can add very specific

00:05:38.620 --> 00:05:42.280
context, which AI usage in the end,
as mentioned,

00:05:42.300 --> 00:05:46.280
is all about.
You wanna provide all the required

00:05:46.540 --> 00:05:50.280
context and have very clear,
specific instructions with

00:05:50.560 --> 00:05:54.220
just the right context.
You definitely also wanna avoid

00:05:54.240 --> 00:05:56.400
providing too much context though.

00:05:56.420 --> 00:05:59.980
Instead, it's really about picking
and adding just the right

00:06:00.040 --> 00:06:03.130
context,
which is a skill you have to build over

00:06:03.140 --> 00:06:07.070
But that is what will allow you to get
great results out of tools

00:06:07.160 --> 00:06:10.820
like Cursor. So here, of course, it
was a very simple

00:06:10.980 --> 00:06:13.660
edit and therefore it's already done.

00:06:13.700 --> 00:06:17.620
Now, here it added some instructions
and then further down below the

00:06:17.680 --> 00:06:21.540
input, which is the content of the post,
and

00:06:21.660 --> 00:06:25.480
it did that because I shared the overall
document where I don't just

00:06:25.560 --> 00:06:29.320
have this simple example here,
but also more

00:06:29.360 --> 00:06:32.740
advanced examples where we have a split
between some general

00:06:32.820 --> 00:06:36.600
instructions,
which would apply to the overall chat

00:06:36.620 --> 00:06:40.360
building a chat,
and then the specific input of the actual

00:06:40.470 --> 00:06:44.420
currently needs to be processed.
But for a utility tool like ours,

00:06:44.460 --> 00:06:48.440
this is not really important.
So I will actually keep this, but also

00:06:48.520 --> 00:06:51.160
change the code a little bit and just use

00:06:52.640 --> 00:06:53.340
input here

00:06:55.340 --> 00:06:59.240
and remove this input key here
and then edit this post

00:06:59.280 --> 00:07:03.000
here and say,
"Here's the article content," and

00:07:03.040 --> 00:07:06.720
then just insert
that content like this into

00:07:06.760 --> 00:07:10.740
this string.
That's not something you have to do,

00:07:10.760 --> 00:07:14.640
do, of course. And then I'll add F here to

00:07:14.680 --> 00:07:17.610
make sure this gets properly injected.

00:07:17.610 --> 00:07:20.400
This is looking good
and therefore we can now test

00:07:20.480 --> 00:07:21.800
this.
