1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Restriction.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Integration\AI;
4
5use Bitrix\AI\Engine;
6use Bitrix\AI\Tuning\Defaults;
7use Bitrix\AI\Tuning\Manager;
8use Bitrix\AI\Tuning\Type;
9use Bitrix\Imbot\Bot\CopilotChatBot;
10use Bitrix\Main\Application;
11use Bitrix\Main\Entity\EventResult;
12use Bitrix\Main\Loader;
13use Bitrix\Main\Localization\Loc;
14
16{
17 public const SETTING_COPILOT_CHAT_PROVIDER = 'im_chat_answer_provider';
18
19 private const AI_TEXT_CATEGORY = 'text';
20 private const DEFAULT_COPILOT_ENABLED = true;
21 private const SETTING_COPILOT_CHAT = 'im_allow_chat_answer_generate';
22 private const PORTAL_ZONE_BLACKLIST = ['cn'];
23
24 private static ?bool $isActive = null;
25 private static ?bool $isAvailable = null;
26
27 public function isActive(): bool
28 {
29 self::$isActive ??= $this->isActiveInternal();
30
31 return self::$isActive;
32 }
33
34 public function isAvailable(): bool
35 {
36 self::$isAvailable ??= $this->isAvailableInternal();
37
38 return self::$isAvailable;
39 }
40
41 public static function onTuningLoad(): EventResult
42 {
43 $result = new EventResult;
44 $items = [];
45 $groups = [];
46
47 if (!empty(Engine::getListAvailable(self::AI_TEXT_CATEGORY)))
48 {
49 $groups['im_copilot_chat'] = [
50 'title' => Loc::getMessage('IM_RESTRICTION_COPILOT_GROUP_MSGVER_1'),
51 'description' => Loc::getMessage('IM_RESTRICTION_COPILOT_DESCRIPTION'),
52 'helpdesk' => '18505482',
53 ];
54
55 $items[self::SETTING_COPILOT_CHAT] = [
56 'group' => 'im_copilot_chat',
57 'title' => Loc::getMessage('IM_RESTRICTION_COPILOT_TITLE'),
58 'header' => Loc::getMessage('IM_RESTRICTION_COPILOT_HEADER'),
59 'type' => Type::BOOLEAN,
60 'default' => self::DEFAULT_COPILOT_ENABLED,
61 ];
62
63 $items[self::SETTING_COPILOT_CHAT_PROVIDER] = array_merge(
64 [
65 'group' => 'im_copilot_chat',
66 'title' => Loc::getMessage('IM_RESTRICTION_COPILOT_PROVIDER_TITLE'),
67 ],
68 Defaults::getProviderSelectFieldParams(self::AI_TEXT_CATEGORY)
69 );
70 }
71
72 $result->modifyFields([
73 'items' => $items,
74 'groups' => $groups,
75 'itemRelations' => [
76 'im_copilot_chat' => [
77 self::SETTING_COPILOT_CHAT => [
78 self::SETTING_COPILOT_CHAT_PROVIDER,
79 ],
80 ],
81 ],
82 ]);
83
84 return $result;
85 }
86
87 private function isActiveInternal(): bool
88 {
89 if (
90 !Loader::includeModule('ai')
92 || !$this->isAvailable()
93 )
94 {
95 return false;
96 }
97
98 $engine = Engine::getListAvailable(self::AI_TEXT_CATEGORY);
99 if (empty($engine))
100 {
101 return false;
102 }
103
104 return $this->isCopilotOptionEnabled();
105 }
106
107 private function isCopilotOptionEnabled(): bool
108 {
109 $settings = Manager::getTuningStorage();
110
111 return (bool)($settings[self::SETTING_COPILOT_CHAT] ?? self::DEFAULT_COPILOT_ENABLED);
112 }
113
114 private function isAvailableInternal(): bool
115 {
116 // todo: need to support changes
117 $portalZone = Application::getInstance()->getLicense()->getRegion() ?? 'ru';
118
119 return !in_array($portalZone, self::PORTAL_ZONE_BLACKLIST, true);
120 }
121}
static getCopilotBotId()
Определения AIHelper.php:16
const SETTING_COPILOT_CHAT_PROVIDER
Определения Restriction.php:17
static getInstance()
Определения servicelocator.php:33
$result
Определения get_property_values.php:14
$portalZone
Определения .description.php:14
$groups
Определения options.php:30
$settings
Определения product_settings.php:43
$items
Определения template.php:224
$engine
Определения options.php:121