Skip to content

Commit

Permalink
Merge pull request #13 from marcelooblan2016/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
marcelooblan2016 authored Nov 21, 2023
2 parents 4b1a78b + 32e0cd9 commit cc43b88
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 26 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"extra": {
"laravel": {
"providers": [
"Marxolity\\OpenAi\\Providers\\OpenAIServiceProvider"
"Marxolity\\OpenAi\\OpenAIServiceProvider"
]
}
},
Expand Down
6 changes: 6 additions & 0 deletions config/open-ai.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
'api_key' => env('OPENAI_API_KEY'),
'default_model' => env('OPENAI_DEFAULT_MODEL', 'gpt-3.5-turbo'),
];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Marxolity\OpenAi\Providers;
namespace Marxolity\OpenAi;

use Illuminate\Support\ServiceProvider;
use Marxolity\OpenAi\Services\Ai\OpenAi;
Expand All @@ -17,9 +17,8 @@ public function register()
{
$this->app->bind(AiInterface::class, OpenAi::class);

$this->mergeConfigFrom(__DIR__.'/../config/ai.php', 'ai');
$this->mergeConfigFrom(__DIR__.'/../config/open-ai.php', 'open-ai');
}

/**
* Bootstrap services.
*
Expand All @@ -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');

}
}
}
4 changes: 2 additions & 2 deletions src/Services/Ai/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 0 additions & 8 deletions src/config/ai.php

This file was deleted.

15 changes: 10 additions & 5 deletions tests/AiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 [
Expand All @@ -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() ),
Expand All @@ -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() ),
Expand All @@ -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() ),
Expand All @@ -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() ),
Expand Down

0 comments on commit cc43b88

Please sign in to comment.