Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

README.md 2.3KB

il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
il y a 2 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Dify PHP SDK
  2. This is the PHP SDK for the Dify API, which allows you to easily integrate Dify into your PHP applications.
  3. ## Requirements
  4. - PHP 7.2 or later
  5. - Guzzle HTTP client library
  6. ## Usage
  7. After installing the SDK, you can use it in your project like this:
  8. ```php
  9. <?php
  10. require 'vendor/autoload.php';
  11. use YourVendorName\DifyPHP\DifyClient;
  12. use YourVendorName\DifyPHP\CompletionClient;
  13. use YourVendorName\DifyPHP\ChatClient;
  14. $apiKey = 'your-api-key-here';
  15. $difyClient = new DifyClient($apiKey);
  16. // Create a completion client
  17. $completionClient = new CompletionClient($apiKey);
  18. $response = $completionClient->create_completion_message(array("query" => "Who are you?"), "blocking", "user_id");
  19. // Create a chat client
  20. $chatClient = new ChatClient($apiKey);
  21. $response = $chatClient->create_chat_message(array(), "Who are you?", "user_id", "blocking", $conversation_id);
  22. $fileForVision = [
  23. [
  24. "type" => "image",
  25. "transfer_method" => "remote_url",
  26. "url" => "your_image_url"
  27. ]
  28. ];
  29. // $fileForVision = [
  30. // [
  31. // "type" => "image",
  32. // "transfer_method" => "local_file",
  33. // "url" => "your_file_id"
  34. // ]
  35. // ];
  36. // Create a completion client with vision model like gpt-4-vision
  37. $response = $completionClient->create_completion_message(array("query" => "Describe this image."), "blocking", "user_id", $fileForVision);
  38. // Create a chat client with vision model like gpt-4-vision
  39. $response = $chatClient->create_chat_message(array(), "Describe this image.", "user_id", "blocking", $conversation_id, $fileForVision);
  40. // File Upload
  41. $fileForUpload = [
  42. [
  43. 'tmp_name' => '/path/to/file/filename.jpg',
  44. 'name' => 'filename.jpg'
  45. ]
  46. ];
  47. $response = $difyClient->file_upload("user_id", $fileForUpload);
  48. $result = json_decode($response->getBody(), true);
  49. echo 'upload_file_id: ' . $result['id'];
  50. // Fetch application parameters
  51. $response = $difyClient->get_application_parameters("user_id");
  52. // Provide feedback for a message
  53. $response = $difyClient->message_feedback($message_id, $rating, "user_id");
  54. // Other available methods:
  55. // - get_conversation_messages()
  56. // - get_conversations()
  57. // - rename_conversation()
  58. ```
  59. Replace 'your-api-key-here' with your actual Dify API key.
  60. ## License
  61. This SDK is released under the MIT License.