1. Go to this page and download the library: Download tredmann/php-ollama 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/ */
tredmann / php-ollama example snippets
use Ollama\Ollama;
$ollama = new Ollama(model: 'gemma2:latest');
echo $ollama->completion(prompt: 'What is the capitol of Germany?');
// The capital of Germany is **Berlin**.
use Ollama\Client\OllamaClient;
$client = new OllamaClient(
baseUrl: 'http://localhost:11434' // default
);
use Ollama\Api\Completion;
$completionApi = new Completion(client: $client);
use Ollama\Requests\CompletionRequest;
$request = new CompletionRequest(
model: 'phi3.5:latest',
prompt: 'What is the capitol of Germany?'
);