87 $result = $this->request->getResult();
95 $markers = $prompt->getMarkers();
97 if (isset($markers[
'json_schema_blocks']))
99 $jsonSchemaBlocks = $markers[
'json_schema_blocks'];
107 GenerationErrors::notCorrectResponse,
108 "Response is not decoded.",
113 if (isset(
$result, $jsonSchemaBlocksArray))
116 if (isset($jsonSchemaBlocksArray[
'blocks'],
$result[
'blocks']))
118 $countBlocksInRequest =
count($jsonSchemaBlocksArray[
'blocks']);
120 $diffCount = $countBlocksInRequest - $countBlocksInResult;
121 if ($diffCount < 0 || $diffCount > 2)
124 GenerationErrors::notFullyResponse,
125 "The number of blocks does not match the expected range.",
132 GenerationErrors::notFullyResponse,
138 $filteredResultBlocks = array_filter(
$result[
'blocks'],
static function ($block)
140 return isset($block[
'titleInMenu']) && $block[
'titleInMenu'] !==
'';
142 $countTitlesInResult =
count($filteredResultBlocks);
143 if ($countTitlesInResult < 4)
146 GenerationErrors::notFullyResponse,
147 "Not enough titles in the menu.",
152 if (isset($diffCount) && $diffCount === 0)
155 for (
$i = 0;
$i < $blocksCount - 1;
$i++)
157 $countBlockNodesInRequest =
count($jsonSchemaBlocksArray[
'blocks'][
$i][
'nodes']);
159 $diffCount = $countBlockNodesInRequest - $countBlockNodesInResult;
160 if ($diffCount < -1 || $diffCount > 1)
163 GenerationErrors::notFullyResponse,
164 "The number of nodes in block $i does not match the expected range.",
174 foreach (
$siteData->getBlocks() as $blockData)
176 if ($blockData->isSeparator() || $blockData->isMenu())
181 foreach ($blockData->getNodes() as $nodeData)
183 if ($nodeData->getType() !== NodeType::Img)
188 if (method_exists($nodeData,
'getGenderData') && !empty($nodeData->getGenderData()))
193 $countPromptTexts = 0;
194 $promptTexts = $nodeData->getPromptTexts();
195 if (is_array($promptTexts))
197 $countPromptTexts =
count($promptTexts);
200 $countPlaceholders = 0;
201 $placeholders = $nodeData->getPlaceholders();
202 if (is_array($placeholders))
204 $countPlaceholders =
count($placeholders);
207 if ($countPromptTexts !== $countPlaceholders)
209 $diffCount = $countPlaceholders - $countPromptTexts;
212 for (
$i = 0;
$i < $diffCount;
$i++)
219 $updatedPromptTexts = [];
220 foreach ($promptTexts as $promptText)
222 if (is_string($promptText) && $promptText !==
'')
224 $updatedPromptTexts[] = $promptText;
229 $updatedPromptTexts[] = $promptGenerator->getRandomReservePromptText();
232 $nodeData->setPromptTexts($updatedPromptTexts);