Google's Gemini AI In Laravel

Google's Gemini AI In Laravel

Dhaval Baldha

01 Mar 2024

8 MINUTES READ

Introduction

Artificial intelligence is a rapidly changing field, and Google is leading the way in innovation in this area. Google just released Gemini, their most advanced and potent AI model to date. This ground-breaking new model has the power to drastically alter the way we interact with computers and the wider environment.

Google AI, the company's research branch, has released Gemini, its most recent and potent artificial intelligence model. This ground-breaking model can handle jobs other than text, such as code, audio, graphics, and video, and it has the potential to completely transform the artificial intelligence sector.

What is Google AI Model Gemini?

Large language models (LLMs) like Meena and PaLM were successful, and Gemini builds on that foundation. But Gemini is much more advanced than its forerunners. It has the ability to comprehend and react to code, graphics, audio, and video in addition to text. Gemini's capacity to operate in multiple modes gives it exceptional power and adaptability.

Key Features of Gemini AI Model

The following are some of Gemini's salient characteristics that distinguish it from other AI models:

  • Multiple learning styles

    Gemini is capable of processing and comprehending a variety of data formats, such as text, code, audio, pictures, and video. This enables it to carry out an extensive variety of duties, including creating various creative text formats, translating across languages, producing various types of creative content, and providing you with enlightening answers to your inquiries, regardless of how bizarre, difficult, or open-ended they may be.

  • Enhanced rationality and judgment

    Compared to earlier generations, Gemini can reason and make judgments more efficiently thanks to its sophisticated architecture. This is partly because of its capacity to comprehend and draw conclusions from the connections among various kinds of data.

  • Flexibility

    Because of its multimodality, Gemini may be used for a wide range of jobs and sectors, including content production and software development.

  • Availability

    Like PaLM 2, Google intends to release Gemini in various sizes and capacities to cater to a broader user base.

  • Capabilities to generate

    Gemini is capable of creating unique and creative text, code, music, and visuals. For those in the creative industries, like writers, artists, and musicians, this makes it a handy tool.

  • The ability to scale

    Because Gemini is scalable, it may be readily adjusted to a variety of jobs and applications. It is therefore a useful tool for companies and organisations of all kinds.

  • Benefits of Google AI Model Gemini

    There are numerous potential benefits to being a Gemini. Here are a handful of instances:

  • Enhanced client support

    Gemini can be used to build chatbots that offer more individualized and beneficial client support.

  • Improved instruction

    Gemini can be used to design customized learning programs that meet the unique requirements of every student.

  • Medical diagnosis

    Gemini can be used to evaluate medical data and pictures to aid physicians in making more precise disease diagnoses.

  • Scientific finding

    Large scientific data sets can be analysed with Gemini to aid in the discovery of new information by researchers.

  • Creative Expression

    Using Gemini to produce original works of art and entertainment is possible.

AI's Future with Gemini

An important turning point in artificial intelligence development has been reached with the debut of Gemini. This formidable new model could revolutionize numerous elements of our life. The potential advantages of Gemini are enormous, even though there are still certain obstacles to be addressed, such as guaranteeing this technology's security and moral application. We may anticipate seeing many more ground-breaking and inventive uses of this technology in the years to come as Gemini develops further.

How to Install Gemini API Client for Laravel

Installation

To use Google's Gemini API, you must have an API key. To obtain an API key, go to Google AI Studio.

Installing the Gemini API Client for Laravel with Composer is the first step.

composer require gemini-api-php/laravel

Configuration

The client can be configured in two different ways.

Variables in the environment

You can use the API key you received from Google AI studio to set the GEMINI_API_KEY environment variable.

In your.env file, add the following line.

GEMINI_API_KEY='YOUR_GEMINI_API_KEY'

Configuration file

You can also run the following command to create a configuration file in your applications config folder.

php artisan vendor: publish --provider=GeminiAPI\Laravel\ServiceProvider

The Gemini API client can now be configured by editing the config/gemini.php file.

How to use

Text Generation


    use GeminiAPI\Laravel\Facades\Gemini;

    print Gemini::generateText('PHP in less than 100 chars');            
            
    // PHP: A scripting language that runs on servers that is used to make dynamic websites.
    // Open-source, often used, and simple to learn.                
                

Text Generation Using Image File


    use GeminiAPI\Laravel\Facades\Gemini;

    print Gemini::generateTextUsingImageFile(
        'image/jpeg',
        'horse.jpg',
        'Explain what is in the image',
    );
    
    // A horse is seen in the picture standing on Earth.
    // The blazing emblem on the forehead of the metal horse.
    // There's a web of luminous lines all around the Earth.
    // The background of the image is covered in stars.
        

Text Generation Using Image Data


    use GeminiAPI\Laravel\Facades\Gemini;

    print Gemini::generateTextUsingImage(
        'image/jpeg',
        base64_encode(file_get_contents('horse.jpg')),
        'Explain what is in the image',
    );            
    
    // A horse is seen in the picture standing on Earth.
    // The blazing emblem on the forehead of the metal horse.
    // There's a web of luminous lines all around the Earth.
    // The background of the image is covered in stars.
    
        

Chat Session (Multi-Turn Conversations)


    use GeminiAPI\Laravel\Facades\Gemini;

    $chat = Gemini::startChat();
    
    print $chat->sendMessage('Hello Techvoot in PHP');                   
    
    // echo "Hello Techvoot!";
    // This code will print "Hello Techvoot!" to the standard output.        
    
    print $chat->sendMessage('in Go');
    
    // fmt.Println("Hello Techvoot!")
    // This code will print "Hello Techvoot!!" to the standard output.
    

Chat Session with History


    use GeminiAPI\Laravel\Facades\Gemini;

    $history = [
        [
            'message' => 'Hello Techvoot in PHP',
            'role' => 'user',
        ],
        [
            'message' => << 'model',
        ],
    ];
    $chat = Gemini::startChat($history);
    
    print $chat->sendMessage('in Go');                              
    
    // fmt.Println("Hello Techvoot!")
    // This code will print "HelloTechvoot!" to the standard output.
        

Text Embeddings


    use GeminiAPI\Laravel\Facades\Gemini;

    print_r(Gemini::embedText('PHP in less than 100 chars'));                                        
    
    // [
    //    [0] => 0.041395925
    //    [1] => -0.017692696
    //    ...
    // ]    
        

Tokens counting


    use GeminiAPI\Laravel\Facades\Gemini;
    print Gemini::countTokens('PHP in less than 100 chars');                                       
    
    // 10      
        

Listing models


    use GeminiAPI\Laravel\Facades\Gemini;

    print_r(Gemini::listModels());                                          
    
    //[
    //  [0] => GeminiAPI\Resources\Model Object
    //    (
    //      [name] => models/gemini-pro
    //      [displayName] => Gemini Pro
    //      [description] => The best model for scaling across a wide range of tasks
    //      ...
    //    )
    //  [1] => GeminiAPI\Resources\Model Object
    //    (
    //      [name] => models/gemini-pro-vision
    //      [displayName] => Gemini Pro Vision
    //      [description] => The best image understanding model to handle a broad range of applications
    //      ...
    //    )
    //]          
        

Integrating Gemini Pro Vision in Laravel

Thanks to the user-friendly interface offered by the Gemini PHP package, using Gemini Pro Vision for image or video analysis is simple. You can ask the AI to interpret an image in the following ways:


    use Gemini\Laravel\Facades\Gemini;
    use Gemini\Types\Blob;
    use Gemini\Types\MimeType;
    
    $result = Gemini::geminiProVision()->generateContent([
        'What is this picture?',
        new Blob(
            mimeType: MimeType::IMAGE_JPEG,
            data: base64_encode(file_get_contents('your-image-url.jpg'))
        )
    ]);
    
    echo $result->text();            
        

Here, we are requesting that Gemini Pro Vision examine a picture and provide a description of what it observes. In addition to the picture data you submit as a Blob object with the base64-encoded image, the API expects a question. This capability can completely change the way users engage with your application by enabling features such as content-based recommendation systems, automatic image tagging, and even accessibility improvements through the provision of text descriptions for visual material.

Conclusion

In conclusion, Google's Gemini AI model marks a significant milestone in the field of artificial intelligence. Its versatility, with the ability to process and comprehend various data formats such as text, code, audio, images, and video, sets it apart from its predecessors. Gemini's enhanced rationality, flexibility, scalability, and creative generation capabilities make it a powerful tool for a wide range of Applications across industries.


Dhaval Baldha
Dhaval Baldha

Co-founder

Dhaval is a visionary leader driving technological innovation and excellence. With a keen strategic mindset and deep industry expertise, he propels the company towards new heights. His leadership and passion for technology make him a cornerstone of Techvoot Solutions' success.

Linkedin
Hire Skilled Developer

*Please fill all the required fields

Get our Newsletter

Customized solutions for your projects

*Please fill all the required fields