1. Go to this page and download the library: Download modelflow-ai/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/ */
modelflow-ai / ollama example snippets
use ModelflowAi\Ollama\Ollama;
// Create a client instance
$client = Ollama::client();
// Use the client
$chat = $client->chat();
$completion = $client->completion();
$embeddings = $client->embeddings();
// Example usage of chat
$chatResponse = $chat->create([
'model' => 'llama2',
'messages' => [['role' => 'user', 'content' => 'Hello, world!']],
]);
echo $chatResponse->message->content;
// Example usage of completion
$completionResponse = $completion->create([
'model' => 'llama2',
'prompt' => 'Once upon a time',
]);
echo $completionResponse->response;
// Example usage of embeddings
$embeddingsResponse = $embeddings->create(['prompt' => 'Hello, world!']);
echo $embeddingsResponse->embedding;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.