PHP code example of simonetoo / dify-php

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

    

simonetoo / dify-php example snippets




use \Simoneto\Dify\Dify;

$apiKey = 'your-api-key-here';

// Set the base uri.

Dify::setBaseUri('https://dify.xx.com');

// Create a http client.
$client = Dify::create();

// Create a http client with api key.
$client = Dify::createWithApiKey($apiKey);

// Create a chat app.
$chat = Dify::chat($apiKey);

// Create a completion app.
$completion = Dify::completion($apiKey);

// Get the dify app information.
$response = $chat->parameters();

// Get the app meta information.
$response = $chat->meta('user-id');

// Send a request to the chat application.
$response = $chat->send('user-id', 'Hello World!');

// Send a request to the chat application with enable streaming mode.
$streamResponse = $chat->stream('user-id','hello World!');

// Provide feedback for a message
$response = $chat->messageFeedback('user-id','message-id','like or dislike');

// Other methods:
// $chat->suggested();
// $chat->conversations();
// $chat->messages();
// ....
//