You can install the package via composer:
composer require mastashake08/laravel-openai-api
You can publish and run the migrations with:
php artisan vendor:publish --tag="openai-api-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="openai-api-config"
This is the contents of the published config file:
/*
|--------------------------------------------------------------------------
| OpenAI API Key and Organization
|--------------------------------------------------------------------------
|
| Here you may specify your OpenAI API Key and organization. This will be
| used to authenticate with the OpenAI API - you can find your API key
| and organization on your OpenAI dashboard, at https://openai.com.
*/
'api_key' => env('OPENAI_API_KEY'),
'organization' => env('OPENAI_ORGANIZATION'),
'api_url' = env('OPENAI_API_URL')
];
$laravelOpenaiApi = new Mastashake\LaravelOpenaiApi();
echo $laravelOpenaiApi->generateResult($type, $data);
php artisan laravel-openai-api:generate-result
You set the OPENAI_API_URL in the .env file if a value is not set then it defaults to /api/generate-result
/api/generate-result POST {openai_data}
The data object requires a type
property that is either set to text or image. Depending on which type then provide the JSON referenced in the OpenAI API Reference
{
"type": "text",
"prompt": "Rust is",
"n": 1,
"model": "text-davinci-003",
"max_tokens": 16
}
{
"type": "image",
"prompt": "A cute baby sea otter",
"n": 1,
"size": "1024x1024"
}
composer test
Help me maintain this project, please consider looking at the FUNDING file for more info.
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information. { "name": "mastashake08/laravel-openai-api", "description": "Add an OpenAI API easily into your projects.", "version": "1.6.0", "description": "Add an OpenAI API and Artisan command easily into your projects. Generate images, or text. Can be integrated with Laravel Sanctum for token based access.", "version": "1.6.2", "keywords": [ "mastashake08", "laravel", "laravel-openai-api", "chatGPT", "OpenAI" "OpenAI", "Laravel Sanctum" ], "homepage": "https://github.com/mastashake08/laravel-openai-api", "license": "MIT", "minimum-stability": "dev", "prefer-stable": true }