PHP code example of token27 / nexus-ai-prompts

1. Go to this page and download the library: Download token27/nexus-ai-prompts 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/ */

    

token27 / nexus-ai-prompts example snippets


use Token27\NexusAI\Prompts\PromptEngine;

// Image/Video Prompt
$str = PromptEngine::raw("A {{animal}} in space", ['animal' => 'cat'])->asPlainString();

// Chat Prompt
$messages = PromptEngine::chat([
    ['role' => 'system', 'content' => 'You are {{persona}}'],
    ['role' => 'user', 'content' => 'Hello!'],
], ['persona' => 'helpful'])->asOpenAI();

$payload = PromptEngine::build()
    ->system('You are {{persona}}')
    ->user('Explain {{topic}}')
    ->variables(['persona' => 'teacher', 'topic' => 'Quantum Physics'])
    ->render()
    ->asAnthropic(); // returns ['system' => '...', 'messages' => [...]]

$registry->autoloadFrom(__DIR__ . '/..');

$payload = $registry->resolve('article/research')
    ->render(['topic' => 'PHP 8.4'])
    ->asGemini(); // returns ['contents' => [['role' => 'user', 'parts' => [...]]]]