diff --git a/README.md b/README.md index 2483a72..44c05ee 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,16 @@ *** A Laravel Package that facilitates effortless integration of the OpenAI API into PHP applications, ensuring seamless connectivity and interaction with OpenAI's services within the Laravel Framework. -| Supported Models| Note | Date| +###### Note: Please be advised that other GPT models may be utilized at your discretion, acknowledging associated risks. +--- +| Tested Models (Limited to `GPT Models`)| Note | Date| | ------------- | ------------- |-----:| -| `gpt-3.5-turbo`| | Nov 20, 2023| +|`gpt-3.5-turbo`|**`default`**| Nov 20, 2023| | `gpt-3.5-turbo-1106`| | Nov 20, 2023| | `gpt-4` | The account must reach at minimum **Tier 1** status. | Nov 20, 2023| | `gpt-4-vision-preview` | The account must reach at minimum **Tier 1** status. | Nov 20, 2023| + --- ## Installation Install the package via Composer [Reference](https://packagist.org/packages/marxolity/open-ai): @@ -17,9 +20,9 @@ composer require marxolity/open-ai ``` --- ## Configuration -Publish the package configuration: (config/ai.php) +Publish the package configuration: (config/open-ai.php) ```bash -php artisan vendor:publish --provider="Marxolity\OpenAi\Providers\OpenAIServiceProvider" --tag="config" +php artisan vendor:publish --provider="Marxolity\OpenAi\OpenAIServiceProvider" --tag="config" ``` Set up your environment variables: ```bash diff --git a/composer.json b/composer.json index 10b9ef1..2cc0bc8 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "extra": { "laravel": { "providers": [ - "Marxolity\\OpenAi\\Providers\\OpenAIServiceProvider" + "Marxolity\\OpenAi\\OpenAIServiceProvider" ] } }, diff --git a/config/open-ai.php b/config/open-ai.php new file mode 100644 index 0000000..4341673 --- /dev/null +++ b/config/open-ai.php @@ -0,0 +1,6 @@ + env('OPENAI_API_KEY'), + 'default_model' => env('OPENAI_DEFAULT_MODEL', 'gpt-3.5-turbo'), +]; \ No newline at end of file diff --git a/src/Providers/OpenAIServiceProvider.php b/src/OpenAIServiceProvider.php similarity index 73% rename from src/Providers/OpenAIServiceProvider.php rename to src/OpenAIServiceProvider.php index 723f7f7..930a2a7 100644 --- a/src/Providers/OpenAIServiceProvider.php +++ b/src/OpenAIServiceProvider.php @@ -1,6 +1,6 @@ app->bind(AiInterface::class, OpenAi::class); - $this->mergeConfigFrom(__DIR__.'/../config/ai.php', 'ai'); + $this->mergeConfigFrom(__DIR__.'/../config/open-ai.php', 'open-ai'); } - /** * Bootstrap services. * @@ -28,11 +27,10 @@ public function register() public function boot() { if ($this->app->runningInConsole()) { - // php artisan vendor:publish --provider="Marxolity\OpenAi\Providers\OpenAIServiceProvider" --tag="config" + // php artisan vendor:publish --provider="Marxolity\OpenAi\OpenAIServiceProvider" --tag="config" $this->publishes([ - __DIR__.'/../config/ai.php' => config_path('ai.php'), + __DIR__.'/../config/open-ai.php' => config_path('open-ai.php'), ], 'config'); - } } } \ No newline at end of file diff --git a/src/Services/Ai/Base.php b/src/Services/Ai/Base.php index f0be07e..fafaad0 100644 --- a/src/Services/Ai/Base.php +++ b/src/Services/Ai/Base.php @@ -24,8 +24,8 @@ class Base protected $endPoint = 'https://api.openai.com/v1/chat/completions'; public function __construct() { - $this->apiKey = config('ai.open_ai.api_key'); - $this->model = config('ai.open_ai.default_model'); + $this->apiKey = config('open-ai.api_key'); + $this->model = config('open-ai.default_model'); } public function sendRequest() diff --git a/src/config/ai.php b/src/config/ai.php deleted file mode 100644 index 7495ef9..0000000 --- a/src/config/ai.php +++ /dev/null @@ -1,8 +0,0 @@ - [ - 'api_key' => env('OPENAI_API_KEY'), - 'default_model' => env('OPENAI_DEFAULT_MODEL', 'gpt-3.5-turbo'), - ], -]; \ No newline at end of file diff --git a/tests/AiTest.php b/tests/AiTest.php index 1d84e0b..7bdb918 100644 --- a/tests/AiTest.php +++ b/tests/AiTest.php @@ -3,7 +3,7 @@ use Orchestra\Testbench\TestCase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Http; -use Marxolity\OpenAi\Providers\OpenAIServiceProvider; +use Marxolity\OpenAi\OpenAIServiceProvider; use Marxolity\OpenAi\Facades\OpenAi; use Mockery\MockInterface; use Arr; @@ -21,6 +21,11 @@ protected function getPackageProviders($app) return [OpenAIServiceProvider::class]; } + protected function configLoad() + { + $this->app['config']->set('open-ai.api_key', 'api-key'); + } + public function response() { return [ @@ -47,7 +52,7 @@ public function response() public function testAiResponseArray() { - $this->app['config']->set('ai.open_ai.api_key', 'api-key'); + $this->configLoad(); Http::fake([ '*' => Http::response( $this->response() ), @@ -62,7 +67,7 @@ public function testAiResponseArray() public function testAiResponseJson() { - $this->app['config']->set('ai.open_ai.api_key', 'api-key'); + $this->configLoad(); Http::fake([ '*' => Http::response( $this->response() ), @@ -77,7 +82,7 @@ public function testAiResponseJson() public function testAiResponseXml() { - $this->app['config']->set('ai.open_ai.api_key', 'api-key'); + $this->configLoad(); Http::fake([ '*' => Http::response( $this->response() ), @@ -92,7 +97,7 @@ public function testAiResponseXml() public function testAiSend() { - $this->app['config']->set('ai.open_ai.api_key', 'api-key'); + $this->configLoad(); Http::fake([ '*' => Http::response( $this->response() ),