PHP code example of assistant-engine / php-sdk

1. Go to this page and download the library: Download assistant-engine/php-sdk 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/ */

    

assistant-engine / php-sdk example snippets


use AssistantEngine\SDK\AssistantEngine;

$assistantEngine = new AssistantEngine(
    'https://api.assistant-engine.com/v1/',     // API URL
    'your_api_token',                           // API Token
    'your_openai_token',                        // OpenAI Token
);

use AssistantEngine\SDK\Models\Options\ConversationOption;

$options = new ConversationOption('assistant_key', [
    'user_id' => 'user123',
    'title' => 'New Conversation',
    'context' => ['key' => 'value'],
    'additional_data' => ['theme' => 'dark']
]);

$conversation = $assistantEngine->findOrCreateConversation($options);

$conversation = $assistantEngine->getConversation($conversationId);

use AssistantEngine\SDK\Models\Options\ConversationUpdateOption;

$updateOptions = new ConversationUpdateOption();
$updateOptions->title = 'Updated Title';
$updateOptions->context = ['key' => 'value'];
$updateOptions->additional_data = ['theme' => 'dark'];

$updatedConversation = $assistantEngine->updateConversation($conversationId, $updateOptions);

$response = $assistantEngine->deactivateConversation($conversationId);

use AssistantEngine\SDK\Models\Options\MessageOption;

$messageOption = new MessageOption();
$messageOption->message = 'Hello, Assistant!';

$response = $assistantEngine->createMessage($conversation->id, $messageOption);

use AssistantEngine\SDK\Models\Options\TaskRunOption;

$taskRunOption = new TaskRunOption(['key' => 'value']);
$taskRunResponse = $assistantEngine->initiateTaskRun('task_key', $taskRunOption);

$taskOutput = $assistantEngine->pollTaskRunUntilComplete('task_key', $runId);

$taskOutput = $assistantEngine->initiateTaskRunAndPoll('task_key', $taskRunOption);

$taskOutput = $assistantEngine->getTaskRun('task_key', $runId);
if (!$taskOutput->is_running) {
    echo "Task completed with output: " . $taskOutput->output;
}
bash
composer