PHP code example of assistant-engine / open-functions-trello

1. Go to this page and download the library: Download assistant-engine/open-functions-trello 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 / open-functions-trello example snippets




use AssistantEngine\OpenFunctions\Trello\TrelloOpenFunction;
use AssistantEngine\OpenFunctions\Trello\Models\Parameters;
use OpenAI;

// Set up parameters for Trello authentication
$parameters = new Parameters();
$parameters->token = env('TRELLO_API_KEY');      // Your Trello API key
$parameters->tokenSecret = env('TRELLO_TOKEN');    // Your Trello token
$parameters->boardId = env('TRELLO_BOARD_ID');     // The ID of the Trello board

// Initialize the Trello Open Function
$trelloFunction = new TrelloOpenFunction($parameters);

// Generate function definitions (for tool integration with an LLM)
$functionDefinitions = $trelloFunction->generateFunctionDefinitions();

$client = OpenAI::client(env('OPENAI_TOKEN'));

$result = $client->chat()->create([
    'model'   => 'gpt-4o',
    'messages'=> [],
    'tools'   => $functionDefinitions
]);

$choice = $result->choices[0];

if ($choice->finishReason === 'tool_calls') {
    $toolCalls = processToolCalls($choice->message->toolCalls, $trelloFunction);
} 

function processToolCalls($toolCalls, $trelloFunction)
{
    $result = [];

    foreach ($toolCalls as $toolCall) {
        // Extract the function name (already namespaced) and arguments
        $functionName = $toolCall->function->name;
        $functionArgs = json_decode($toolCall->function->arguments, true);

        $response = $trelloFunction->callMethod($functionName, $functionArgs);
        $result[] = $response;
    }

    return $result;
}

// inside config/filament-assistant.php

// Tools configuration: each tool is identified by a key.
'tools' => [
    'trello' => [
        'namespace'   => 'trello',
        'description' => 'This tool allows you to manage your Trello boards, lists, and cards.',
        'tool'        => function () {
            $parameter = new \AssistantEngine\OpenFunctions\Trello\Models\Parameters();
            $parameter->token = env('TRELLO_API_KEY');
            $parameter->tokenSecret = env('TRELLO_TOKEN');
            $parameter->boardId = env('TRELLO_BOARD_ID');

            return new \AssistantEngine\OpenFunctions\Trello\TrelloOpenFunction($parameter);
        },
    ]
]