1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
RequestSingle.php
См. документацию.
1
<?php
2
declare(strict_types=1);
3
4
namespace
Bitrix\Landing\Copilot\Generation\Step;
5
6
use Bitrix\Landing\Copilot\Connector\AI\Prompt;
7
use Bitrix\Landing\Copilot\Data\Site;
8
use Bitrix\Landing\Copilot\Generation\GenerationException;
9
use Bitrix\Landing\Copilot\Generation\Request;
10
use Bitrix\Landing\Copilot\Generation\Type\GenerationErrors;
11
use Bitrix\Landing\Copilot\Generation\Type\RequestQuotaDto;
12
13
abstract
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
}
Bitrix\Landing\Copilot\Connector\AI\Prompt
Определения
Prompt.php:7
Bitrix\Landing\Copilot\Generation\GenerationException
Определения
GenerationException.php:11
Bitrix\Landing\Copilot\Generation\Request\getByGeneration
static getByGeneration(int $generationId, int $stepId)
Определения
Request.php:347
Bitrix\Landing\Copilot\Generation\Step\AIStep
Определения
AIStep.php:9
Bitrix\Landing\Copilot\Generation\Step\BaseStep\$siteData
Data Site $siteData
Определения
BaseStep.php:14
Bitrix\Landing\Copilot\Generation\Step\RequestSingle
Определения
RequestSingle.php:14
Bitrix\Landing\Copilot\Generation\Step\RequestSingle\getPrompt
getPrompt()
Bitrix\Landing\Copilot\Generation\Step\RequestSingle\verifyResponse
verifyResponse()
Bitrix\Landing\Copilot\Generation\Step\RequestSingle\getRequestQuota
static getRequestQuota(Site $siteData)
Bitrix\Landing\Copilot\Generation\Step\RequestSingle\execute
execute()
Определения
RequestSingle.php:32
Bitrix\Landing\Copilot\Generation\Step\RequestSingle\isStarted
isStarted()
Определения
RequestSingle.php:73
Bitrix\Landing\Copilot\Generation\Step\RequestSingle\clearErrors
clearErrors()
Определения
RequestSingle.php:91
Bitrix\Landing\Copilot\Generation\Step\RequestSingle\$request
Request $request
Определения
RequestSingle.php:15
Bitrix\Landing\Copilot\Generation\Step\RequestSingle\initialize
initialize()
Определения
RequestSingle.php:20
Bitrix\Landing\Copilot\Generation\Step\RequestSingle\applyResponse
applyResponse()
Bitrix\Landing\Copilot\Generation\Step\RequestSingle\isFinished
isFinished()
Определения
RequestSingle.php:81
Bitrix\Landing\Copilot\Generation\Type\RequestQuotaDto
Определения
RequestQuotaDto.php:7
Bitrix\Main\Request
Определения
request.php:10
Bitrix\Landing\Site
Определения
cookies.php:2
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
bitrix
modules
landing
lib
Copilot
Generation
Step
RequestSingle.php
Создано системой
1.14.0