1. Go to this page and download the library: Download easybdit/laraveleasyai 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/ */
easybdit / laraveleasyai example snippets
// Same code. Any provider. Just change the name.
$response = AI::provider('ollama')->chat($messages); // Self-hosted, free
$response = AI::provider('openai')->chat($messages); // ChatGPT
$response = AI::provider('anthropic')->chat($messages); // Claude
$response = AI::provider('deepseek')->chat($messages); // DeepSeek
echo ai('What is Laravel?'); // running against a model on your own machine
use EasyAI\LaravelAI\Facades\AI;
AI::rag()->ingest('Refunds are accepted within 30 days of purchase.', 'policies');
$answer = AI::rag()->ask('What is the refund window?');
// "Refunds are accepted within 30 days of purchase."
use EasyAI\LaravelAI\Facades\AI;
$response = AI::chat([['role' => 'user', 'content' => 'What is Laravel?']]);
echo $response->content;
$answer = ai('What is Laravel?');
// routes/web.php — good enough for trying things out, no view/controller needed
use EasyAI\LaravelAI\Facades\AI;
Route::get('/test-ai', function () {
$response = AI::chat([['role' => 'user', 'content' => 'What is Laravel?']]);
return $response->content;
});
interface VectorStoreInterface
{
public function upsert(string $content, string $source, array $embedding): void;
public function search(array $queryEmbedding, ?string $source, int $topK): array;
public function delete(?string $source): void;
public function count(?string $source): int;
}
public function register(): void
{
$this->app->bind(
\EasyAI\LaravelAI\Commerce\Contracts\ProductResolver::class,
\App\Services\MyProductResolver::class
);
}
AI::custom('lmstudio')->chat($messages);
// or, in the chat UI provider selector: "custom:lmstudio"
use EasyAI\LaravelAI\Agent\Tool;
$weather = Tool::make(
name: 'get_weather',
description: 'Get the current weather for a city.',
parameters: ['type' => 'object', 'properties' => ['city' => ['type' => 'string']], '
$response = AI::provider('openai')->tools([$weather])->run([
['role' => 'user', 'content' => 'What is the weather in Paris?'],
]);
echo $response->content;
// "It's currently 22°C and sunny in Paris."
$response = AI::provider('anthropic')->tools([$weather, $calculator])->run([
['role' => 'user', 'content' => 'What is 12 times 7?'],
]);
echo $response->content; // the final answer
$response->hasToolCalls(); // false on the final turn (that's how run() knows to stop)
use EasyAI\LaravelAI\Agent\Tools\WebSearchTool;
$response = AI::provider('openai')
->tools([WebSearchTool::make()])
->run([['role' => 'user', 'content' => 'What happened in the news today about Laravel?']]);
$response = AI::provider('openai')->model('gpt-4o-mini')->chat($messages);
$response->getEstimatedCost(); // 0.0007 (float, USD) — or null if that exact provider/model pair has no configured rate
// ❌ This shadows every package route, including its JSON APIs
Route::get('/{any}', fn () => view('app'))->where('any', '.*');
// ✅ Use fallback() instead — it only matches when nothing else did
Route::fallback(fn () => view('app'));
// routes/api.php, inside your existing auth:sanctum group
Route::post('/session-bridge', function (Request $request) {
Auth::guard('web')->login($request->user());
$request->session()->regenerate();
return response()->json(['ok' => true]);
});