1. Go to this page and download the library: Download pv-source/aivory 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/ */
pv-source / aivory example snippets
use PvSource\Aivory\Client;
use PvSource\Aivory\LLM\Turn\Turn;
// Создаем клиент
$client = new Client(
providerName: 'deepseek',
auth: ['apiKey' => 'sk-your-api-key']
);
$provider = $client->getProvider();
// Отправляем запрос
$turn = Turn::query()
->withProvider($provider)
->setUserPrompt('Привет! Расскажи о PHP')
->setModel('deepseek-chat')
->setTemperature(0.7)
->send();
// Получаем ответ
$assistantMessage = $turn->getResponse()->getAssistant();
echo $assistantMessage->content;
use PvSource\Aivory\LLM\Turn\Request\ResponseFormat;
// Создаем ResponseFormat с использованием класса
$responseFormat = ResponseFormat::jsonSchema(
schema: ['type' => MathSolution::class],
name: 'math_solution',
strict: true
);
$turn = Turn::query()
->withProvider($provider)
->setUserPrompt('Реши: 2 + 2 * 3')
->setModel('deepseek-chat')
->setResponseFormat($responseFormat)
->send();
// Автоматическое преобразование в типизированный объект
$mathSolution = $turn->getResponse()->getSchemaObjects();
echo $mathSolution->answer; // "8"
$client = new Client(
providerName: 'deepseek', // или 'openai'
auth: ['apiKey' => 'sk-...'],
httpClient: $customHttpClient // опционально
);