PHP code example of codingwisely / taskallama

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

    

codingwisely / taskallama example snippets


return [
    'model' => env('OLLAMA_MODEL', 'llama3.2'),
    'default_format' => 'json',
    'url' => env('OLLAMA_URL', 'http://127.0.0.1:11434'),
    'default_prompt' => env('OLLAMA_DEFAULT_PROMPT', 'Hello Taskavelian, how can I assist you today?'),
    'connection' => [
        'timeout' => env('OLLAMA_CONNECTION_TIMEOUT', 300),
    ],
];

use CodingWisely\Taskallama\Facades\Taskallama;

$response = Taskallama::agent('You are a professional task creator...')
    ->prompt('Write a task for implementing a new feature in a SaaS app.')
    ->model('llama3.2')
    ->options(['temperature' => 0.5])
    ->stream(false)
    ->ask();

return $response['response'];

use CodingWisely\Taskallama\Facades\Taskallama;

return response()->stream(function () use () {
    Taskallama::agent('You are a professional task creator...')
        ->prompt('Write a task for implementing a new feature in a SaaS app.')
        ->model('llama3.2')
        ->options(['temperature' => 0.5])
        ->stream(true)
        ->ask();
 }, 200, [
    'Cache-Control' => 'no-cache',
    'X-Accel-Buffering' => 'no',
    'Content-Type' => 'text/event-stream',
]);

use CodingWisely\Taskallama\Facades\Taskallama;
$messages = [
    ['role' => 'user', 'content' => 'Tell me about Laravel'],
    ['role' => 'assistant', 'content' => 'Laravel is a PHP framework for web development.'],
    ['role' => 'user', 'content' => 'Why is it so popular?'],
];

$response = Taskallama::agent('You are a Laravel expert.')
    ->model('llama3.2')
    ->options(['temperature' => 0.7])
    ->chat($messages);

namespace App\Livewire;

use CodingWisely\Taskallama\Taskallama;
use Livewire\Component;

class AskTaskallama extends Component
{
    public $question = '';
    public $response = '';

    public function ask()
    {
        if (empty(trim($this->question))) {
            $this->response = "Please provide a valid question.";
            return;
        }

        try {
            $this->response = Taskallama::agent('You are a task-writing assistant.')
                ->prompt($this->question)
                ->model('llama3.2')
                ->options(['temperature' => 0])
                ->stream(false)
                ->ask()['response'] ?? "No response received.";
        } catch (\Exception $e) {
            $this->response = "Error: " . $e->getMessage();
        }
    }

    public function render()
    {
        return view('livewire.ask-taskallama');
    }
}

$embeddings = Taskallama::agent('Embedding Assistant')
    ->model('llama3.2')
    ->options(['temperature' => 0.5])
    ->ask();

print_r($embeddings);

$models = Taskallama::getInstance()->listLocalModels();
print_r($models);

$modelInfo = Taskallama::getInstance()->getModelInfo('llama3.2');
print_r($modelInfo);

$modelSettings = Taskallama::getInstance()->getModelSettings('llama3.2');
print_r($modelSettings);

$pullModel = Taskallama::getInstance()->pull('mistral');
$deleteModel = Taskallama::getInstance()->delete('mistral');
bash
php artisan vendor:publish --tag="taskallama-config"