File: /var/www/html/laravel/app/Prompts/Notam.php
<?php
namespace App\Prompts;
use Illuminate\Support\Str;
class Notam
{
public function __construct(
public string $template
)
{
}
public static function create(string $template): Notam
{
return new self($template);
}
public function format(array $inputVariables): Notam
{
$this->template = Str::swap($inputVariables, $this->template);
return $this;
}
public function outputParser(string $outputParser): Notam
{
$this->template = Str::squish($this->template . $outputParser);
return $this;
}
public function parse($response): object
{
$formatted = str($response)
->after('```json')
->before('```')
->trim();
return (object)json_decode($formatted, true);
}
public function toString(): string
{
$this->template = Str::squish($this->template);
return $this->template;
}
}