1. Go to this page and download the library: Download kaviyarasu/ai-agent 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/ */
kaviyarasu / ai-agent example snippets
use Kaviyarasu\AIAgent\Facades\AIAgent;
// Text generation
$response = AIAgent::text()->generateText('Write a story about a robot');
// Stream text generation
foreach (AIAgent::text()->streamText('Explain the theory of relativity') as $chunk) {
echo $chunk;
}
// Image generation
$response = AIAgent::image()->generateImage('A futuristic city at sunset');
// Switch provider at runtime
$response = AIAgent::provider('openai')->text()->generateText('Hello world');
use Kaviyarasu\AIAgent\Facades\AIAgent;
// Use specific model with custom parameters
$response = AIAgent::provider('claude')
->text()
->switchModel('claude-3-opus-20240229')
->generateText('Explain quantum computing', [
'max_tokens' => 1000,
'temperature' => 0.7,
'top_p' => 0.9
]);
// Generate image with specific dimensions
$response = AIAgent::provider('openai')
->image()
->switchModel('dall-e-3')
->generateImage('A serene landscape with mountains', [
'size' => '1024x1024',
'quality' => 'hd',
'style' => 'vivid'
]);
// Generate multiple images
$response = AIAgent::provider('openai')
->image()
->generateMultipleImages('A serene landscape with mountains', 3);
use Kaviyarasu\Agent\Facades\Agent;
// Generate text
$response = Agent::generateText('Write a haiku about Laravel');
// Create an image
$response = Agent::provider('openai')->generateImage('A coding workspace');
// Switch providers dynamically
$result = Agent::provider('claude')->generateText('Explain quantum computing');