simonetoo/dify-php

这是 Dify API 的 PHP SDK。

dev-master 2024-09-07 12:11 UTC

This package is auto-updated.

Last update: 2024-09-07 12:11:47 UTC


README

这是 Dify API 的 PHP SDK,它允许您轻松地将 Dify 集成到您的 PHP 应用程序中。

要求

  • PHP: ^7.2|^8.0
  • guzzlehttp/guzzle: ^7.8
  • ext-json: *

用法

<?php

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();
// ....
// 

将 'your-api-key-here' 替换为您的实际 Dify API 密钥。

许可证

此 SDK 在 MIT 许可证下发布。