3namespace Bitrix\Im\V2\Integration\AI;
8use Bitrix\AI\Tuning\Manager;
9use Bitrix\Im\V2\Analytics\CopilotAnalytics;
11use Bitrix\Im\V2\Pull\Event\ChangeEngine;
12use Bitrix\Im\V2\Result;
13use Bitrix\Main\Loader;
14use Bitrix\Main\Localization\Loc;
52 if (!self::isAvailable())
57 if (!isset(self::$availableEngines))
59 self::$availableEngines = Engine::getListAvailable(self::CATEGORY);
62 return self::$availableEngines;
75 'recommended' =>
$engine->isPreferredForQuality(
new Quality(self::QUALITY)),
82 public function updateEngine(
Chat $chat,
string $engineCode):
Result
100 $oldEngineName = $this->
getEngineNameByCode($chat->getEngineCode() ?? self::getDefaultEngineCode());
104 $result = $chat->setEngineCode($engineCode)->save();
110 (
new CopilotAnalytics($chat))->addChangeEngine($oldEngineName ??
'');
113 (
new ChangeEngine($chat, $engineCode, $engineName))
114 ->setContext($chat->getContext())
125 $user = $chat->getContext()->getUser();
126 $genderSuffix =
$user->getGender() ===
'F' ?
'_F' :
'';
130 'IM_COPILOT_UPDATE_ENGINE' . $genderSuffix,
131 [
'#USER_ID#' =>
$userId,
'#ENGINE#' => $engineName]
136 'MESSAGE_TYPE' => $chat->
getType(),
137 'TO_CHAT_ID' => $chat->getChatId(),
148 if (!self::isAvailable())
153 if (!isset(self::$defaultEngineCode))
155 self::$defaultEngineCode =
156 (string)(
new Manager())
162 return !empty(self::$defaultEngineCode) ? self::$defaultEngineCode :
null;
167 if (!self::isAvailable())
177 if (!self::isAvailable())
185 if (!isset($engineCode))
191 return Engine::getByCode($engineCode,
$context, self::CATEGORY);
201 if (!isset(
$code) || !self::isAvailable())
220 foreach ($codes as
$code)
234 if (!isset(
$code) || !self::isAvailable())
241 return $engine?->getIEngine()->getName();
247 $codeFromOption = \CUserOptions::GetOption(
249 'lastSelectedEngineCode',
254 if (is_string($codeFromOption))
256 $code = $codeFromOption;
266 \CUserOptions::SetOption(
'im',
'lastSelectedEngineCode',
$code,
false,
$userId);
274 return Loader::includeModule(
'ai');
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getType($chatData, bool $camelCase=true)
setLastSelectedEngineCode(string $code, int $userId)
static string $defaultEngineCode
getLastSelectedEngineCode(int $userId)
getAvailableEnginesForRest()
sendUpdateEngineMessage(Chat $chat, string $engineCode)
static getDefaultEngineName()
getAvailableEngineCodes()
validateEngineCode(?string $code)
getEngineNameByCode(?string $code, ?Context $context=null)
static getDefaultEngine(?Context $context=null)
static array $availableEngines
getEnginesByCodes(array $codes, ?Context $context=null)
getEngineByCode(?string $code, ?Context $context=null)
static getDefaultEngineCode()
const SETTING_COPILOT_CHAT_PROVIDER
</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