PHP code example of assistant-engine / open-functions-github
1. Go to this page and download the library: Download assistant-engine/open-functions-github 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-github example snippets
use AssistantEngine\OpenFunctions\Github\GithubOpenFunction;
use AssistantEngine\OpenFunctions\Github\Models\Parameters;
use OpenAI;
// Set up parameters for GitHub authentication
$parameters = new Parameters();
$parameters->token = env('GITHUB_TOKEN');
$parameters->owner = env('GITHUB_OWNER');
$parameters->repository = env('GITHUB_REPOSITORY');
// Initialize the GitHub Open Function
$githubFunction = new GithubOpenFunction($parameters);
// Generate function definitions (for tool integration with an LLM)
$functionDefinitions = $githubFunction->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, $githubFunction);
}
function processToolCalls($toolCalls, AbstractOpenFunction $githubFunction)
{
$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 = $githubFunction->callMethod($functionName, $functionArgs);
}
return $result;
}
// inside config/filament-assistant.php
// Tools configuration: each tool is identified by a key.
'tools' => [
'github' => [
'namespace' => 'github',
'description' => 'This is a demo github repository.',
'tool' => function () {
$parameter = new \AssistantEngine\OpenFunctions\Github\Models\Parameters();
$parameter->token = env('GITHUB_TOKEN');
$parameter->owner = env('GITHUB_OWNER');
$parameter->repository = env('GITHUB_REPOSITORY');
return new \AssistantEngine\OpenFunctions\Github\GithubOpenFunction($parameter);
},
]
]
// ...