PHP code example of particle-academy / teachers-aid

1. Go to this page and download the library: Download particle-academy/teachers-aid 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/ */

    

particle-academy / teachers-aid example snippets


// AppServiceProvider::register()
use ParticleAcademy\TeachersAid\Contracts\ChatDriver;
use ParticleAcademy\TeachersAid\Drivers\PrismChatDriver;

$this->app->bind(ChatDriver::class, fn () => new PrismChatDriver(
    provider: config('teachers-aid.drivers.prism.provider'),
    model: config('teachers-aid.drivers.prism.model'),
));

use ParticleAcademy\TeachersAid\Agent\TeachersAid;
use ParticleAcademy\TeachersAid\Chat\Message;
use ParticleAcademy\TeachersAid\Plan\PlanApplier;

$result = app(TeachersAid::class)->respondTo(
    Message::user('Build a course on situational awareness from this handbook.', [$attachment]),
    $history,
);

$result->reply;          // what to show the teacher
$result->hasProposals(); // did it draft anything?
$result->plan->toArray() // the diff to render for review

$refs = app(PlanApplier::class)->apply($plan);  // ref => new id

$plan->add(ChangeOperation::create('course', ['title' => 'Patrol Basics'], ref: 'c1'));
$plan->add(ChangeOperation::create('lesson', ['course_id' => '$c1', 'title' => 'Lesson one']));

interface ChatDriver
{
    /** @param list<Message> $messages  @param list<ToolDefinition> $tools */
    public function send(array $messages, array $tools = []): ChatResponse;

    /** @return list<string> MIME types the model reads as raw bytes. [] means text-only. */
    public function nativeMimeTypes(): array;
}

'name'      => env('TEACHERS_AID_NAME', 'TAC'),   // appears in the system prompt and chat header
'driver'    => env('TEACHERS_AID_DRIVER', 'prism'),
'max_steps' => (int) env('TEACHERS_AID_MAX_STEPS', 8),

// Entity name (as the model refers to it) => model class.
// Anything absent cannot be proposed at all, so this doubles as the blast radius.
'entities' => [
    'curriculum'      => Curriculum::class,
    'course'          => Course::class,
    'lesson'          => Lesson::class,
    'test'            => Test::class,
    'question'        => Question::class,
    'question_option' => QuestionOption::class,
],

'uploads' => [
    'max_bytes'      => 20 * 1024 * 1024,
    'max_text_chars' => 200_000,
],
sh
php artisan vendor:publish --tag=teachers-aid-config   # config/teachers-aid.php