1. Go to this page and download the library: Download xmon-org/ai-content-bundle 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/ */
xmon-org / ai-content-bundle example snippets
use Xmon\AiContentBundle\Enum\TaskType;
use Xmon\AiContentBundle\Service\AiTextService;
class MyService
{
public function __construct(
private readonly AiTextService $aiTextService,
) {}
public function summarize(string $content): string
{
// Uses the model configured for NEWS_CONTENT task
$result = $this->aiTextService->generateForTask(
TaskType::NEWS_CONTENT,
systemPrompt: 'You are a helpful assistant.',
userMessage: "Summarize: {$content}",
);
return $result->getText();
}
}
use Xmon\AiContentBundle\Service\AiImageService;
class MyService
{
public function __construct(
private readonly AiImageService $aiImageService,
) {}
public function generateImage(): void
{
// Uses the model configured for IMAGE_GENERATION task
$result = $this->aiImageService->generateForTask(
prompt: 'A serene Japanese dojo with morning light',
);
file_put_contents('image.png', $result->getBytes());
}
}
// Use specific model without fallback
$result = $this->aiTextService->generate($system, $user, [
'model' => 'claude',
'use_fallback' => false,
'timeout' => 120,
]);
// Use specific model with fallback to configured fallback_models
$result = $this->aiTextService->generate($system, $user, [
'model' => 'claude',
'use_fallback' => true,
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.