PHP code example of excelle-insights / ai-assistant
1. Go to this page and download the library: Download excelle-insights/ai-assistant 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/ */
excelle-insights / ai-assistant example snippets
if (class_exists(\ExcelleInsights\AiAssistant\Facade\AiAssistantManager::class)) {
(new \ExcelleInsights\AiAssistant\Services\AiAssistantService())->onInboundMessages($results);
}
// api/src/Services/MaintainaContextProvider.php
use ExcelleInsights\AiAssistant\Contracts\SystemContextProviderInterface;
class MaintainaContextProvider implements SystemContextProviderInterface {
public function getCompanyContext(int $companyId): array {
$db = \ExcelleCore\Core\Database::getInstance()->getConnection();
$row = $db->query("SELECT name FROM companies WHERE id=$companyId")->fetch();
return ['name'=>$row['name'], 'services'=> $db->query("SELECT name FROM service_types WHERE company_id=$companyId")->fetchAll(PDO::FETCH_COLUMN)];
}
public function getCustomerContext(int $conversationId): array { /* last 3 service_records like AiController.php:604 */ return []; }
public function getCompanyKnowledge(int $companyId, string $query, int $k=5): array { /* FTS over ai_assistant_knowledge */ return []; }
public function canAutoReply(int $conversationId): bool { return true; } // business hours, opt-in
}
use ExcelleInsights\AiAssistant\Support\LlmFactory;
$ai = new \ExcelleInsights\AiAssistant\Facade\AiAssistantManager(
pdo: \ExcelleCore\Core\Database::getInstance()->getConnection(),
contextProvider: new MaintainaContextProvider(),
openAI: LlmFactory::make() // or new \ExcelleCore\AI\OpenAIClient() to reuse host's
);
// Host side, e.g. api/src/Services/AppBookingHandler.php
use ExcelleInsights\AiAssistant\Contracts\BookingHandlerInterface;
use ExcelleInsights\AiAssistant\Support\BookingIntent;
class AppBookingHandler implements BookingHandlerInterface {
public function handleBookingIntent(BookingIntent $intent): void {
// $intent->companyId, ->contactPhone, ->contactName, ->service,
// ->preferredDate (Y-m-d or null), ->confidence, ->messageBody, ->aiReply
// De-dupe + insert into YOUR bookings table + notify staff here.
}
}
$ai = new \ExcelleInsights\AiAssistant\Services\AiAssistantService(
openAI: $llm,
bookingHandler: new AppBookingHandler(), // or:
);
$ai->setBookingHandler(new AppBookingHandler());
$ai->onInboundMessages($results);
use ExcelleInsights\AiAssistant\Services\KnowledgeService;
use ExcelleInsights\AiAssistant\Services\TrainingService;
$knowledge = new KnowledgeService($pdo, LlmFactory::make());
$training = new TrainingService($pdo, $knowledge);
$training->ingest($companyId, "Return Policy", "30 days...", "manual");