Use Google's Gemini AI in Laravel
Last updated on by Paul Redmond
Start using Google’s Gemini AI APIs in your Laravel application with the Gemini PHP package. This package for Laravel built around the Gemini PHP Client, providing a Facade to interact with the API and AI models available:
use Gemini\Laravel\Facades\Gemini; $result = Gemini::geminiPro()->generateContent('Hello'); $result->text(); // Hello! How can I assist you today?
The Gemini AI also can work with both text, image, and video simultaneously via the Gemini Pro Vision model. Given the following picture from this project’s readme, we can ask questions about the picture, like "What is this picture?"
Feeding the above image to the Gemini Pro Vision API is easy with this package, using the following code:
$result = Gemini::geminiProVision() ->generateContent([ 'What is this picture?', new Blob( mimeType: MimeType::IMAGE_JPEG, data: base64_encode( file_get_contents('https://storage.googleapis.com/generativeai-downloads/images/scones.jpg') ) ) ]); $result->text();/*The picture shows a table with a white tablecloth. On the table are two cupsof coffee, a bowl of blueberries, a silver spoon, and some flowers. There arealso some blueberry scones on the table.*/
This package also provides conveniences around streaming partial responses, testing fakes, and more. You can get started with this package on GitHub at google-gemini-php/laravel. Also, the official Gemini Docs and API Reference for Developers and gemini.google.com are excellent references.