1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
RequestSingle.php
См. документацию.
1<?php
2declare(strict_types=1);
3
4namespace Bitrix\Landing\Copilot\Generation\Step;
5
6use Bitrix\Landing\Copilot\Connector\AI\Prompt;
7use Bitrix\Landing\Copilot\Data\Site;
8use Bitrix\Landing\Copilot\Generation\GenerationException;
9use Bitrix\Landing\Copilot\Generation\Request;
10use Bitrix\Landing\Copilot\Generation\Type\GenerationErrors;
11use Bitrix\Landing\Copilot\Generation\Type\RequestQuotaDto;
12
13abstract class RequestSingle extends AIStep
14{
15 protected ?Request $request = null;
16
20 public function initialize(): void
21 {
22 $existsRequests = Request::getByGeneration($this->generation->getId(), $this->stepId);
23 if (!empty($existsRequests))
24 {
25 $this->request = array_shift($existsRequests);
26 }
27 }
28
32 public function execute(): bool
33 {
34 if (!parent::execute())
35 {
36 return false;
37 }
38
39 if (!isset($this->siteData, $this->stepId))
40 {
41 return false;
42 }
43
44 if (!isset($this->request))
45 {
46 $this->request = new Request($this->generation->getId(), $this->stepId);
47 $this->request->send($this->getPrompt(), $this->connector);
48 }
49 elseif ($this->request->getError())
50 {
51 throw new GenerationException(
52 GenerationErrors::notCorrectResponse,
53 $this->request->getError()->getMessage(),
54 );
55 }
56
57 if ($this->request->isReceived())
58 {
59 $this->verifyResponse();
60 if ($this->applyResponse())
61 {
62 $this->request->setApplied();
63 }
64 $this->changed = true;
65 }
66
67 return true;
68 }
69
73 public function isStarted(): bool
74 {
75 return isset($this->request);
76 }
77
81 public function isFinished(): bool
82 {
83 return
84 isset($this->request)
85 && $this->request->isApplied();
86 }
87
91 public function clearErrors(): void
92 {
93 if (
94 $this->request
95 && $this->request->getError()
96 )
97 {
98 $this->request->setDeleted();
99 $this->request = null;
100 }
101 }
102
108 abstract protected function getPrompt(): Prompt;
109
115 abstract protected function applyResponse(): bool;
116
122 abstract public function verifyResponse(): void;
123
127 abstract public static function getRequestQuota(Site $siteData): ?RequestQuotaDto;
128}
static getByGeneration(int $generationId, int $stepId)
Определения Request.php:347
Определения request.php:10
Определения cookies.php:2
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393