Skip to content

Commit

Permalink
Update OpenAiSolutionResponse.php
Browse files Browse the repository at this point in the history
  • Loading branch information
bestmomo authored Jul 22, 2024
1 parent e55d808 commit 279cc66
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/Solutions/OpenAi/OpenAiSolutionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,24 @@ public function description(): string
{
return $this->between('FIX', 'ENDFIX', $this->rawText);
}

public function links(): array
{
$rawText = Str::finish($this->rawText, 'ENDLINKS');

$rawText = Str::finish($this->rawText, 'ENDLINKS');
$textLinks = $this->between('LINKS', 'ENDLINKS', $rawText);

$textLinks = explode(PHP_EOL, $textLinks);

$textLinks = array_map(function ($textLink) {
$textLink = str_replace('\\', '\\\\', $textLink);
$textLink = str_replace('\\\\\\', '\\\\', $textLink);

return json_decode($textLink, true);
}, $textLinks);

array_filter($textLinks);

$links = [];

foreach ($textLinks as $textLink) {
$links[$textLink['title']] = $textLink['url'];
$textLink = str_replace('\\', '\\\\', $textLink);
$textLink = str_replace('\\\\\\', '\\\\', $textLink);

$decodedLink = json_decode($textLink, true);

if ($decodedLink !== null) {
// Ajouter au tableau de liens
$links[$decodedLink['title']] = $decodedLink['url'];
}
}

return $links;
Expand Down

0 comments on commit 279cc66

Please sign in to comment.