itsimiro / laravel-openai
A laravel package to integrate openai in laravel application
v1.0.5
2023-11-08 15:52 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.5
- laravel/framework: ^9.46.0|v10.0.0|^10.1.5
- spatie/laravel-data: ^3.1
Requires (Dev)
- phpunit/phpunit: ^10.0
- spatie/ray: ^1.28
This package is auto-updated.
Last update: 2024-11-08 18:05:43 UTC
README
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:
- Completions
- Chat
- Edits
- Models
- Images
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.