PHP code example of matgro / dify-sdk

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

    

matgro / dify-sdk example snippets


use GuzzleHttp\Client;
use Matgro\Dify\DifyClient;

$client = new DifyClient(
    new Client(),
    getenv('DIFY_BASE_URL'),
    getenv('DIFY_API_KEY')
);

$dataset = $client->createDataset(
    'Documentos Secretaría',
    'Material interno'
);

$client->updateDataset($dataset->id(), 'Documentos institucionales');
$datasets = $client->listDatasets();
$documents = $client->listDocuments($dataset->id());
$upload = $client->uploadDocument($dataset->id(), '/private/path/source.pdf');
$status = $client->getIndexingStatus($dataset->id(), $upload->batch());
$client->updateDocumentByText($dataset->id(), $upload->document()->id(), 'Documento actualizado', 'Contenido actualizado');
$client->deleteDocument($dataset->id(), $upload->document()->id());
$client->deleteDataset($dataset->id());