3namespace Bitrix\Im\V2\Integration\AI;
5use Bitrix\Im\V2\Analytics\CopilotAnalytics;
7use Bitrix\Im\V2\Chat\Param\Params;
8use Bitrix\Im\V2\Common\ContextCustomer;
9use Bitrix\Im\V2\Result;
10use Bitrix\Main\Loader;
21 protected ?\Bitrix\AI\Role\RoleManager
$aiManager =
null;
25 if (!Loader::includeModule(
'ai'))
30 return \Bitrix\AI\Role\RoleManager::getUniversalRoleCode();
35 if (!Loader::includeModule(
'imbot') || !Loader::includeModule(
'ai'))
41 $roleCodes = array_unique($roleCodes);
44 foreach ($this->
getAiManager()->getRolesAvatarsFromCache($roleCodes) as $roleCode => $avatar)
52 return !empty($roleData) ? $roleData :
null;
57 if (!Loader::includeModule(
'imbot') || !Loader::includeModule(
'ai'))
63 $roleCodes = array_unique($roleCodes);
72 foreach ($roleCodes as
$code)
74 $role = self::$roles[
$code] ??
null;
79 $role[
'prompts'] = self::$prompts[
$code] ?? [];
81 $roleData[
$code] = $role;
85 return !empty($roleData) ? $roleData :
null;
92 $codesWithoutCache = array_diff($roleCodes, array_keys(self::$roles));
93 if (empty($codesWithoutCache))
98 foreach ($roleManager->getRolesByCode($codesWithoutCache) as $role)
107 $rolesWithoutPrompts = array_diff($roleCodes, array_keys(self::$prompts));
109 if (empty($rolesWithoutPrompts))
114 $prompts = $roleManager->getPromptsByCategoryAndRoleCodes(self::PROMPT_CATEGORY, $rolesWithoutPrompts);
115 foreach ($rolesWithoutPrompts as
$code)
117 self::$prompts[
$code] =
129 'code' => $role[
'code'],
130 'name' => $role[
'name'],
131 'desc' => $role[
'description'],
132 'avatar' => $role[
'avatar'],
141 'code' => $role[
'code'],
142 'avatar' => $role[
'avatar'],
149 if (!isset($chatId) || !Loader::includeModule(
'ai'))
154 $params = Params::getInstance($chatId);
156 if (
$params->get(Params::COPILOT_MAIN_ROLE) ===
null)
161 return (
string)
$params->get(Params::COPILOT_MAIN_ROLE)->getValue();
168 if (!Loader::includeModule(
'ai'))
175 if (!isset($roleCode))
180 $roleData = $this->
getRoles([$roleCode]);
181 if (empty($roleData))
188 $params = Params::getInstance($chat->getChatId());
190 $params->get(Params::COPILOT_MAIN_ROLE) !==
null
191 &&
$params->get(Params::COPILOT_MAIN_ROLE)->getValue() === $roleCode
200 $params->addParamByName(Params::COPILOT_MAIN_ROLE, $roleCode);
203 if (!isset($roleData[$roleCode]))
211 $chat->sendBanner(
null, $roleData[$roleCode][
'name'],
true);
219 if (!\
Bitrix\
Main\Loader::includeModule(
'pull'))
226 'command' =>
'chatCopilotRoleUpdate',
228 'chatId' => $chat->getChatId(),
229 'dialogId' =>
'chat' . $chat->getChatId(),
231 'chats' => [[
'dialogId' => $chat->getDialogId(),
'role' => $this->
getMainRole($chat->getChatId())]],
232 'roles' => [$roleData[
'code'] => $roleData],
250 $roleCodes[] = $role[
'code'];
258 if (!Loader::includeModule(
'ai'))
264 $roles = $roleManager->getRecommendedRoles(4);
265 array_unshift(
$roles, $roleManager->getUniversalRole());
272 $this->aiManager ??= new \Bitrix\AI\Role\RoleManager($this->getContext()->getUserId(), LANGUAGE_ID);
formatRoleData(array $role)
Bitrix AI Role RoleManager $aiManager
updateRole(Chat $chat, ?string $roleCode)
fillPrompts(array $roleCodes)
formatRoleDataShort(array $role)
sendPushCopilotRole(Chat $chat, array $roleData)
getRoles(array $roleCodes, bool $withPrompts=true)
getRolesShort(array $roleCodes)
static getDefaultRoleCode()
getMainRole(?int $chatId)
fillRoles(array $roleCodes)
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']