Skip to content

Commit

Permalink
Improve extension installation
Browse files Browse the repository at this point in the history
  • Loading branch information
drejmanMacopedia committed Apr 3, 2023
1 parent 1d7c9eb commit 45a6855
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ Install composer dependency
composer require macopedia/akeneo-openai-translator
```

register bundle in `config/bundles.php`

```php
return [
'Macopedia\Translator\MacopediaTranslatorBundle' => ['all' => true]
];
```

define Open AI Key in `.env` file:

```dotenv
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"@cs:fix",
"@phpstan",
"@phpunit"
],
"post-install-cmd": [
"make upgrade-front"
]

},
Expand Down
9 changes: 4 additions & 5 deletions src/Macopedia/Translator/Client/OpenAiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ class OpenAiClient
public function __construct(
private LoggerInterface $logger,
private string $model,
string $apiKey,
string $organization = null,
?string $apiKey = '',
?string $organization = null,
private bool $logging = false
)
{
) {
$this->client = new OpenAi($apiKey);
$this->client->listModels();

Expand Down Expand Up @@ -54,7 +53,7 @@ public function ask(string $role, string $content): ?Response
}


#[ArrayShape(['model' => "string", 'messages' => "\string[][]"])]
#[ArrayShape(['model' => 'string', 'messages' => "\string[][]"])]
private function generateMessage(string $role, string $content): array
{
return [
Expand Down
4 changes: 4 additions & 0 deletions src/Macopedia/Translator/MacopediaTranslatorBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@

final class MacopediaTranslatorBundle extends Bundle
{
public function getParent()
{
return null;
}
}
4 changes: 3 additions & 1 deletion src/Macopedia/Translator/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
parameters:
open_ai_key: env(default::OPEN_AI_KEY)
services:
Macopedia\Translator\Client\OpenAiClient:
arguments:
- '@logger'
- 'gpt-3.5-turbo'
- '%env(OPEN_AI_KEY)%'
- '%open_ai_key%'

Macopedia\Translator\Translator\OpenAiTranslator:
arguments:
Expand Down
48 changes: 48 additions & 0 deletions tests/Translator/LanguageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Translator;

use InvalidArgumentException;
use Macopedia\Translator\Translator\Language;
use PHPUnit\Framework\TestCase;

final class LanguageTest extends TestCase
{
/**
* @dataProvider dataProvider
* @param string $code
* @param bool $correct
*/
public function testCreateCorrectLanguage(string $code, bool $correct): void
{
if (!$correct) {
$this->expectException(InvalidArgumentException::class);
}

Language::fromCode($code);

if ($correct) {
$this->addToAssertionCount(1);
}
}

/**
* @return array<int, array<int, string|bool>>
*/
public static function dataProvider(): array
{
return [
['sg', true],
['sa', true],
['sc', true],
['sr', true],
['sn', true],
['SN', false],
['SR', false],
['gb', false],
['Pl', false],
['pln', false],
['pl_PL', false],
];
}
}
3 changes: 3 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

require dirname(__DIR__) . '/vendor/autoload.php';

0 comments on commit 45a6855

Please sign in to comment.