Skip to content

Commit 7198c2d

Browse files
authored
Merge pull request #11 from LS-Myron/main
Updated code, updated class Request and added RequestInterface
2 parents b0c7814 + 761c05a commit 7198c2d

File tree

8 files changed

+32
-13
lines changed

8 files changed

+32
-13
lines changed

Api/RequestInterface.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace MageOS\CatalogDataAI\Api;
5+
6+
interface RequestInterface
7+
{
8+
/**
9+
* Retrieve products id.
10+
* @return int
11+
*/
12+
public function getId(): int;
13+
14+
/**
15+
* Retrieve overwrite flag.
16+
* @return bool
17+
*/
18+
public function getOverwrite(): bool;
19+
}

Controller/Adminhtml/Product/MassEnrich.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Magento\Backend\Model\View\Result\Redirect;
88
use Magento\Catalog\Api\ProductRepositoryInterface;
99
use Magento\Backend\App\Action;
10+
use Magento\Catalog\Model\Product;
1011
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
1112
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
1213
use Magento\Framework\Controller\ResultFactory;
@@ -41,7 +42,7 @@ public function execute(): Redirect
4142

4243
$productEnriched = 0;
4344
if($this->config->isEnabled()) {
44-
/** @var \Magento\Catalog\Model\Product $product */
45+
/** @var Product $product */
4546
foreach ($collection->getItems() as $product) {
4647
//@TODO: we hit rate limit, change to batching the request
4748
$this->publisher->execute($product->getId(), $this->overwrite);

Model/Config.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
22
declare(strict_types=1);
3+
34
namespace MageOS\CatalogDataAI\Model;
45

56
use Magento\Framework\App\Config\ScopeConfigInterface;
6-
USE Magento\Catalog\Model\Product;
7+
use Magento\Catalog\Model\Product;
78

89
class Config
910
{
@@ -19,8 +20,7 @@ class Config
1920

2021
public function __construct(
2122
private readonly ScopeConfigInterface $scopeConfig
22-
) {
23-
}
23+
) {}
2424

2525
public function isEnabled(): bool
2626
{

Model/Product/Enricher.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
class Enricher
1414
{
1515
private Client $client;
16-
public function __construct
17-
(
16+
public function __construct(
1817
private readonly Factory $clientFactory,
1918
private readonly Config $config
2019
) {

Model/Product/Publisher.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ class Publisher
1616
public function __construct(
1717
private readonly PublisherInterface $publisher,
1818
private readonly RequestFactory $requestFactory,
19-
) {
20-
}
19+
) {}
2120

2221
/**
2322
* @param int|string $productId

Model/Product/Request.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
namespace MageOS\CatalogDataAI\Model\Product;
55

6+
use MageOS\CatalogDataAI\Api\RequestInterface;
7+
68
/**
79
* Data model for enrichment message queue.
810
*/
9-
class Request
11+
class Request implements RequestInterface
1012
{
1113
public function __construct(
1214
private readonly int $id,
@@ -15,15 +17,15 @@ public function __construct(
1517
}
1618

1719
/**
18-
* Retrieve products id.
20+
* @inheritDoc
1921
*/
2022
public function getId(): int
2123
{
2224
return $this->id;
2325
}
2426

2527
/**
26-
* Retrieve overwrite flag.
28+
* @inheritDoc
2729
*/
2830
public function getOverwrite(): bool
2931
{

Observer/Product/SaveBefore.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ public function execute(Observer $observer): void
2424
if($this->config->canEnrich($product) && !$this->config->isAsync()) {
2525
$this->enricher->execute($product);
2626
}
27-
2827
}
2928
}

etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<description>write a detailed product description for {{name}} with features in bullet list, under 1000 words</description>
1212
</product>
1313
<advanced>
14-
<system_prompt>You are a helpful assistant.</system_prompt>
14+
<system_prompt>Be a content generator, just reply with the content, skip all introductions.</system_prompt>
1515
<temperature>0</temperature>
1616
<frequency_penalty>0</frequency_penalty>
1717
<presence_penalty>0</presence_penalty>

0 commit comments

Comments
 (0)