PHP code example of halilcosdu / laravel-chatbot

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

    

halilcosdu / laravel-chatbot example snippets


return [
    'model' => env('OPENAI_MODEL', 'gpt-5.4-mini'),
    'instructions' => env('OPENAI_INSTRUCTIONS'),
    'prompt_id' => env('OPENAI_PROMPT_ID'),  // optional; overrides model+instructions
    'api_key' => env('OPENAI_API_KEY'),
    'organization' => env('OPENAI_ORGANIZATION'),
    'request_timeout' => env('OPENAI_TIMEOUT'),
    'models' => [
        'thread' => env('CHATBOT_THREAD_MODEL', \HalilCosdu\ChatBot\Models\Thread::class),
        'thread_messages' => env('CHATBOT_THREAD_MESSAGE_MODEL', \HalilCosdu\ChatBot\Models\ThreadMessage::class),
    ],
];

use HalilCosdu\ChatBot\Facades\ChatBot;

$thread = ChatBot::createThread('Why is the sky blue?', ownerId: auth()->id());
// Creates a Conversation, runs a Response against it, and stores the user
// message + assistant reply as ThreadMessage rows.

$assistantMessage = ChatBot::updateThread('What about at sunset?', $thread->id);

ChatBot::listThreads(ownerId: auth()->id(), search: 'sky');
ChatBot::thread($thread->id);
ChatBot::deleteThread($thread->id);

ChatBot::createConversationAsRaw();
ChatBot::conversationAsRaw($conversationId);
ChatBot::deleteConversationAsRaw($conversationId);
ChatBot::listConversationItemsAsRaw($conversationId);
ChatBot::createResponseAsRaw(['model' => 'gpt-5.4-mini', 'input' => [...], 'conversation' => $conversationId]);
ChatBot::responseAsRaw($responseId);
bash
php artisan vendor:publish --tag="chatbot-config"
php artisan vendor:publish --tag="chatbot-migrations"
php artisan migrate