1. Go to this page and download the library: Download falahatiali/homa 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/ */
falahatiali / homa example snippets
use Homa\Facades\Homa;
$response = Homa::ask('Hello!');
$response = Homa::provider('ollama')->ask('Explain Laravel service container.');
echo $response->content();
use Homa\Facades\Homa;
$response = Homa::ask('What is Laravel?');
echo $response->content();
// Use OpenAI
$openaiResponse = Homa::provider('openai')
->model('gpt-4')
->ask('What is Laravel?');
// Use Anthropic Claude
$claudeResponse = Homa::provider('anthropic')
->model('claude-3-5-sonnet-20241022')
->ask('What is Laravel?');
// Use Groq (Ultra-fast inference)
$groqResponse = Homa::provider('groq')
->model('openai/gpt-oss-20b')
->ask('What is Laravel?');
// Use Gemini (Google AI with multimodal)
$geminiResponse = Homa::provider('gemini')
->model('gemini-2.0-flash-exp')
->ask('What is Laravel?');
$response = Homa::systemPrompt('You are a Laravel expert. Answer concisely.')
->ask('What is a service provider?');
$conversation = Homa::startConversation();
$response1 = $conversation->ask('Hello! My name is Ali.');
// AI: Hello Ali! Nice to meet you...
$response2 = $conversation->ask('What is my name?');
// AI: Your name is Ali.
// Access conversation history
$history = $conversation->history();
// Clear conversation and start fresh
$conversation->clear();
$messages = [
['role' => 'system', 'content' => 'You are a helpful Laravel assistant.'],
['role' => 'user', 'content' => 'What are service containers?'],
['role' => 'assistant', 'content' => 'Service containers are...'],
['role' => 'user', 'content' => 'Can you give me an example?'],
];
$response = Homa::chat($messages);
$response = Homa::ask('Hello!');
// Get the response content
$content = $response->content();
// Get the model used
$model = $response->model();
// Get usage statistics (tokens, etc.)
$usage = $response->usage();
// Get raw API response
$raw = $response->raw();
// Convert to array
$array = $response->toArray();
// Convert to JSON
$json = $response->toJson();
// Use as string
echo $response; // Automatically calls content()
$blogPost = Homa::model('gpt-4')
->maxTokens(2000)
->ask('Write a blog post about Laravel best practices');
$response = Homa::systemPrompt('You are an expert PHP developer.')
->ask('Review this code and suggest improvements: ' . $code);
$conversation = Homa::systemPrompt('You are a helpful customer support agent.')
->startConversation();
$response = $conversation->ask($customerQuestion);
$analysis = Homa::model('claude-3-5-sonnet-20241022')
->ask("Analyze this data and provide insights: " . json_encode($data));
use Homa\Contracts\AIProviderInterface;
use Homa\Response\AIResponse;
class CustomProvider implements AIProviderInterface
{
public function sendMessage(array $messages, array $options = []): AIResponse
{
// Your implementation
}
// Implement other
bash
php artisan vendor:publish --tag=homa-config
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.