PHP Classes

Laravel GPT: Send questions to Laravel ChatGPT API using models

Recommend this page to a friend!
  Info   View files Documentation   View files View files (19)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2023-03-28 (8 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 94 This week: 3All time: 9,824 This week: 35Up
Version License PHP version Categories
laragpt 1.0.0Custom (specified...5PHP 5, Graphics, Text processing, Web..., A..., C..., A...
Description 

Author

This package can send questions to Laravel ChatGPT API using models.

It provides a Laravel service class that can send HTTP requests to the ChatGPT API Web server to perform several actions.

Currently, it can:

- Take chat messages and get responses from ChatGPT

- Transcribe audio files in MP3 with speech to text

- Edit a text and process editing instructions, for instance

- Create an image with a given size from a text description

- Edit an image to change it using editing instructions

- Create a variation of an image

Innovation Award
PHP Programming Innovation award winner
April 2023
Winner
ChatGPT became a popular application of artificial intelligence due to its capability to automatically process requests from humans and translate them into practical actions that are done in much less time than they would take if they were done in traditional methods.

This package provides a Laravel service PHP class that can perform several types of actions to process text, images, and audio using Chat GPT API.

Manuel Lemos
Picture of Eric Jumba
  Performance   Level  
Name: Eric Jumba <contact>
Classes: 1 package by
Country: United States United States
Age: ???
All time rank: 4406556 in United States United States
Week rank: 36 Up4 in United States United States Up
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Documentation

Laravel implementation of chatgpt, includes models listing and retrieving, completions prediction, chat completion from conversation, edits, images creation, image edit, image variations, audio translation and transcription.

Installation

You can install the package via composer:

composer require jumbaeric/laragpt

publish config file

php artisan vendor:publish

and select laragpt package to publish.

Add openai api key to your env variable

OPENAI_API_KEY=

Usage

All methods return Array


use Jumbaeric\Laragpt\Laragpt;

// Complete
// Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.
    $args = [
        'prompt' => 'Brainstorm some ideas combining VR and fitness', //required
        'model' => 'text-davinci-003',  //  required
    ];

    Laragpt::complete($args);

// Chat
// Given a chat conversation, the model will return a chat completion response.

Laragpt::chat([
        'model' => 'gpt-3.5-turbo', // required
        'messages' => [             // required
            [
                "role" => "system",
                "content" => "You are a helpful assistant."
            ],
            [
                "role" => "user",
                "content" => "Who won the world series in 2020?"
            ],
            [
                "role" => "assistant",
                "content" => "The Los Angeles Dodgers won the World Series in 2020."
            ],
            [
                "role" => "user",
                "content" => "Where was it played?"
            ],
        ],
        'temperature' => 1.0,   //  optional
        'max_tokens' => 4000,   //  optional
        'frequency_penalty' => 0,   //  optional
        'presence_penalty' => 0,    //  optional
    ]);

// Audio
// trascribe: Transcribes audio into the input language.
// translate: Translates audio into into English.

$type = "transcript"; // string: Required : value can be transcript or translation
Laragpt::audio([
            'model' => 'whisper-1',     //  required
            'file' => "audio.mp3",      //  required
            'prompt' => "",             //  optional
            'response_format' => '',    //  optional
            'temperature' => '',        //  optional
        ], $type);

// Edits
// Given a prompt and an instruction, the model will return an edited version of the prompt.
Laragpt::edits([
        'model' => 'text-davinci-edit-001', // required
        'input' => 'What day of the wek is it?',
        'instruction' => 'Fix the spelling mistakes',   //  required
        'n' => 1,   //  optional
        'temperature' => 1,   //  optional
        'top_p' => 1,    //  optional
    ]);

// Images
    $createArr = [ // $type = create
        'prompt' => 'A cute baby sea otter',
        'size' => '1024x1024',   //  required
        'n' => 1,   //  optional
    ] ;

    $ceateEditArr = [ // $type = createEdit
        'prompt' => 'A cute baby sea otter wearing a beret',    // required
        'image' => '@otter.png',                                //required
        'mask' => '@mask.png',
        'n' => 1,
        'size' => '1024x1024',
    ];

    $createVariationArr = [ // $type = variations
        'image' => '@otter.png',
        'n' => 2,
        'size' => '1024x1024',
    ];
    
    Laragpt::images($createArr, $type = 'create');

// Models
$model_id = null; // String : Optional : Lists all models when value is null, model set returns the model details
Laragpt::models($model_id);


Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email jumbaeric@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imageconfig (1 file)
Files folder imagesrc (3 files, 1 directory)
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file main.yml Data Auxiliary data

  Files folder image Files  /  config  
File Role Description
  Accessible without login Plain text file config.php Aux. Auxiliary script

  Files folder image Files  /  src  
File Role Description
Files folder imageOpenAI (9 files)
  Plain text file Laragpt.php Class Class source
  Plain text file LaragptFacade.php Class Class source
  Plain text file LaragptServiceProvider.php Class Class source

  Files folder image Files  /  src  /  OpenAI  
File Role Description
  Plain text file Audio.php Class Class source
  Plain text file Chat.php Class Class source
  Plain text file Completion.php Class Class source
  Plain text file Edits.php Class Class source
  Plain text file Embeddings.php Class Class source
  Plain text file Files.php Class Class source
  Plain text file Images.php Class Class source
  Plain text file Models.php Class Class source
  Plain text file OpenAI.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:94
This week:3
All time:9,824
This week:35Up