PHP code example of devdojo / ai

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

    

devdojo / ai example snippets


$response = ai('What is the meaning of life?');

$response = ai('What color is the sky?', function($chunk){
    // $chunk will contain the stream text response
});

Route::get('question', function(){
    echo ai('What is the meaning of life?');
});

public function submit($input)
{
    $this->output = ai($input, function($chunk){
        logger($chunk);
    });
}

<livewire:basic-example />
<livewire:chat-example />

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>AI Examples</title>
        @vite(['resources/css/app.css', 'resources/js/app.js'])
    </head>
    <body class="w-screen h-screen flex items-center bg-stone-100 justify-center">
        <div class="w-full max-w-7xl gap-5 mx-auto flex items-stretch">
            <div class="h-full flex-1 p-10 space-y-5 rounded-xl bg-white shadow-sm">
                <h2 class="text-xl font-semibold">Basic Example</h2>
                <livewire:basic-example />
            </div>
            <div class="h-full flex-1 mx-auto p-10 space-y-5 rounded-xl bg-white shadow-sm">
                <h2 class="text-xl font-semibold">Chat Example</h2>
                <livewire:chat-example />
            </div>
        </div>
    </body>
</html>



return [
    /*
    |--------------------------------------------------------------------------
    | AI Configuration
    |--------------------------------------------------------------------------
    |
    | Configuration options for the DevDojo AI package.
    |
    */

    'default_provider' => env('AI_DEFAULT_PROVIDER', 'openai'),
    'default_model' => env('AI_DEFAULT_MODEL', 'gpt-4'),
];

php artisan ai:install-examples