diff --git a/README.md b/README.md index 72a760f..aed0356 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/composer.json b/composer.json index 78d4a7c..531d514 100755 --- a/composer.json +++ b/composer.json @@ -43,6 +43,9 @@ "@cs:fix", "@phpstan", "@phpunit" + ], + "post-install-cmd": [ + "make upgrade-front" ] }, diff --git a/src/Macopedia/Translator/Client/OpenAiClient.php b/src/Macopedia/Translator/Client/OpenAiClient.php index c484c98..5ed3fb8 100644 --- a/src/Macopedia/Translator/Client/OpenAiClient.php +++ b/src/Macopedia/Translator/Client/OpenAiClient.php @@ -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(); @@ -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 [ diff --git a/src/Macopedia/Translator/MacopediaTranslatorBundle.php b/src/Macopedia/Translator/MacopediaTranslatorBundle.php index 1d18501..716ee02 100644 --- a/src/Macopedia/Translator/MacopediaTranslatorBundle.php +++ b/src/Macopedia/Translator/MacopediaTranslatorBundle.php @@ -8,4 +8,8 @@ final class MacopediaTranslatorBundle extends Bundle { + public function getParent() + { + return null; + } } diff --git a/src/Macopedia/Translator/Resources/config/services.yml b/src/Macopedia/Translator/Resources/config/services.yml index c9c9c3f..2b8a65f 100644 --- a/src/Macopedia/Translator/Resources/config/services.yml +++ b/src/Macopedia/Translator/Resources/config/services.yml @@ -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: diff --git a/tests/Translator/LanguageTest.php b/tests/Translator/LanguageTest.php new file mode 100644 index 0000000..49ed4ca --- /dev/null +++ b/tests/Translator/LanguageTest.php @@ -0,0 +1,48 @@ +expectException(InvalidArgumentException::class); + } + + Language::fromCode($code); + + if ($correct) { + $this->addToAssertionCount(1); + } + } + + /** + * @return array> + */ + 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], + ]; + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..637c614 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,3 @@ +