1. Go to this page and download the library: Download solution-forest/ai-kit-core 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/ */
solution-forest / ai-kit-core example snippets
use SolutionForest\AiKit\Models\Collection;
use SolutionForest\AiKit\Ingestion\IngestionService;
use SolutionForest\AiKit\Agents\RagAgent;
// 1. Create a knowledge base and ingest documents.
$kb = Collection::create(['name' => 'Handbook']);
app(IngestionService::class)->createFromPath($kb, storage_path('handbook.pdf'), sync: true);
app(IngestionService::class)->createFromUrl($kb, 'https://example.com/faq', sync: true);
// 2. Ask a question — grounded, cited, provider from config.
$response = (new RagAgent('handbook'))->prompt('What is the refund window?');
echo $response->text;
use SolutionForest\AiKit\Agents\RagAgent;
(new RagAgent(collection: 'handbook'))
->forTenant('acme') // optional tenant scope
->prompt('...'); // uses ai-kit.chat.provider + model
namespace App\Ai;
use SolutionForest\AiKit\Agents\RagAgent;
final class SupportAgent extends RagAgent
{
public function instructions(): \Stringable|string
{
return 'You are our support assistant. Always search first; answer only from the knowledge base; cite sources.';
}
}
use SolutionForest\AiKit\Support\UsageStats;
app(UsageStats::class)->totals(30); // ['prompt'=>, 'completion'=>, 'total'=>, 'cost'=>, 'messages'=>]
app(UsageStats::class)->daily(14); // per-day token series
app(UsageStats::class)->conversationTokens($id);
use SolutionForest\AiKit\Facades\AiKit;
AiKit::withTenant('acme', fn () => (new RagAgent('handbook'))->prompt('...'));
use SolutionForest\AiKit\Services\ChatService;
$result = app(ChatService::class)->ask('What is the refund window?', 'handbook');
$result->answer; // string
$result->citations; // [{document_title, chunk_index, score, content}, ...]
$result->usage; // {in, out, total}