PHP code example of lonnieezell / scribe

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

    

lonnieezell / scribe example snippets




// Define once
class SummarizePrompt extends BasePrompt
{
    public function __construct(private string $text) {}

    public function systemPrompt(): string
    {
        return 'You are a concise summarizer. Return a 2-sentence summary.';
    }

    public function userPrompt(): string
    {
        return 'Summarize: ' . $this->text;
    }
}

// Use anywhere in your CI4 app
$response = service('scribe')->run(new SummarizePrompt($articleText));
echo $response->content;

public array $drivers = [
    'claude' => [
        'apiKey' => env('CLAUDE_API_KEY', ''),
        'model'  => 'claude-haiku-4-5',
    ],
    // ...
];



namespace App\Prompts;

use Myth\Scribe\Prompts\BasePrompt;

class ClassifyEmailPrompt extends BasePrompt
{
    public function __construct(private string $emailBody) {}

    public function systemPrompt(): string
    {
        return 'Classify the email as spam or not_spam.';
    }

    public function userPrompt(): string
    {
        return $this->emailBody;
    }

    public function schema(): ?array
    {
        return [
            'type'       => 'object',
            'properties' => ['label' => ['type' => 'string', 'enum' => ['spam', 'not_spam']]],
            '

$response = service('scribe')->run(new ClassifyEmailPrompt($body));
$result   = $response->toArray(); // ['label' => 'spam']

use Myth\Scribe\Drivers\FakeDriver;

$fake = new FakeDriver(['content' => '{"label":"spam"}']);
// inject $fake into your service or swap the driver in config

$prompt = new SummarizePrompt($text);
$prompt->driver = 'openai';
bash
php spark publish:config AI