PHP and WP AI Client SDK

Hi there. I want to I wanted to create this um this quick video to summarize a little bit the content of the stream we did last Friday about the PHP AI client. So in this video I want to summarize a little bit the ideas that we covered in the last stream but also to clarify a few things
that I learned after the session. So yeah let's go for it. Okay so we talked about the PHP AI client SDK. One of the things I wanted to clarify is that in the in the post where
this idea was announced, the idea of creating a PHP AI client. There was this section here that talked about two composer packages. And one of the things that I learned after the the stream last Friday was that these two packages, this was the idea of the packages as published on July 2025.
But after that there has been like two packages released. One of them was the PHP AI client and the other one is the WP AI client. So this is the agnostic WordPress one and this is the specific WordPress one. This one the WordPress one is built on top of
the PHP one. And this is really the starting point for any plug-in that wants to use this AI client because this package internally uses this one. So we kind we can forget about this one unless we are working on a project that is not specifically related to WordPress. We
can just focus on this one. And this other one can be used in other projects outside of workers. Let's focus on this one. In the code we created the other day, I struggled a bit with the with the credentials. But one of the cool things about this
about this Dolbyp AI client as announced here is that it integrates with uh ZVP admin for credentials. That means that if we initialized a specific um class um provided by this package, we will get automatically a a screen from where we
can enter the API credentials and that will unblock the rest of the things. So I think this is a a clear idea that I wanted to highlight here. If we check the code, we can see how we are doing this here. So with the auto load, we are um
automatically loading the name spacesh as we use them. And here when we do this or the AI client class we use the static method in it this is enabling this it's enabling let me see if I can find yeah it's enabling this AI credentials screen
inside the DVP admin which I I think it's um it's a great thing to take into account and a clear idea to start implementing um enabling AI in our plugins. this idea of okay if I initialize this method I get a screen where the final user can enter the credentials and that unblocks the use of the rest of
the methods because for example here the code once we have the credentials we can do things like this and If we enter in the cell, well, let me clear from here. We can call the different functions that are internally using the
static methods of the of the class. For example, we can prompt something and then from that prompt, we can generate some text. So here we are prompting for a we are asking for a random description of a WordPress plugin. That means that if we do
this, it will properly use the credentials to call the specific models. This is something managed internally by the by the class and we will get uh the output. In this case, this is a random description of a plug-in. If we call this again, we will get a diff different one. This is the Dolby Dolbyp social
sharer pro. This is completely um invented. We have social shader pro and social share boost. So it's another one. Okay, cool. Another cool thing that we can do is to generate an image using the AI models. To do that, we can use the prompt method of the AI client. This is a static
method. And then we can call the generate image. But for images is recommended to increase the the time out because by default I think is um yeah 30 seconds and 30 seconds is usually
not enough for image generation. So yeah, configuring the request so to increment the timeout for images is um recommended to not get errors because if we don't do this, we will probably get a timeout error. So with this in place, we can call this function. This function besides getting an image
generated by the model, it wraps it in the proper format to be consumed by other uh code in WordPress. I mean this method prompt and the generate image it actually returns a I think it's a base 64 format which is a bunch of characters like numbers and and letters. So we need
to do something with that if we want to really use it in our code. So this is non AI related code but what I'm doing here is to generate to save that into a file to generate the proper uh urls and and path file to file name paths.
So we can try this function inside the shell. It's going to take a little bit
There you go. Here's the image. If we click here, we can actually see the image being generated is this one. So
there you go., PHP and WP AI Client SDK, YouTube, 01kfxb595zgszrts5x5kfe47jg.