mastashake08 / laravel-openai-api
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.
Fund package maintenance!
mastashake08
Patreon
cash.me/$mastashake08
Requires
- php: ^8.1
- illuminate/contracts: *
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpunit/phpunit: ^9.5
- dev-main
- 1.8.4
- 1.8.3
- 1.8.2
- 1.8.0
- 1.7.9
- 1.7.8
- 1.7.7
- 1.7.6
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.9
- 1.6.8
- 1.6.7
- 1.6.6
- 1.6.5
- 1.6.4
- 1.6.0
- 1.5.9
- 1.5.8
- 1.5.7
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.9
- 1.4.8
- 1.4.7
- 1.4.6
- 1.4.5
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.9
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.1
- 1.2.0
- 1.1.0
- dev-dependabot/github_actions/actions/checkout-4
- dev-has_prompts_trait
This package is auto-updated.
Last update: 2024-09-11 03:26:49 UTC
README
Installation
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')
];
Usage
Via Code
$laravelOpenaiApi = new Mastashake\LaravelOpenaiApi(); echo $laravelOpenaiApi->generateResult($type, $data);
Via Artisan
php artisan laravel-openai-api:generate-result
Via API
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
Text Example
{
"type": "text",
"prompt": "Rust is",
"n": 1,
"model": "text-davinci-003",
"max_tokens": 16
}
Image Example
{
"type": "image",
"prompt": "A cute baby sea otter",
"n": 1,
"size": "1024x1024"
}
Testing
composer test
Consider Sponsoring
Help me maintain this project, please consider looking at the FUNDING file for more info.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
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 }