1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
BaseConnector.php
См. документацию.
1<?php
2declare(strict_types=1);
3
5
6use Bitrix\AI\Context;
7use Bitrix\AI\Engine;
11
12abstract class BaseConnector implements IConnector
13{
14 protected const CATEGORY = 'text';
15
16 protected const CONTEXT_ID = 'landing_site_copilot';
17 protected const DEFAULT_TEMPERATURE = 0.7;
18 protected const MAX_TOKENS = 16383;
19
20 protected const PROMPT_CODE = 'zero_prompt';
21 protected const PROMPT_CATEGORY = '';
22
23 protected bool $active = true;
24 protected ?Engine $engine;
25 protected float $temperature = self::DEFAULT_TEMPERATURE;
26
30 public function __construct()
31 {
32 if (!Loader::includeModule('ai'))
33 {
34 $this->active = false;
35 }
36 else
37 {
38 $engineCode = static::getEngineCode();
39 if ($engineCode)
40 {
41 $this->active = true;
42 $this->engine = Engine::getByCode(
43 $engineCode,
44 new Context('landing', static::CONTEXT_ID),
45 static::CATEGORY
46 );
47 }
48 }
49 }
50
54 abstract public function request(Prompt $prompt): Main\Result;
55
56 abstract protected function getEngineCode(): ?string;
57
58 protected function canRequest(): bool
59 {
60 return $this->active && isset($this->engine);
61 }
62
63 public function setTemperature(float $temperature): self
64 {
65 $this->temperature = $temperature;
66
67 return $this;
68 }
69}
setTemperature(float $temperature)
Определения BaseConnector.php:63
Определения result.php:20
Определения loader.php:13
Определения culture.php:9
Определения action.php:3