PHP code example of edrisaturay / filament-ai-chat-agent
1. Go to this page and download the library: Download edrisaturay/filament-ai-chat-agent 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/ */
edrisaturay / filament-ai-chat-agent example snippets
use EdrisaTuray\FilamentAiChatAgent\AiChatAgentPlugin;
public function panel(Panel $panel): Panel
{
return $panel
...
->plugin(
AiChatAgentPlugin::make()
)
...
}
use App\GPT\Functions\YourCustomGPTFunction;
use EdrisaTuray\FilamentAiChatAgent\AiChatAgentPlugin;
...
public function panel(Panel $panel): Panel
{
return $panel
...
->plugin(
AiChatAgentPlugin::make()
->defaultPanelWidth('400px') // default 350px
->botName('GPT Assistant')
->model('gpt-4o')
->buttonText('Ask ChatGPT')
->buttonIcon('heroicon-m-sparkles')
// System instructions for the GPT
->systemMessage('Act nice and help')
// Array of GPTFunctions the GPT can use
->functions([
new YourCustomGPTFunction(),
])
// Default start message, set to false to not show a message
->startMessage('Hello sir! How can I help you today?')
->pageWatcherEnabled(true)
)
...
}
class GetUserDataFunction
{
public function toArray(): array
{
return [
'name' => 'get_user_data',
'description' => 'Get user information by ID',
'parameters' => [
'type' => 'object',
'properties' => [
'user_id' => [
'type' => 'integer',
'description' => 'The user ID',
],
],
'
public function panel(Panel $panel): Panel
{
return $panel
->plugin(
AiChatAgentPlugin::make()
->pageWatcherEnabled(true) // Enable page watcher
->pageWatcherSelector('.custom-content') // Specify the selector
->pageWatcherMessage(
"This is the plain text the user can see on the page, use it as additional context for the previous message:\n\n"
) // Optional custom message for ChatGPT
);
}
public function panel(Panel $panel): Panel
{
return $panel
->plugin(
AiChatAgentPlugin::make()
->pageWatcherEnabled(fn () => auth()->user()->settings['enable_page_watcher'] ?? false) // User opt-in
->pageWatcherSelector('.fi-page')
);
}