Hi.
This lesson is very important because Google deprecated one of the library, the Google generative AI.
We used to talk to AI.
If you open link from the resources to this lesson, you will find out this library on the npm portal
page and you will see it's deprecated.
So Google tells us that for new gaming models, they created a new SDK, which we will use.
And if you scroll down, you will see that the current libraries they have and the mode of limited maintenance,
they do only critical bug fixes and no new features will be added.
And also the end of life of this library is 31st of August of 2025.
So let's switch to new SDK.
You will see the GitHub repository where you can find the library source code and also all the examples.
But I suggest you to open the documentation they provide at the top because it has much more examples.
So first switch to our code base and we need to uninstall the old library.
I will type npm uninstall and the library name.
And now let's copy paste the command to install the new library.
SEC.
It's added to our package.json file.
And if you scroll down and you will see that you need to import it from the different paths and the
different class name costs.
And if you open the source assistant, our Google Assistant, you will see we do it differently.
So I just paste a new library and you import here.
Yeah.
And let's see.
And now we need to init a class instance Stance and provide an object with API key prop.
We do it a bit differently here, so we use a new class.
We provide our API key.
It's an object we can still use same API key so it's not an issue.
And now let's switch here.
So uh.
Okay.
You see here we they suggest to use a generate content method.
We won't use it because it's for single requests where you need to just get an answer and you don't
need a history.
We use the chat history and that is why we open chats and chat documentation from the left menu.
And if you scroll down, you will see an example of how to create a chat and how to send a message and
of course the process, the result.
So I will just copy paste it and put it at the top and we will adopt it with you.
So the first we need to save chart to our class variable.
And then we need to use we need to pass a model from the props.
We just remove this model name.
And what else are also the class instance and name differently.
It named Google I and now we can remove the our old implementation.
So it's fine.
Now let's switch to send the response.
We need to provide an object with a prop message.
So I just will wrap it into braces and change the prop name.
And to get the response we can use just text prop.
So to test it works I will open application file.
First I will open a Google AI assistant.
Please check it.
Did you use the right assistant and then I will comment some code which is used to streaming just to
check our normal chat method works fine.
I will comment the loop, I will comment setting the streaming messages and I will set the result instead
of a chunk.
And now let's run our application and check everything works.
I need to open it.
I will open the network tab just to see.
In any cases it doesn't provide errors and I will just say type okay.
You see it works.
We send the request everything fine.
And now let's let's update the streaming method.
So if you scroll down you will see send message stream documentation how to use it I will open again
my Google AI file and same.
We need to wrap content into braces.
And also there are some changes how we process the result.
So we can remove dot stream and we can remove the function because we can get just the text from a chunk.
And I think it should work.
And now let's make our changes from the application component only changes where we commented the streaming.
You see I, I leave the change where we import the right assistant.
And now if I switch to our application refresh page and say hey, so you see it works and you see it,
make a request to the stream which send the parts of the of the content.
So everything works.
But let's wait a minute.
Um, I showed you how to use the Google SDK or a token to AI, but in case you want to use an OpenAI
SDK, because it's also possible it's same as we do for the deep sig.
You see, we provide here as we define the OpenAI client and provides a base URL for the deep sig API,
provide API key, and just reuse all the methods.
So it also can be an option.
You will find another link for in resources for this lesson on a Google page, where it tells that you
can use an OpenAI client to talk to Google gaming models.
And here you will find an example of how to do it.
It's really easy.
You can follow this example if you need it, but I prefer to explain in the lessons the all possible
SDK how to integrate them.
So see you in the next lesson.