krzar / laravel-openai-api
v0.3.6
2024-09-18 08:06 UTC
Requires
- php: ^8.2
- illuminate/http: ^11.0
- illuminate/support: ^11.0
- krzar/array-dto: ^1.1
README
This package allow you to connect to OpenAI API and use it in your Laravel application.
Requirements
- Laravel 11.x
- PHP 8.2+
Installation
composer require krzar/laravel-openai-api
Usage
For more details about OpenAI API visit OpenAI API
Configuration
Add your OpenAI API key to your .env
file:
OPENAI_API_KEY=your-api-key OPENAI_ORGANIZATION=your-organization OPENAI_PROJECT=your-project
Config file
You can publish and edit the configuration file:
php artisan vendor:publish --provider="KrZar\OpenAi\OpenAiServiceProvider"
Usage
Example of usage chat endpoint:
use KrZar\LaravelOpenAiApi\Chat\ChatConnector; use KrZar\LaravelOpenAiApi\Chat\ValueObjects\ChatModel; $chatConnector = new ChatConnector(); $response = $chatConnector->createCompletion('Send me random text', ChatModel::GPT4o);