diff --git a/CHANGELOG.md b/CHANGELOG.md
index a6e2d34..b55bd2d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
### Added
+- Added new option to define the approximate length of product descriptions.
- Add new plugin configuration hint for OpenAI key that it starts with **sk_**. (thx @jissereitsma)
- Added better error output for OpenAI requests. Sometimes the message is empty, but the error code can still be displayed. (thx @jissereitsma)
diff --git a/src/Command/ProductGenerateCommand.php b/src/Command/ProductGenerateCommand.php
index 2e53ea1..2293a9a 100644
--- a/src/Command/ProductGenerateCommand.php
+++ b/src/Command/ProductGenerateCommand.php
@@ -85,6 +85,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$withImages = $input->getOption('images');
$imgSize = $input->getOption('images-size');
+ $descriptionLength = $this->configService->getProductDescriptionLength();
+
if ($keyWords === null) {
throw new \Exception('No AI keywords given. Please specify what you want to be generated by providing the --keywords option.');
}
@@ -123,6 +125,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->io->note('Images will not be generated for the products.');
}
+
+ $this->io->note('Product description length: ' . $descriptionLength . ' characters');
+
+
# -----------------------------------------------------------------------------------------------------------------------
# configure our generator
@@ -136,7 +142,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->productGenerator->generate(
$keyWords,
$count,
- $category
+ $category,
+ $descriptionLength
);
if ($this->errorCount <= 0) {
diff --git a/src/Resources/config/config.xml b/src/Resources/config/config.xml
index 91da777..cc82a0f 100644
--- a/src/Resources/config/config.xml
+++ b/src/Resources/config/config.xml
@@ -23,6 +23,13 @@
If enabled product images will be automatically generated if no CLI argument is provided.
+
+ productDescriptionLength
+
+ 400
+ The approximate target length of a product description text.
+
+
productImageSize
diff --git a/src/Service/Config/ConfigService.php b/src/Service/Config/ConfigService.php
index 39afd11..94083b4 100644
--- a/src/Service/Config/ConfigService.php
+++ b/src/Service/Config/ConfigService.php
@@ -27,6 +27,11 @@ class ConfigService
*/
private $mediaImageSize;
+ /**
+ * @var int
+ */
+ private $productDescriptionLength;
+
/**
* @param SystemConfigService $configService
@@ -39,6 +44,8 @@ public function __construct(SystemConfigService $configService)
$this->productImageSize = $configService->getString('AIDemoData.config.productImageSize');
$this->mediaImageSize = $configService->getString('AIDemoData.config.mediaImageSize');
+
+ $this->productDescriptionLength = $configService->getInt('AIDemoData.config.productDescriptionLength');
}
/**
@@ -69,6 +76,18 @@ public function getProductImageSize(): string
return $this->productImageSize;
}
+ /**
+ * @return int
+ */
+ public function getProductDescriptionLength(): int
+ {
+ if (empty($this->productDescriptionLength)) {
+ return 400;
+ }
+
+ return (int)$this->productDescriptionLength;
+ }
+
/**
* @return string
*/
diff --git a/src/Service/Generator/ProductGenerator.php b/src/Service/Generator/ProductGenerator.php
index 485d995..af779e0 100644
--- a/src/Service/Generator/ProductGenerator.php
+++ b/src/Service/Generator/ProductGenerator.php
@@ -114,10 +114,11 @@ public function setGenerateImages(bool $generateImages, string $imageSize): void
* @param string $keywords
* @param int $maxCount
* @param string $category
- * @throws \Exception
+ * @param int $descriptionLength
+ * @throws \JsonException
* @return void
*/
- public function generate(string $keywords, int $maxCount, string $category)
+ public function generate(string $keywords, int $maxCount, string $category, int $descriptionLength)
{
$prompt = 'Create a list of demo products with these properties, separated values with ";". Only write down values and no property names ' . PHP_EOL;
$prompt .= PHP_EOL;
@@ -127,7 +128,7 @@ public function generate(string $keywords, int $maxCount, string $category)
$prompt .= 'product count.' . PHP_EOL;
$prompt .= 'product number code. should be 16 unique random alphanumeric.' . PHP_EOL;
$prompt .= 'name of the product.' . PHP_EOL;
- $prompt .= 'description (about 400 characters).' . PHP_EOL;
+ $prompt .= 'description (about ' . $descriptionLength . ' characters).' . PHP_EOL;
$prompt .= 'price value (no currency just number).' . PHP_EOL;
$prompt .= 'EAN code.' . PHP_EOL;
$prompt .= 'SEO description (max 100 characters).' . PHP_EOL;