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.

1.8.4 2023-04-10 07:10 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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 }