Looking to hire Laravel developers? Try LaraJobs

laravel-openai maintained by itsimiro

Description
A laravel package to integrate openai in laravel application
Author
Last update
2023/11/08 16:52 (dev-main)
License
Downloads
593

Comments
comments powered by Disqus

Laravel OpenAI

A laravel package to integrate openai in laravel application.

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.