-: We are going to run the Assistants API
inside our code editor.
Let's do some coding.
The requirements here are the same as using the API
as we did before.
We are going to import OS just as before.
We are going to import time now
to perform delays on our code.
Then we are going to import OpenAI and load our API key.
Now we are going to instantiate the OpenAI client
just as before, and now the new stuff comes in.
We are going to use this line to upload our ebook.
Now we are going to create the assistant.
We are going to use this line
and we are going to set the instructions
just as before, you're a career assistant.
We are going to set the model to GPT-3.5 turbo just
to have a faster performance.
For the purpose of this exercise, we want to do Retrieval.
So if you want to activate Retrieval, you just have
to erase these hashtags
and you can use Retrieval just as before.
So let's run this.
So now the first thing we have to do is go
to Open AI's playground
and you'll see that here we have
the assistant we just created.
We are going to copy the ID
and we are going to paste it here.
There we go.
So we are going to run this cell block
and we should get the assistant's answer.
So don't worry if you get lost
and you think this is too long.
Basically here we are getting, fetching the assistants.
It's going to print "Assistant located."
Then we are going to create a thread.
Then we are going to post the message into the thread.
"I want to build a career in AI," just as before.
Then we are going to run just as we did before
in the playground.
We are going to run the thread through the assistant
and then here we have the processing.
So let's run this and see how much time it takes.
There we go. "Assistant Located, Thread Created,
Thread Ready, Assistant Loaded"
and "Run Started - Please wait."
So maybe we have to wait a little bit here.
Okay, just we have the answer.
Well, this got way faster because we are just
using ChatGPT 3.5 and we are not using Retrieval.
So here it says, "To get started,
could you tell me a little bit more about
your background and current level in AI?"
Great.
So now if we want to continue the conversation,
we just have to run the code again,
but taking it from the message part.
So we are going to post a new message.
"I am an engineer and I know Python on a basic level,"
and we are going to run that through the thread
and then we are going to do the processing.
So let's run this and see what we get.
There we go. The same sequence.
There we go. Great.
"It's fantastic that you have a background
in engineering and some Python.
Building a career in AI will definitely
align with your skills. It's important to..."
Okay, so we have another answer.
So if we wanted to continue the conversation just
as we did in the playground, we go so on
and so forth with this code.
So that's it about running the Assistants API
inside our code editor.
Now we are going
to talk a little bit more about custom functions.