1. Go to this page and download the library: Download alex-tikhomirova/ai-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/ */
alex-tikhomirova / ai-client example snippets
use AlexTikhomirova\Ai\AiClient;
use AlexTikhomirova\Ai\Transport\GuzzleTransport;
$client = new AiClient(new GuzzleTransport('sk-...'));
$text = $client->textFromPayload([
'model' => 'gpt-4o-mini',
'input' => 'Write a short product description.',
]);
use AlexTikhomirova\Ai\AiClient;
use AlexTikhomirova\Ai\Transport\GuzzleTransport;
$transport = new GuzzleTransport('sk-...');
$client = new AiClient($transport);
$text = $client->textFromPayload([
'model' => 'gpt-4o-mini',
'input' => 'Write a short product description.',
]);
$data = $client->jsonFromPayload([
'model' => 'gpt-4o-mini',
'input' => 'Return JSON with fields title and description.',
'text' => [
'format' => [
'type' => 'json_object',
],
],
]);
use AlexTikhomirova\Ai\Prompt\PromptInterface;
final class MyPrompt implements PromptInterface
{
public function toPayload(): array
{
return [
'model' => 'gpt-4o-mini',
'input' => 'Hello',
];
}
public function outputType(): string
{
return 'text';
}
public function responseClass(): ?string
{
return null;
}
}