PHP code example of thekiharani / laravel-aria

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

    

thekiharani / laravel-aria example snippets


use NoriaLabs\Aria\Contracts\KnowledgeSource;
use NoriaLabs\Aria\Knowledge\KnowledgeDocument;

class SiteKnowledge implements KnowledgeSource
{
    public function documents(): iterable
    {
        foreach (config('lanes') as $lane) {
            yield new KnowledgeDocument(
                sourceType: 'lane',
                sourceKey: $lane['slug'],
                title: $lane['title'],
                body: $lane['headline']."\n".$lane['lede'],
                sourceUrl: '/'.$lane['slug'],
            );
        }
    }

    public function corpus(): string
    {
        return 'noria-site';
    }
}

use NoriaLabs\Aria\Contracts\Persona;

class Aria implements Persona
{
    public function instructions(): string
    {
        return 'You are Aria. Never quote a price unless asked. ...';
    }

    public function greeting(): ?string
    {
        return null;
    }
}

$this->app->bind(KnowledgeSource::class, SiteKnowledge::class);
$this->app->bind(Persona::class, Aria::class);
$this->app->tag([CaptureLead::class], 'aria.tools');

$response = app(Assistant::class)->reply('Do you do mobile money reconciliation?');

$response->text;            // the answer
$response->conversationId;  // hold this to continue the thread

app(Assistant::class)->reply($message, $conversationId);
app(Assistant::class)->reply($message, participant: $user);

return app(Assistant::class)->stream($message, $conversationId);

app(Assistant::class)->stream($message, $conversationId, onDelta: fn (string $d) => $this->stream('answer', $d));

class WorkspaceBudget implements BudgetPolicy
{
    public function cap(): ?int      { return $this->settings->aiCapUsdMicros(); }
    public function scope(): ?string { return Tenancy::currentWorkspaceId(); }
}

Aria::useConversationModel(SupportThread::class);

class Ascii implements NoriaLabs\Aria\Contracts\Normaliser
{
    public function normalise(string $text): string { /* ... */ }
}

use Laravel\Ai\Embeddings;
use NoriaLabs\Aria\Agents\AriaAgent;

AriaAgent::fake(['Yes, we do.']);
Embeddings::fake();
bash
composer vendor:publish --tag=aria-config
php artisan migrate
bash
php artisan vendor:publish --tag=aria-migrations