PHP code example of sabatinomasala / laravel-llm-prompt

1. Go to this page and download the library: Download sabatinomasala/laravel-llm-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/ */

    

sabatinomasala / laravel-llm-prompt example snippets


php artisan make:prompt Example



namespace App\Prompts;

use SabatinoMasala\LaravelLlmPrompt\BasePrompt;

class Example extends BasePrompt
{

    public function __construct(
        public string $language = 'English'
    ) {}

    public function getBasePrompt(): string
    {
        // You can use variables in the prompt
        return 'Explain the pythagorean theorem in {language} as if I were a 5 year old.';
    }
}

$prompt = new \App\Prompts\Example('French');
echo $prompt->get();
// Explain the pythagorean theorem in French as if I were a 5 year old.



namespace App\Prompts;

use SabatinoMasala\LaravelLlmPrompt\BasePrompt;

class Brainstorm extends BasePrompt
{

    public function __construct(
        public string $language,
        public string $series,
    ){}

    public function addHistory(array $history): void
    {
        $this->add('Make sure the following titles are not in the list:');
        collect($history)->each(function($line) {
            $this->add('- ' . $line);
        });
    }

    public function getBasePrompt(): string
    {
        return 'Give me a list of 30 story titles in {language} I can write.
Only respond with a list of titles, no other information.
1 title per line.
A good title consists of 4-8 words.
Do not number the list.
You will be penalized if the language is not {language}
The story should fit in the series {series}';
    }
}