2declare(strict_types=1);
4namespace Bitrix\Landing\Copilot\Generation\Step;
6use Bitrix\Landing\Copilot\Connector\AI;
7use Bitrix\Landing\Copilot\Connector\AI\Prompt;
8use Bitrix\Landing\Copilot\Converter;
9use Bitrix\Landing\Copilot\Data\Block\Operator;
10use Bitrix\Landing\Copilot\Data\Type\NodeType;
11use Bitrix\Landing\Copilot\Generation\Error;
12use Bitrix\Landing\Copilot\Generation\GenerationException;
13use Bitrix\Landing\Copilot\Generation\Markers;
14use Bitrix\Landing\Copilot\Generation\Type\Errors;
15use Bitrix\Landing\Copilot\Generation\Type\GenerationErrors;
16use Bitrix\Landing\Copilot\Generation\Type\RequestQuotaDto;
17use Bitrix\Landing\Copilot\Data\Site;
19use Bitrix\Landing\Rights;
25 parent::__construct();
26 if (class_exists(self::getConnectorClass()))
37 return AI\Text::class;
50 $prompt =
new Prompt(
'landing_ai_block_content');
58 $result = $this->request->getResult();
79 $result = $this->request->getResult();
87 !isset(
$result[
'isAllowedRequest'])
88 ||
$result[
'isAllowedRequest'] !==
"yes"
113 foreach (
$result[
'blocks'] as &$block)
115 if (!isset($block[
'nodes']))
120 foreach ($block[
'nodes'] as &$node)
124 $node = array_filter($node,
static function($value) {
125 return $value !==
'';
135 $block[
'nodes'] = array_filter($block[
'nodes'],
static function($node) {
136 return !empty($node);
154 Landing\Landing::setEditMode();
155 $landingInstance = Landing\Landing::createInstance(
$siteData->getLandingId());
156 foreach (
$siteData->getBlocks() as $blockData)
158 $blockId = $blockData->getId();
159 $blockInstance = $landingInstance->getBlockById($blockId);
162 $blockContent = $blockInstance->getContent();
165 foreach ($blockData->getNodes() as $nodeData)
167 if ($nodeData->getType() !== NodeType::Img)
172 $promptTexts = $nodeData->getPromptTexts();
173 if (isset($blockContent) && $promptTexts)
176 method_exists($nodeData,
'setSrc')
177 && method_exists($nodeData,
'setDefaultSrc')
180 $defaultSrcDataPrepared = [];
181 $nodeDataValues = $nodeData->getValues();
182 foreach ($nodeDataValues as $nodeDataValue)
184 $defaultSrcDataPrepared[] = [
185 'src' => $nodeDataValue[
'defaultSrc'],
186 'src2x' => $nodeDataValue[
'defaultSrc2x']
189 $nodeData->setSrc($defaultSrcDataPrepared);
static initSiteBlock(Site $siteData, array $json)
static saveImgNodesDataFromResponse(Site $siteData, array $result)
static createError(?Errors $code=null)
static getBlockContentPromptMarkers(Data\Site $siteData)
static getRequestQuota(Site $siteData)
prepareResult(array $result)
static setDefaultSrcForImgNodes(Site $siteData)
static getConnectorClass()
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)