Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
Restriction.php
1
<?php
2
3
namespace
Bitrix\Im\V2\Integration\AI
;
4
5
use Bitrix\AI\Context;
6
use Bitrix\AI\Engine;
7
use
Bitrix\Main\Config\Option
;
8
use
Bitrix\Main\Loader
;
9
use
Bitrix\Main\Localization\Loc
;
10
11
class
Restriction
12
{
13
public
const
AI_TEXT_CATEGORY
=
'text'
;
14
public
const
AI_IMAGE_CATEGORY
=
'image'
;
15
public
const
AI_TEXTAREA
=
'textarea'
;
16
public
const
AI_COPILOT_CHAT
=
'copilot_chat'
;
17
18
private
const
CATEGORIES_BY_TYPE = [
19
self::AI_TEXTAREA =>
self::AI_TEXT_CATEGORY
,
20
self::AI_COPILOT_CHAT =>
self::AI_TEXT_CATEGORY
,
21
];
22
23
private
const
SETTING_COPILOT_CHAT =
'im_allow_chat_answer_generate'
;
24
private
const
SETTING_TEXTAREA_CHAT =
'im_allow_chat_textarea_generate'
;
25
private
const
SETTINGS_BY_TYPE = [
26
self::AI_COPILOT_CHAT => self::SETTING_COPILOT_CHAT,
27
self::AI_TEXTAREA => self::SETTING_TEXTAREA_CHAT,
28
];
29
30
public
const
AI_TEXT_ERROR
=
'AI_TEXT_NOT_AVAILABLE'
;
31
public
const
AI_IMAGE_ERROR
=
'AI_IMAGE_NOT_AVAILABLE'
;
32
33
private
string
$type;
34
35
public
function
__construct
(
string
$type)
36
{
37
$this->type = $type;
38
}
39
40
public
function
isAvailable
(): bool
41
{
42
if
(!Loader::includeModule(
'ai'
))
43
{
44
return
false
;
45
}
46
47
if
(!isset(self::CATEGORIES_BY_TYPE[$this->type]))
48
{
49
return
false
;
50
}
51
52
$category = self::CATEGORIES_BY_TYPE[$this->type];
53
$engine = Engine::getByCategory($category,
new
Context(
'im'
,
''
));
54
55
if
(is_null($engine))
56
{
57
return
false
;
58
}
59
60
$copilotSetting = (new \Bitrix\AI\Tuning\Manager())->getItem(self::SETTINGS_BY_TYPE[$this->type]);
61
if
(!isset($copilotSetting))
62
{
63
return
false
;
64
}
65
66
return
$copilotSetting->getValue();
67
}
68
69
public
static
function
onTuningLoad
(): \
Bitrix
\Main\
Entity
\
EventResult
70
{
71
$result = new \Bitrix\Main\Entity\EventResult;
72
$items = [];
73
$groups = [];
74
75
if
(\
Bitrix
\AI\Engine::getByCategory(self::CATEGORIES_BY_TYPE[self::AI_COPILOT_CHAT], \
Bitrix
\AI\Context::getFake()))
76
{
77
$groups[
'im_copilot_chat'
] = [
78
'title'
=>
Loc::getMessage
(
'IM_RESTRICTION_COPILOT_TITLE'
),
79
'description'
=>
Loc::getMessage
(
'IM_RESTRICTION_COPILOT_DESCRIPTION'
),
80
'helpdesk'
=>
'18505482'
,
81
];
82
83
$items[self::SETTING_COPILOT_CHAT] = [
84
'group'
=>
'im_copilot_chat'
,
85
'title'
=>
Loc::getMessage
(
'IM_RESTRICTION_COPILOT_TITLE'
),
86
'header'
=>
Loc::getMessage
(
'IM_RESTRICTION_COPILOT_HEADER'
),
87
'type'
=> \Bitrix\AI\Tuning\Type::BOOLEAN,
88
'default'
=>
true
,
89
];
90
}
91
92
$result->modifyFields([
93
'items'
=> $items,
94
'groups'
=> $groups,
95
]);
96
97
return
$result;
98
}
99
}
Bitrix\Im\V2\Integration\AI\Restriction
Definition
Restriction.php:12
Bitrix\Im\V2\Integration\AI\Restriction\AI_IMAGE_CATEGORY
const AI_IMAGE_CATEGORY
Definition
Restriction.php:14
Bitrix\Im\V2\Integration\AI\Restriction\AI_TEXTAREA
const AI_TEXTAREA
Definition
Restriction.php:15
Bitrix\Im\V2\Integration\AI\Restriction\AI_TEXT_CATEGORY
const AI_TEXT_CATEGORY
Definition
Restriction.php:13
Bitrix\Im\V2\Integration\AI\Restriction\AI_TEXT_ERROR
const AI_TEXT_ERROR
Definition
Restriction.php:30
Bitrix\Im\V2\Integration\AI\Restriction\AI_COPILOT_CHAT
const AI_COPILOT_CHAT
Definition
Restriction.php:16
Bitrix\Im\V2\Integration\AI\Restriction\AI_IMAGE_ERROR
const AI_IMAGE_ERROR
Definition
Restriction.php:31
Bitrix\Im\V2\Integration\AI\Restriction\onTuningLoad
static onTuningLoad()
Definition
Restriction.php:69
Bitrix\Im\V2\Integration\AI\Restriction\isAvailable
isAvailable()
Definition
Restriction.php:40
Bitrix\Im\V2\Integration\AI\Restriction\__construct
__construct(string $type)
Definition
Restriction.php:35
Bitrix\Main\Config\Option
Definition
option.php:15
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\Im\V2\Entity
Definition
Entity.php:6
Bitrix\Im\V2\Integration\AI
Definition
AIHelper.php:3
Bitrix
modules
im
lib
V2
Integration
AI
Restriction.php
Создано системой
1.10.0