1. Go to this page and download the library: Download rajanvijayan/ai-engine 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/ */
rajanvijayan / ai-engine example snippets
AIEngine\AIEngine;
// Create with Gemini (default)
$ai = new AIEngine('your-gemini-api-key');
$response = $ai->generateContent('Hello! How are you?');
echo $response;
// Gemini
$ai = new AIEngine($geminiKey, ['provider' => 'gemini']);
// Meta Llama
$ai = new AIEngine($metaKey, ['provider' => 'meta']);
// Groq (Llama models)
$ai = AIEngine::create('groq', $groqKey);
$ai = AIEngine::create('groq', $groqKey);
$ai->setSystemInstruction("You are a helpful assistant.");
// Start a conversation
$ai->chat("My name is John");
$ai->chat("What's my name?"); // AI remembers: "John"
// Clear conversation
$ai->newConversation();
new AIEngine($apiKey, $config = [])
[
'provider' => 'gemini', // 'gemini', 'meta', or 'groq'
'model' => null, // Model name (uses provider default if null)
'timeout' => 60, // Request timeout in seconds
'enable_logging' => false // Enable logging
]
$ai = new AIEngine($apiKey);
$answer = $ai->generateContent('What is the capital of France?');
echo $answer;
$ai = AIEngine::create('groq', $groqKey);
$ai->setSystemInstruction("You are a math tutor. Be concise.");
echo $ai->chat("What is 15 + 27?"); // "42"
echo $ai->chat("Multiply that by 2"); // "84" - remembers previous answer!