1. Go to this page and download the library: Download ogi/prompt library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ogi / prompt example snippets
gi\Prompt\Prompt;
class MyPrompt extends Prompt
{
public $purpose = 'Who are the leaders of England, France and Russia when World War 2 started';
public $instructions = [
'For definition of leader consider titles - king, prime-minister, president',
'Present the output in a markdown table with columns leader title,name, country'
];
}
$prompt = new MyPrompt();
echo $prompt->render();
class MyPrompt extends Prompt
{
public $questions = [
'What is your name?',
'How old are you?',
'What is your favorite color?',
];
}
$prompt = new MyPrompt();
echo $prompt->render();
use Illuminate\Support\Collection;
class MyPrompt extends Prompt
{
public $items;
public function __construct()
{
$this->items = new Collection([
'First Item',
'Second Item',
new Collection(['Nested Item 1', 'Nested Item 2']),
'Third Item',
]);
}
}
$prompt = new MyPrompt();
echo $prompt->render();
class SubPrompt extends Prompt
{
public $message = 'This is a sub-prompt.';
public $details = [
'detail1' => 'Detail One',
'detail2' => 'Detail Two',
];
}
class MyPrompt extends Prompt
{
public $title = 'Main Prompt';
public $subPrompt;
public function __construct()
{
$this->subPrompt = new SubPrompt();
}
}
$prompt = new MyPrompt();
echo $prompt->render();
gi\Prompt\Templates\GeneralPromptTemplate;
class MyPrompt extends GeneralPromptTemplate
{
public function setInput($data): void
{
$this->input = $data;
}
}
$prompt = new MyPrompt();
$prompt->addContext('Provide recommendations based on user input.');
$prompt->addPurpose('To give tailored advice for improving coding practices.');
$prompt->addGoal('Ensure the recommendations are practical and concise.');
$prompt->addInputDefinition('A brief description of the code the user wants feedback on.');
$prompt->addOutputDefinition('A list of suggestions to improve the user’s code.');
$prompt->addHowtoSteps([
'Analyze the provided code.',
'Identify areas of improvement.',
'Provide actionable feedback with examples.',
]);
echo $prompt->render();
class CustomObject
{
public function toArray()
{
return [
'keyA' => 'Value A',
'keyB' => 'Value B',
];
}
}
class MyPrompt extends Prompt
{
public $customData;
public function __construct()
{
$this->customData = new CustomObject();
$this->customArray = [1,2, new CustomObject()];
}
}
$prompt = new MyPrompt();
echo $prompt->render();
class StringableObject
{
public function __toString()
{
return 'I can be converted to a string!';
}
}
class MyPrompt extends Prompt
{
public $stringable;
public function __construct()
{
$this->stringable = new StringableObject();
}
}
$prompt = new MyPrompt();
echo $prompt->render();
class MyPrompt extends Prompt
{
public $publicProperty = 'Public Value';
protected $protectedProperty = 'Protected Value';
private $privateProperty = 'Private Value';
}
$prompt = new MyPrompt();
echo $prompt->render();
class MyPrompt extends Prompt
{
public $nullProperty = null;
public $emptyArray = [];
}
$prompt = new MyPrompt();
echo $prompt->render();
class MyPrompt extends Prompt
{
public $trueProperty = true;
public $falseProperty = false;
}
$prompt = new MyPrompt();
echo $prompt->render();
class MyPrompt extends Prompt
{
public $integerProperty = 42;
public $floatProperty = 3.14;
}
$prompt = new MyPrompt();
echo $prompt->render();
class MyPrompt extends Prompt
{
public $specialChars = 'Special < & > " \' Characters';
}
$prompt = new MyPrompt();
echo $prompt->render();
class NonStringableObject
{
public $data = 'Some Data';
}
class MyPrompt extends Prompt
{
public $nonStringableObject;
public function __construct()
{
$this->nonStringableObject = new NonStringableObject();
}
}
$prompt = new MyPrompt();
echo $prompt->render();
class MyPrompt extends Prompt
{
public $me;
public function __construct()
{
$this->me = $this;
}
}
$prompt = new MyPrompt();
echo $prompt->render();