itsimiro/laravel-openai

A laravel package to integrate openai in laravel application

v1.0.5 2023-11-08 15:52 UTC

This package is auto-updated.

Last update: 2024-04-08 16:48:46 UTC


README

A laravel package to integrate openai in laravel application.

GitHub Workflow Status (master) Packagist Downloads Latest Version

Installation

You can install the package via composer:

composer require itsimiro/laravel-openai

Publish the configuration file:

php artisan vendor:publish --provider="Itsimiro\OpenAI\Providers\OpenaiServiceProvider"

This will create a config/laravel-openai.php configuration file in your project. Be sure to specify the key in your environment file.

OPENAI_API_KEY=sk-*

Endpoint Support

Available now:

Coming soon:

  • Images
    • Create image edit
  • Audio
    • Create transcription
    • Create translation
  • Embeddings
    • Create embeddings

Usage

Create completion:

$openAI = $this->container->make(\Itsimiro\OpenAI\Services\OpenAI::class);

$result = $openAI->getDavinci()->completion(new \Itsimiro\OpenAI\Services\DataTransferObjects\CompletionParameters()); // Itsimiro\OpenAI\Services\API\Results\CompletionResult

$result->getChoices(); // Choices from OpenAI.

Create chat:

$openAI = $this->container->make(\Itsimiro\OpenAI\Services\OpenAI::class);

$result = $openAI->getDavinci()->chat(new ChatParameters()); // Itsimiro\OpenAI\Services\API\Results\CompletionResult

$result->getChoices(); // Choices from OpenAI.

Create image:

$openAI = $this->container->make(\Itsimiro\OpenAI\Services\OpenAI::class);


$result = $openAI->getDalle()->createImage(new CreateImageParameters(
  'dog with a bone',
  2,
  responseFormat: ImageResponseFormatEnum::URL
 ));

$result->getImages(); // Generated images

See the documentation for more details on using OpenAI.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

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