PHP code example of angelxmoreno / prompt-classes

1. Go to this page and download the library: Download angelxmoreno/prompt-classes 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/ */

    

angelxmoreno / prompt-classes example snippets


    
    
    declare(strict_types=1);
    
    namespace YourNamespace\Prompts;
    
    use PromptClasses\Core\AbstractPrompt;
    
    class HelloPrompt extends AbstractPrompt
    {
        public string $promptTpl = 'Say "Hello {{name}}. Good {{time_of_day}}"';
        public array $promptParams = ['name', 'time_of_day'];
    }
    

    $helloPrompt = new HelloPrompt($openaiApiKey);
    $response = $helloPrompt->send('John', 'Morning');
    // returns `Hello John. Good Morning`
    

    $response = $helloPrompt->send('Morning', 'John');
    // still returns `Hello John. Good Morning`
    

    
    
    declare(strict_types=1);
    
    namespace YourNamespace\Prompts;
    
    use PromptClasses\Core\AbstractPrompt;
    
    class MetaDescriptionPrompt extends AbstractPrompt
    {
        public string $promptTpl = 'Write a meta description no longer than 160 characters including spaces for a product page with the title "{{title}}"';
        public array $promptParams = ['title'];
    }
    

    $metaDescriptionPrompt = new MetaDescriptionPrompt($openaiApiKey);
    $response = $metaDescriptionPrompt->send('Supernatural Dean Winchester That was Scary Vintage Sunset T-Shirt');
    // returns `Get the Supernatural Dean Winchester 'That was Scary' Vintage Sunset T-Shirt. Show your love for the hit TV show with this iconic design.`
    

    
    
    declare(strict_types=1);
    
    namespace YourNamespace\Prompts;
    
    use PromptClasses\Core\AbstractPrompt;
    
    class MetaDescriptionPrompt extends AbstractPrompt
    {
        public string $promptTpl = 'Write a meta description no longer than 160 characters including spaces for a product page with the title "{{title}}"';
        public array $promptParams = ['title'];
        
        protected array $openaiParams = [
            'model' => 'gpt-3.5-turbo',
            'temperature' => 0.2,
            'frequency_penalty' => 1.8
        ];
    }