Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
ai.php
1
<?php
2
namespace
Bitrix\Landing\Connector
;
3
4
use Bitrix\AI\Context;
5
use Bitrix\AI\Engine;
6
use Bitrix\AI\Engine\IEngine;
7
use Bitrix\AI\Tuning;
8
use Bitrix\AI\Tuning\Type;
9
use
Bitrix\Main\Event
;
10
use
Bitrix\Main\Entity
;
11
use
Bitrix\Main\EventResult
;
12
use
Bitrix\Main\Loader
;
13
use
Bitrix\Main\Localization\Loc
;
14
15
class
Ai
16
{
17
private
const
TUNING_CODE_IMAGE =
'landing_allow_image_generate'
;
18
private
const
TUNING_CODE_TEXT =
'landing_allow_text_generate'
;
19
24
public
static
function
isImageAvailable
(): bool
25
{
26
if
(!Loader::includeModule(
'ai'
))
27
{
28
return
false
;
29
}
30
31
$engine = Engine::getByCategory(
'image'
, Context::getFake());
32
if
(!$engine)
33
{
34
return
false
;
35
}
36
37
return
true
;
38
}
39
44
public
static
function
isImageActive
(): bool
45
{
46
if
(!self::isImageAvailable())
47
{
48
return
false
;
49
}
50
51
$default =
false
;
52
$setting = (
new
Tuning\Manager())->getItem(self::TUNING_CODE_IMAGE);
53
54
return
$setting ? (bool)$setting->getValue() : $default;
55
}
56
61
public
static
function
isTextAvailable
(): bool
62
{
63
if
(!Loader::includeModule(
'ai'
))
64
{
65
return
false
;
66
}
67
68
$engine = Engine::getByCategory(
'text'
, Context::getFake());
69
if
(!$engine)
70
{
71
return
false
;
72
}
73
74
return
true
;
75
}
76
81
public
static
function
isCopilotAvailable
(): bool
82
{
83
if
(!self::isTextAvailable())
84
{
85
return
false
;
86
}
87
88
if
(\
Bitrix
\Main\
Config
\Option::get(
'landing'
,
'enable_copilot'
,
'N'
) ===
'Y'
)
89
{
90
return
true
;
91
}
92
93
return
false
;
94
}
95
100
public
static
function
isTextActive
(): bool
101
{
102
if
(!self::isTextAvailable())
103
{
104
return
false
;
105
}
106
107
$default =
false
;
108
$setting = (
new
Tuning\Manager())->getItem(self::TUNING_CODE_TEXT);
109
110
return
$setting ? (bool)$setting->getValue() : $default;
111
}
112
117
public
static
function
onTuningLoad
():
Entity
\
EventResult
118
{
119
$result =
new
Entity\EventResult;
120
$items = [];
121
$groups = [];
122
123
if
(Engine::getByCategory(
'image'
, Context::getFake()))
124
{
125
$items[self::TUNING_CODE_IMAGE] = [
126
'group'
=> Tuning\Defaults::GROUP_IMAGE,
127
'header'
=>
Loc::getMessage
(
'LANDING_CONNECTOR_AI_ALLOW_IMAGE_COPILOT_DESC'
),
128
'title'
=>
Loc::getMessage
(
'LANDING_CONNECTOR_AI_ALLOW_COPILOT_TITLE'
),
129
'type'
=> Type::BOOLEAN,
130
'default'
=>
true
,
131
'sort'
=> 300,
132
];
133
}
134
135
if
(Engine::getByCategory(
'text'
, Context::getFake()))
136
{
137
$items[self::TUNING_CODE_TEXT] = [
138
'group'
=> Tuning\Defaults::GROUP_TEXT,
139
'header'
=>
Loc::getMessage
(
'LANDING_CONNECTOR_AI_ALLOW_TEXT_COPILOT_DESC'
),
140
'title'
=>
Loc::getMessage
(
'LANDING_CONNECTOR_AI_ALLOW_COPILOT_TITLE'
),
141
'type'
=> Type::BOOLEAN,
142
'default'
=>
true
,
143
'sort'
=> 300,
144
];
145
}
146
147
$result->modifyFields([
148
'items'
=> $items,
149
'groups'
=> $groups,
150
]);
151
152
return
$result;
153
}
154
161
public
static
function
onBeforeCompletions(
Event
$event):
EventResult
162
{
164
$engine = $event->
getParameter
(
'engine'
);
165
$category = $engine->getCategory();
166
$module = $engine->getContext()->getModuleId();
167
168
$config =
new
Tuning\Manager();
169
$configItem = $config->getItem(
"{$module}_allow_{$category}_generate"
);
170
171
if
($configItem && $configItem->getValue())
172
{
173
return
new
EventResult
(EventResult::SUCCESS);
174
}
175
else
176
{
177
return
new
EventResult
(EventResult::ERROR);
178
}
179
}
180
}
Bitrix\Landing\Binding\Entity
Definition
entity.php:11
Bitrix\Landing\Connector\Ai
Definition
ai.php:16
Bitrix\Landing\Connector\Ai\isTextActive
static isTextActive()
Definition
ai.php:100
Bitrix\Landing\Connector\Ai\isTextAvailable
static isTextAvailable()
Definition
ai.php:61
Bitrix\Landing\Connector\Ai\isImageAvailable
static isImageAvailable()
Definition
ai.php:24
Bitrix\Landing\Connector\Ai\isImageActive
static isImageActive()
Definition
ai.php:44
Bitrix\Landing\Connector\Ai\onTuningLoad
static onTuningLoad()
Definition
ai.php:117
Bitrix\Landing\Connector\Ai\isCopilotAvailable
static isCopilotAvailable()
Definition
ai.php:81
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\Event\getParameter
getParameter($key)
Definition
event.php:80
Bitrix\Main\EventResult
Definition
eventresult.php:5
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Landing\Connector
Definition
ai.php:2
Bitrix\Main\Config
Definition
configuration.php:2
Bitrix
modules
landing
lib
connector
ai.php
Создано системой
1.10.0