Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
settings.php
1<?php
2
4
5use Bitrix\AI\Context;
6use Bitrix\AI\Engine;
9use Bitrix\AI\Tuning;
11
12final class Settings
13{
14 private const TEXT_CATEGORY = 'text';
15 private const IMAGE_CATEGORY = 'image';
16 private const TUNING_CODE_IMAGE = 'calendar_allow_image_generate';
17 private const TUNING_CODE_TEXT = 'calendar_allow_text_generate';
18 private const TUNING_CODE_IMAGE_COMMENT = 'calendar_comment_allow_image_generate';
19 private const TUNING_CODE_TEXT_COMMENT = 'calendar_comment_allow_text_generate';
20
21 public static function isTextAvailable(): bool
22 {
23 if (!self::checkEngineAvailable(self::TEXT_CATEGORY))
24 {
25 return false;
26 }
27
28 $item = (new Tuning\Manager())->getItem(self::TUNING_CODE_TEXT);
29
30 return $item ? $item->getValue() : true;
31 }
32
33 public static function isTextCommentAvailable(): bool
34 {
35 if (!self::checkEngineAvailable(self::TEXT_CATEGORY))
36 {
37 return false;
38 }
39
40 $item = (new Tuning\Manager())->getItem(self::TUNING_CODE_TEXT_COMMENT);
41
42 return $item ? $item->getValue() : true;
43 }
44
45 public static function isImageAvailable(): bool
46 {
47 if (!self::checkEngineAvailable(self::IMAGE_CATEGORY))
48 {
49 return false;
50 }
51
52 $item = (new Tuning\Manager())->getItem(self::TUNING_CODE_IMAGE);
53
54 return $item ? $item->getValue() : true;
55 }
56
57 public static function isImageCommentAvailable(): bool
58 {
59 if (!self::checkEngineAvailable(self::IMAGE_CATEGORY))
60 {
61 return false;
62 }
63
64 $item = (new Tuning\Manager())->getItem(self::TUNING_CODE_IMAGE_COMMENT);
65
66 return $item ? $item->getValue() : true;
67 }
68
69 private static function checkEngineAvailable(string $type): bool
70 {
71 if (!Loader::includeModule('ai'))
72 {
73 return false;
74 }
75
76 $engine = Engine::getByCategory($type, Context::getFake());
77 if (!$engine)
78 {
79 return false;
80 }
81
82 return true;
83 }
84
85 public static function onTuningLoad(): Entity\EventResult
86 {
87 $result = new Entity\EventResult();
88
89 $items = [];
90 $groups = [];
91
92 if (Engine::getByCategory(self::TEXT_CATEGORY, Context::getFake()))
93 {
94 $items[self::TUNING_CODE_TEXT] = [
95 'group' => Tuning\Defaults::GROUP_TEXT,
96 'header' => Loc::getMessage('CALENDAR_AI_SETTINGS_ALLOW_TEXT_COPILOT_DESC'),
97 'title' => Loc::getMessage('CALENDAR_AI_SETTINGS_COPILOT_TITLE'),
98 'type' => Tuning\Type::BOOLEAN,
99 'default' => true,
100 'sort' => 500,
101 ];
102
103 $items[self::TUNING_CODE_TEXT_COMMENT] = [
104 'group' => Tuning\Defaults::GROUP_TEXT,
105 'header' => Loc::getMessage('CALENDAR_AI_SETTINGS_ALLOW_TEXT_COMMENT_COPILOT_DESC'),
106 'title' => Loc::getMessage('CALENDAR_AI_SETTINGS_COPILOT_COMMENT_TITLE'),
107 'type' => Tuning\Type::BOOLEAN,
108 'default' => true,
109 'sort' => 510,
110 ];
111 }
112
113 if (Engine::getByCategory(self::IMAGE_CATEGORY, Context::getFake()))
114 {
115 $items[self::TUNING_CODE_IMAGE] = [
116 'group' => Tuning\Defaults::GROUP_IMAGE,
117 'header' => Loc::getMessage('CALENDAR_AI_SETTINGS_ALLOW_IMAGE_COPILOT_DESC'),
118 'title' => Loc::getMessage('CALENDAR_AI_SETTINGS_COPILOT_TITLE'),
119 'type' => Tuning\Type::BOOLEAN,
120 'default' => true,
121 'sort' => 500,
122 ];
123
124 $items[self::TUNING_CODE_IMAGE_COMMENT] = [
125 'group' => Tuning\Defaults::GROUP_IMAGE,
126 'header' => Loc::getMessage('CALENDAR_AI_SETTINGS_ALLOW_IMAGE_COMMENT_COPILOT_DESC'),
127 'title' => Loc::getMessage('CALENDAR_AI_SETTINGS_COPILOT_COMMENT_TITLE'),
128 'type' => Tuning\Type::BOOLEAN,
129 'default' => true,
130 'sort' => 510,
131 ];
132 }
133
134 $result->modifyFields([
135 'items' => $items,
136 'groups' => $groups,
137 ]);
138
139 return $result;
140 }
141}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29