PHP code example of webbycrown / laraknow-ai

1. Go to this page and download the library: Download webbycrown/laraknow-ai 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/ */

    

webbycrown / laraknow-ai example snippets


'route_middleware' => ['web', 'auth'],

'route_name_prefix' => 'my-laraknow',

'rate_limiter_name' => '',

return [
    'instructions' => <<<'PROMPT'
        You are the AI assistant for this application.

        Application Overview:
        Describe what this application does.

        Assistant Responsibilities:
        Describe what users may ask the assistant to help with.

        Database Meaning:
        - Explain important table meanings and relationships.
        - Explain business statuses using real stored values.
        - Explain workflow rules, such as when to ask follow-up questions.

        Small Talk:
        - For greetings, thanks, and casual questions, reply naturally and briefly.

        Strict Rules:
        - Use only configured tools and allowed tables.
        - Do not invent records, counts, statuses, or database values.
        - For count/total questions, return only the verified aggregate unless details are requested.
    PROMPT,

    'auto_analyze_project' => false,

    'allowed_tables' => [
        'products',
        'orders',
        'customers',
    ],

    'blocked_columns' => [
        'password',
        'remember_token',
        'token',
        'api_token',
    ],

    'blocked_table_columns' => [
        'customers' => ['email', 'phone'],
    ],

    'route_prefix' => 'laraknow-ai',
    'route_name_prefix' => 'laraknow-ai',
    'rate_limiter_name' => 'laraknow-ai',
    'rate_limiter_max_attempts' => 30,
    'rate_limiter_decay_minutes' => 1,
    'route_middleware' => ['web', 'auth'],

    'ui' => [
        'theme' => 'auto',
        'brand' => [
            'name' => 'LaraKnow',
            'subtitle' => 'Always here to help',
        ],
    ],
];

'allowed_tables' => [
    'products',
    'brands',
    'orders',
],

'blocked_columns' => [
    'password',
    'remember_token',
    'api_token',
    'access_token',
    'refresh_token',
],

'blocked_table_columns' => [
    'users' => ['email', 'phone'],
    'orders' => ['internal_note'],
],

'ui' => [
    'theme' => 'light',
    'brand' => [
        'name' => 'Support Assistant',
        'subtitle' => 'Online',
    ],
    'colors' => [
        'primary' => '#2563eb',
        'user_bubble_bg' => '#2563eb',
    ],
],

'route_prefix' => 'laraknow-ai',
bash
php artisan vendor:publish --provider="Laravel\Ai\AiServiceProvider"
bash
php artisan vendor:publish --tag=laraknow-config
php artisan vendor:publish --tag=laraknow-assets
bash
php artisan migrate
bash
php artisan config:clear
php artisan route:clear
text
GET       /laraknow-ai
POST      /laraknow-ai/chat
GET       /laraknow-ai/conversations
POST      /laraknow-ai/conversations
GET       /laraknow-ai/conversations/{conversation}/messages
DELETE    /laraknow-ai/conversations/{conversation}
bash
php artisan route:list --path=laraknow-ai
text
config/laraknow.php
bash
php artisan route:list --path=laraknow-ai
php artisan route:clear
php artisan config:clear
bash
php artisan vendor:publish --provider="Laravel\Ai\AiServiceProvider"
php artisan migrate
bash
php artisan vendor:publish --tag=laraknow-assets --force
bash
php -l src/config/laraknow.php
vendor/bin/pint --dirty --format agent
php artisan test --compact
bash
php artisan route:list --path=laraknow-ai