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