1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
PromptGenerator.php
См. документацию.
1
<?php
2
declare(strict_types=1);
3
4
namespace
Bitrix\Landing\Copilot\Generation;
5
6
use Bitrix\Landing\Copilot\Data\Node\Node;
7
use Bitrix\Landing\Copilot\Data\Site;
8
9
class
PromptGenerator
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
}
Bitrix\Landing\Copilot\Generation\PromptGenerator
Определения
PromptGenerator.php:10
Bitrix\Landing\Copilot\Generation\PromptGenerator\getUpdatedPromptTexts
getUpdatedPromptTexts(array $prompts)
Определения
PromptGenerator.php:34
Bitrix\Landing\Copilot\Generation\PromptGenerator\initTemplate
initTemplate()
Определения
PromptGenerator.php:72
Bitrix\Landing\Copilot\Generation\PromptGenerator\getRandomReservePromptText
getRandomReservePromptText()
Определения
PromptGenerator.php:57
Bitrix\Landing\Copilot\Generation\PromptGenerator\__construct
__construct(PromptTemplateProvider $templateProvider, Site $site, ?Node $node=null)
Определения
PromptGenerator.php:18
Bitrix\Landing\Copilot\Generation\PromptTemplateProvider
Определения
PromptTemplateProvider.php:7
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
color
background color
Определения
file_new.php:745
Bitrix\Landing\Copilot\Data\Node
Определения
Icon.php:4
Bitrix\Landing\Site
Определения
cookies.php:2
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$key
if(empty($signedUserToken)) $key
Определения
quickway.php:257
style
font style
Определения
invoice.php:442
$pattern
if(!Loader::includeModule('sale')) $pattern
Определения
index.php:20
$site
$site
Определения
yandex_run.php:614
bitrix
modules
landing
lib
Copilot
Generation
PromptGenerator.php
Создано системой
1.14.0