1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
RequestSiteData.php
См. документацию.
1<?php
2declare(strict_types=1);
3
4namespace Bitrix\Landing\Copilot\Generation\Step;
5
6use Bitrix\Landing\Copilot\Connector\AI;
7use Bitrix\Landing\Copilot\Connector\AI\Prompt;
8use Bitrix\Landing\Copilot\Data\Site;
9use Bitrix\Landing\Copilot\Generation\Error;
10use Bitrix\Landing\Copilot\Generation\GenerationException;
11use Bitrix\Landing\Copilot\Generation\Markers;
12use Bitrix\Landing\Copilot\Generation\Type\Errors;
13use Bitrix\Landing\Copilot\Generation\Type\GenerationErrors;
14use Bitrix\Landing\Copilot\Generation\Type\RequestQuotaDto;
15
17{
18 public function __construct()
19 {
20 parent::__construct();
21 if (class_exists(self::getConnectorClass()))
22 {
23 $this->connector = new (self::getConnectorClass())();
24 }
25 }
26
30 public static function getConnectorClass(): string
31 {
32 return AI\Text::class;
33 }
34
39 {
40 return new RequestQuotaDto(self::getConnectorClass(), 1);
41 }
42
43 protected function getPrompt(): Prompt
44 {
45 $prompt = new Prompt('landing_ai_data');
46 $prompt->setMarkers(Markers::getSiteDataPromptMarkers($this->siteData));
47
48 return $prompt;
49 }
50
51 protected function applyResponse(): bool
52 {
53 $result = $this->request->getResult();
54
55 if ($result)
56 {
57 Site::initSite($this->siteData, $result);
58 }
59
60 return true;
61 }
62
72 public function verifyResponse(): void
73 {
74 $result = $this->request->getResult();
75
76 if (!$result)
77 {
78 throw new GenerationException(GenerationErrors::notExistResponse);
79 }
80
81 if (
82 !isset($result['siteData']['isAllowedRequest'])
83 || $result['siteData']['isAllowedRequest'] !== "yes"
84 )
85 {
86 $this->request->saveError(Error::createError(Errors::requestNotAllowed));
87
88 throw new GenerationException(GenerationErrors::restrictedRequest);
89 }
90
91 if (
92 !isset($result['siteData']['colors'])
93 && !isset($result['siteData']['titles'])
94 )
95 {
96 throw new GenerationException(
97 GenerationErrors::notFullyResponse,
98 "Missing required 'colors' or 'titles' in 'siteData'.",
99 );
100 }
101 }
102}
static createError(?Errors $code=null)
Определения Error.php:53
static getSiteDataPromptMarkers(Data\Site $siteData)
Определения Markers.php:39
$result
Определения get_property_values.php:14
Определения cookies.php:2