1. Go to this page and download the library: Download apie/ai-instructor 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/ */
apie / ai-instructor example snippets
class MovieReview {
public function __construct(
public string $name,
public string $description,
public int $rating
) {
}
}
use Apie\AiInstructor\AiInstructor;
// ollama
$instructor = AiInstructor::createForOllama('http://localhost:11434');
// openAI
$instructor = AiInstructor::createForOpenAi('api-key');
// custom:
$instructor = AiInstructor::createForCustomConfig(
'api-key',
'http://localhost:11434/'
);
$result = $instructor->instruct(
MovieReview::class,
'tinyllama',
'You are an AI bot that comes up with a movie review for a movie made from the description given by the user. It should follow the format given. If you can not come up with a movie review of the description given by the user, then make a review of a random Hollywood movie.',
'I think the Lord of the Rings movie has dated terrible'
);
var_dump($result); // dumps a MovieReview instance.