1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
PromptGenerator.php
См. документацию.
1<?php
2declare(strict_types=1);
3
4namespace Bitrix\Landing\Copilot\Generation;
5
6use Bitrix\Landing\Copilot\Data\Node\Node;
7use Bitrix\Landing\Copilot\Data\Site;
8
10{
11 private PromptTemplateProvider $templateProvider;
12 private ?Node $node;
13 private ?string $template;
14 private string $style;
15 private string $color;
16 private string $siteTopic;
17
18 public function __construct(PromptTemplateProvider $templateProvider, Site $site, ?Node $node = null)
19 {
20 $this->templateProvider = $templateProvider;
21 $this->node = $node;
22 $this->style = $site->getImageStyle();
23 $this->color = $site->getColors()->themeName;
24 $this->siteTopic = $site->getSiteTopic();
25 }
26
34 public function getUpdatedPromptTexts(array $prompts): array
35 {
36 $this->initTemplate();
37
38 $updatedPrompts = [];
39 foreach ($prompts as $prompt)
40 {
41 $updatedPrompts[] = str_replace(
42 ['{#prompt}', '{#color}', '{#style}', '{#siteTopic}'],
43 [$prompt, $this->color, $this->style, $this->siteTopic],
44 $this->template
45 );
46 }
47
48 return $updatedPrompts;
49 }
50
57 public function getRandomReservePromptText(): string
58 {
59 $this->template = $this->templateProvider->getRandomReserveTemplate();
60 $this->prepareTemplate();
61
62 return str_replace(
63 ['{#color}', '{#style}', '{#siteTopic}'],
64 [$this->color, $this->style, $this->siteTopic],
65 $this->template,
66 );
67 }
68
72 protected function initTemplate(): void
73 {
74 if ($this->node === null)
75 {
76 $this->template = $this->templateProvider->getPreviewTemplate();
77 }
78 elseif (method_exists($this->node, 'isEditInStyle') && $this->node->isEditInStyle())
79 {
80 $this->template = $this->templateProvider->getBgTemplate();
81 }
82 else
83 {
84 $this->template = $this->templateProvider->getBaseTemplate();
85 }
86
87 $this->prepareTemplate();
88 }
89
90 private function prepareTemplate(): void
91 {
92 $placeholders = [
93 '#color' => $this->color,
94 '#style' => $this->style,
95 '#siteTopic' => $this->siteTopic,
96 ];
97
98 foreach ($placeholders as $key => $value)
99 {
100 if ($value === '')
101 {
102 $pattern = sprintf('/\[[^]]*{%s}[^]]*]/', $key);
103 $this->template = preg_replace($pattern, '', $this->template);
104 }
105 }
106
107 $this->template = str_replace(['[', ']'], '', $this->template);
108 }
109}
__construct(PromptTemplateProvider $templateProvider, Site $site, ?Node $node=null)
Определения PromptGenerator.php:18
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
background color
Определения file_new.php:745
Определения cookies.php:2
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
font style
Определения invoice.php:442
if(!Loader::includeModule('sale')) $pattern
Определения index.php:20
$site
Определения yandex_run.php:614