1. Go to this page and download the library: Download sentix/ai-chatbot 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/ */
sentix / ai-chatbot example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Sentix\AiChatbot\Traits\HasAiContext;
class Product extends Model
{
use HasAiContext;
// Define fields exposed to the AI chatbot (defaults to $fillable if not set)
protected $aiFields = ['id', 'name', 'price', 'description', 'in_stock'];
// Relationships are automatically detected if the related model ALSO uses HasAiContext!
public function category()
{
return $this->belongsTo(Category::class);
}
public function reviews()
{
return $this->hasMany(Review::class);
}
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Sentix\AiChatbot\Traits\HasAiContext;
class Category extends Model
{
use HasAiContext;
protected $aiFields = ['id', 'name', 'slug'];
}
public function scopeUserScoped($query, $userId)
{
return $query->where('customer_id', $userId);
}
'custom_context' => [
'How to add products' => 'Go to Admin > Products > Click Add Product. Fill in Name, Price, SKU, and Category.',
'Menu Navigation' => 'Header menu
use Sentix\AiChatbot\Contracts\AiToolInterface;
use Sentix\AiChatbot\Tools\AiToolRegistry;
class GetOrderStatusTool implements AiToolInterface
{
public function name(): string
{
return 'get_order_status';
}
public function description(): string
{
return 'Get live delivery status of an order using order ID.';
}
public function parameters(): array
{
return [
'order_id' => 'string (
use Sentix\AiChatbot\Contracts\AiDriverInterface;
use Sentix\AiChatbot\Drivers\AiDriverFactory;
class MyCustomAiDriver implements AiDriverInterface
{
public function ask(string $prompt, array $chatHistory, string $systemPrompt, array $config): string
{
return "Response from MyCustomAiDriver";
}
public function askStream(string $prompt, array $chatHistory, string $systemPrompt, array $config, \Closure $onChunk): void
{
$onChunk("Streaming chunk response...");
}
public function testConnection(string $apiKey, string $model): bool
{
return true;
}
}
// Register in your AppServiceProvider:
AiDriverFactory::extend('my_custom_ai', MyCustomAiDriver::class);