Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Restriction.php
1<?php
2
4
5use Bitrix\AI\Context;
6use Bitrix\AI\Engine;
10
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}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29