PHP code example of hanwoolderink / ollama-laravel-client

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

    

hanwoolderink / ollama-laravel-client example snippets


use Hanwoolderink\Ollama\Laravel\Facades\Ollama;

$response = Ollama::chat()->create(
  model: 'llama3.1:latest', 
  message: Message::make('Why is the sky blue?')
);

echo $response->message->content;

use Hanwoolderink\Ollama\Laravel\Facades\Ollama;
use Hanwoolderink\Ollama\Dtos\Message;

$response = Ollama::chat()->stream(
    model: 'llama3.1:latest',
    messages: [
        Message::make('Why does the sky appear more blue in the morning and more red in the evening?')
    ],
);

foreach ($response as $streamResponse) {
    // update storage, socket, etc.. This prints to cli
    $stream = fopen('php://stdout', 'w');
    fwrite($stream, $streamResponse->message->content);
    fclose($stream);
}
bash
php artisan vendor:publish