dify
This commit is contained in:
1
dify/sdks/php-client/.gitignore
vendored
Normal file
1
dify/sdks/php-client/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/vendor
|
||||
95
dify/sdks/php-client/README.md
Normal file
95
dify/sdks/php-client/README.md
Normal file
@@ -0,0 +1,95 @@
|
||||
# Dify PHP SDK
|
||||
|
||||
This is the PHP SDK for the Dify API, which allows you to easily integrate Dify into your PHP applications.
|
||||
|
||||
## Requirements
|
||||
|
||||
- PHP 7.2 or later
|
||||
- Guzzle HTTP client library
|
||||
|
||||
## Usage
|
||||
|
||||
If you want to try the example, you can run `composer install` in this directory.
|
||||
|
||||
In exist project, copy the `dify-client.php` to you project, and merge the following to your `composer.json` file, then run `composer install && composer dump-autoload` to install. Guzzle does not require 7.9, other versions have not been tested, but you can try.
|
||||
|
||||
```json
|
||||
{
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "^7.9"
|
||||
},
|
||||
"autoload": {
|
||||
"files": ["path/to/dify-client.php"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
After installing the SDK, you can use it in your project like this:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
$apiKey = 'your-api-key-here';
|
||||
|
||||
$difyClient = new DifyClient($apiKey);
|
||||
|
||||
// Create a completion client
|
||||
$completionClient = new CompletionClient($apiKey);
|
||||
$response = $completionClient->create_completion_message(array("query" => "Who are you?"), "blocking", "user_id");
|
||||
|
||||
// Create a chat client
|
||||
$chatClient = new ChatClient($apiKey);
|
||||
$response = $chatClient->create_chat_message(array(), "Who are you?", "user_id", "blocking", $conversation_id);
|
||||
|
||||
$fileForVision = [
|
||||
[
|
||||
"type" => "image",
|
||||
"transfer_method" => "remote_url",
|
||||
"url" => "your_image_url"
|
||||
]
|
||||
];
|
||||
|
||||
// $fileForVision = [
|
||||
// [
|
||||
// "type" => "image",
|
||||
// "transfer_method" => "local_file",
|
||||
// "url" => "your_file_id"
|
||||
// ]
|
||||
// ];
|
||||
|
||||
// Create a completion client with vision model like gpt-4-vision
|
||||
$response = $completionClient->create_completion_message(array("query" => "Describe this image."), "blocking", "user_id", $fileForVision);
|
||||
|
||||
// Create a chat client with vision model like gpt-4-vision
|
||||
$response = $chatClient->create_chat_message(array(), "Describe this image.", "user_id", "blocking", $conversation_id, $fileForVision);
|
||||
|
||||
// File Upload
|
||||
$fileForUpload = [
|
||||
[
|
||||
'tmp_name' => '/path/to/file/filename.jpg',
|
||||
'name' => 'filename.jpg'
|
||||
]
|
||||
];
|
||||
$response = $difyClient->file_upload("user_id", $fileForUpload);
|
||||
$result = json_decode($response->getBody(), true);
|
||||
echo 'upload_file_id: ' . $result['id'];
|
||||
|
||||
// Fetch application parameters
|
||||
$response = $difyClient->get_application_parameters("user_id");
|
||||
|
||||
// Provide feedback for a message
|
||||
$response = $difyClient->message_feedback($message_id, $rating, "user_id");
|
||||
|
||||
// Other available methods:
|
||||
// - get_conversation_messages()
|
||||
// - get_conversations()
|
||||
// - rename_conversation()
|
||||
```
|
||||
|
||||
Replace 'your-api-key-here' with your actual Dify API key.
|
||||
|
||||
## License
|
||||
|
||||
This SDK is released under the MIT License.
|
||||
9
dify/sdks/php-client/composer.json
Normal file
9
dify/sdks/php-client/composer.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"require": {
|
||||
"php": ">=7.2",
|
||||
"guzzlehttp/guzzle": "^7.9"
|
||||
},
|
||||
"autoload": {
|
||||
"files": ["dify-client.php"]
|
||||
}
|
||||
}
|
||||
663
dify/sdks/php-client/composer.lock
generated
Normal file
663
dify/sdks/php-client/composer.lock
generated
Normal file
@@ -0,0 +1,663 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "7827c548fdcc7e87cb0ae341dd2c6b1b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
"version": "7.9.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/guzzle.git",
|
||||
"reference": "d281ed313b989f213357e3be1a179f02196ac99b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/d281ed313b989f213357e3be1a179f02196ac99b",
|
||||
"reference": "d281ed313b989f213357e3be1a179f02196ac99b",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"guzzlehttp/promises": "^1.5.3 || ^2.0.3",
|
||||
"guzzlehttp/psr7": "^2.7.0",
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"psr/http-client": "^1.0",
|
||||
"symfony/deprecation-contracts": "^2.2 || ^3.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/http-client-implementation": "1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"ext-curl": "*",
|
||||
"guzzle/client-integration-tests": "3.0.2",
|
||||
"php-http/message-factory": "^1.1",
|
||||
"phpunit/phpunit": "^8.5.39 || ^9.6.20",
|
||||
"psr/log": "^1.1 || ^2.0 || ^3.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-curl": "Required for CURL handler support",
|
||||
"ext-intl": "Required for Internationalized Domain Name (IDN) support",
|
||||
"psr/log": "Required for using the Log middleware"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
},
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
},
|
||||
{
|
||||
"name": "Jeremy Lindblom",
|
||||
"email": "jeremeamia@gmail.com",
|
||||
"homepage": "https://github.com/jeremeamia"
|
||||
},
|
||||
{
|
||||
"name": "George Mponos",
|
||||
"email": "gmponos@gmail.com",
|
||||
"homepage": "https://github.com/gmponos"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Nyholm",
|
||||
"email": "tobias.nyholm@gmail.com",
|
||||
"homepage": "https://github.com/Nyholm"
|
||||
},
|
||||
{
|
||||
"name": "Márk Sági-Kazár",
|
||||
"email": "mark.sagikazar@gmail.com",
|
||||
"homepage": "https://github.com/sagikazarmark"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Schultze",
|
||||
"email": "webmaster@tubo-world.de",
|
||||
"homepage": "https://github.com/Tobion"
|
||||
}
|
||||
],
|
||||
"description": "Guzzle is a PHP HTTP client library",
|
||||
"keywords": [
|
||||
"client",
|
||||
"curl",
|
||||
"framework",
|
||||
"http",
|
||||
"http client",
|
||||
"psr-18",
|
||||
"psr-7",
|
||||
"rest",
|
||||
"web service"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/guzzle/guzzle/issues",
|
||||
"source": "https://github.com/guzzle/guzzle/tree/7.9.2"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/GrahamCampbell",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/Nyholm",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-07-24T11:22:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/promises",
|
||||
"version": "2.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/promises.git",
|
||||
"reference": "7c69f28996b0a6920945dd20b3857e499d9ca96c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/promises/zipball/7c69f28996b0a6920945dd20b3857e499d9ca96c",
|
||||
"reference": "7c69f28996b0a6920945dd20b3857e499d9ca96c",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"phpunit/phpunit": "^8.5.39 || ^9.6.20"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\Promise\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
},
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Nyholm",
|
||||
"email": "tobias.nyholm@gmail.com",
|
||||
"homepage": "https://github.com/Nyholm"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Schultze",
|
||||
"email": "webmaster@tubo-world.de",
|
||||
"homepage": "https://github.com/Tobion"
|
||||
}
|
||||
],
|
||||
"description": "Guzzle promises library",
|
||||
"keywords": [
|
||||
"promise"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/guzzle/promises/issues",
|
||||
"source": "https://github.com/guzzle/promises/tree/2.2.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/GrahamCampbell",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/Nyholm",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-03-27T13:27:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/psr7",
|
||||
"version": "2.7.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/psr7.git",
|
||||
"reference": "c2270caaabe631b3b44c85f99e5a04bbb8060d16"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/c2270caaabe631b3b44c85f99e5a04bbb8060d16",
|
||||
"reference": "c2270caaabe631b3b44c85f99e5a04bbb8060d16",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"psr/http-factory": "^1.0",
|
||||
"psr/http-message": "^1.1 || ^2.0",
|
||||
"ralouphie/getallheaders": "^3.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/http-factory-implementation": "1.0",
|
||||
"psr/http-message-implementation": "1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"http-interop/http-factory-tests": "0.9.0",
|
||||
"phpunit/phpunit": "^8.5.39 || ^9.6.20"
|
||||
},
|
||||
"suggest": {
|
||||
"laminas/laminas-httphandlerrunner": "Emit PSR-7 responses"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\Psr7\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
},
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
},
|
||||
{
|
||||
"name": "George Mponos",
|
||||
"email": "gmponos@gmail.com",
|
||||
"homepage": "https://github.com/gmponos"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Nyholm",
|
||||
"email": "tobias.nyholm@gmail.com",
|
||||
"homepage": "https://github.com/Nyholm"
|
||||
},
|
||||
{
|
||||
"name": "Márk Sági-Kazár",
|
||||
"email": "mark.sagikazar@gmail.com",
|
||||
"homepage": "https://github.com/sagikazarmark"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Schultze",
|
||||
"email": "webmaster@tubo-world.de",
|
||||
"homepage": "https://github.com/Tobion"
|
||||
},
|
||||
{
|
||||
"name": "Márk Sági-Kazár",
|
||||
"email": "mark.sagikazar@gmail.com",
|
||||
"homepage": "https://sagikazarmark.hu"
|
||||
}
|
||||
],
|
||||
"description": "PSR-7 message implementation that also provides common utility methods",
|
||||
"keywords": [
|
||||
"http",
|
||||
"message",
|
||||
"psr-7",
|
||||
"request",
|
||||
"response",
|
||||
"stream",
|
||||
"uri",
|
||||
"url"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/guzzle/psr7/issues",
|
||||
"source": "https://github.com/guzzle/psr7/tree/2.7.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/GrahamCampbell",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/Nyholm",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-03-27T12:30:47+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-client",
|
||||
"version": "1.0.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/http-client.git",
|
||||
"reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90",
|
||||
"reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.0 || ^8.0",
|
||||
"psr/http-message": "^1.0 || ^2.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Http\\Client\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "https://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interface for HTTP clients",
|
||||
"homepage": "https://github.com/php-fig/http-client",
|
||||
"keywords": [
|
||||
"http",
|
||||
"http-client",
|
||||
"psr",
|
||||
"psr-18"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/php-fig/http-client"
|
||||
},
|
||||
"time": "2023-09-23T14:17:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-factory",
|
||||
"version": "1.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/http-factory.git",
|
||||
"reference": "e616d01114759c4c489f93b099585439f795fe35"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35",
|
||||
"reference": "e616d01114759c4c489f93b099585439f795fe35",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.0.0",
|
||||
"psr/http-message": "^1.0 || ^2.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Http\\Message\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "https://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interfaces for PSR-7 HTTP message factories",
|
||||
"keywords": [
|
||||
"factory",
|
||||
"http",
|
||||
"message",
|
||||
"psr",
|
||||
"psr-17",
|
||||
"psr-7",
|
||||
"request",
|
||||
"response"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/php-fig/http-factory/tree/1.0.2"
|
||||
},
|
||||
"time": "2023-04-10T20:10:41+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-message",
|
||||
"version": "2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/http-message.git",
|
||||
"reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71",
|
||||
"reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2 || ^8.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Http\\Message\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "https://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interface for HTTP messages",
|
||||
"homepage": "https://github.com/php-fig/http-message",
|
||||
"keywords": [
|
||||
"http",
|
||||
"http-message",
|
||||
"psr",
|
||||
"psr-7",
|
||||
"request",
|
||||
"response"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/php-fig/http-message/tree/2.0"
|
||||
},
|
||||
"time": "2023-04-04T09:54:51+00:00"
|
||||
},
|
||||
{
|
||||
"name": "ralouphie/getallheaders",
|
||||
"version": "3.0.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ralouphie/getallheaders.git",
|
||||
"reference": "120b605dfeb996808c31b6477290a714d356e822"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822",
|
||||
"reference": "120b605dfeb996808c31b6477290a714d356e822",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"php-coveralls/php-coveralls": "^2.1",
|
||||
"phpunit/phpunit": "^5 || ^6.5"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/getallheaders.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ralph Khattar",
|
||||
"email": "ralph.khattar@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "A polyfill for getallheaders.",
|
||||
"support": {
|
||||
"issues": "https://github.com/ralouphie/getallheaders/issues",
|
||||
"source": "https://github.com/ralouphie/getallheaders/tree/develop"
|
||||
},
|
||||
"time": "2019-03-08T08:55:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/deprecation-contracts",
|
||||
"version": "v3.5.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/deprecation-contracts.git",
|
||||
"reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6",
|
||||
"reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.1"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "3.5-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
"url": "https://github.com/symfony/contracts"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"function.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "A generic function and convention to trigger deprecation notices",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-09-25T14:20:29+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
206
dify/sdks/php-client/dify-client.php
Normal file
206
dify/sdks/php-client/dify-client.php
Normal file
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class DifyClient {
|
||||
protected $api_key;
|
||||
protected $base_url;
|
||||
protected $client;
|
||||
|
||||
public function __construct($api_key, $base_url = null) {
|
||||
$this->api_key = $api_key;
|
||||
$this->base_url = $base_url ?? 'https://api.dify.ai/v1/';
|
||||
$this->client = new Client([
|
||||
'base_uri' => $this->base_url,
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $this->api_key,
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
protected function send_request($method, $endpoint, $data = null, $params = null, $stream = false) {
|
||||
$options = [
|
||||
'json' => $data,
|
||||
'query' => $params,
|
||||
'stream' => $stream,
|
||||
];
|
||||
|
||||
$response = $this->client->request($method, $endpoint, $options);
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function message_feedback($message_id, $rating, $user) {
|
||||
$data = [
|
||||
'rating' => $rating,
|
||||
'user' => $user,
|
||||
];
|
||||
return $this->send_request('POST', "messages/{$message_id}/feedbacks", $data);
|
||||
}
|
||||
|
||||
public function get_application_parameters($user) {
|
||||
$params = ['user' => $user];
|
||||
return $this->send_request('GET', 'parameters', null, $params);
|
||||
}
|
||||
|
||||
public function file_upload($user, $files) {
|
||||
$data = ['user' => $user];
|
||||
$options = [
|
||||
'multipart' => $this->prepareMultipart($data, $files)
|
||||
];
|
||||
|
||||
return $this->client->request('POST', 'files/upload', $options);
|
||||
}
|
||||
|
||||
protected function prepareMultipart($data, $files) {
|
||||
$multipart = [];
|
||||
foreach ($data as $key => $value) {
|
||||
$multipart[] = [
|
||||
'name' => $key,
|
||||
'contents' => $value
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
$multipart[] = [
|
||||
'name' => 'file',
|
||||
'contents' => fopen($file['tmp_name'], 'r'),
|
||||
'filename' => $file['name']
|
||||
];
|
||||
}
|
||||
|
||||
return $multipart;
|
||||
}
|
||||
|
||||
|
||||
public function text_to_audio($text, $user, $streaming = false) {
|
||||
$data = [
|
||||
'text' => $text,
|
||||
'user' => $user,
|
||||
'streaming' => $streaming
|
||||
];
|
||||
|
||||
return $this->send_request('POST', 'text-to-audio', $data);
|
||||
}
|
||||
|
||||
public function get_meta($user) {
|
||||
$params = [
|
||||
'user' => $user
|
||||
];
|
||||
|
||||
return $this->send_request('GET', 'meta',null, $params);
|
||||
}
|
||||
}
|
||||
|
||||
class CompletionClient extends DifyClient {
|
||||
public function create_completion_message($inputs, $response_mode, $user, $files = null) {
|
||||
$data = [
|
||||
'inputs' => $inputs,
|
||||
'response_mode' => $response_mode,
|
||||
'user' => $user,
|
||||
'files' => $files,
|
||||
];
|
||||
return $this->send_request('POST', 'completion-messages', $data, null, $response_mode === 'streaming');
|
||||
}
|
||||
}
|
||||
|
||||
class ChatClient extends DifyClient {
|
||||
public function create_chat_message($inputs, $query, $user, $response_mode = 'blocking', $conversation_id = null, $files = null) {
|
||||
$data = [
|
||||
'inputs' => $inputs,
|
||||
'query' => $query,
|
||||
'user' => $user,
|
||||
'response_mode' => $response_mode,
|
||||
'files' => $files,
|
||||
];
|
||||
if ($conversation_id) {
|
||||
$data['conversation_id'] = $conversation_id;
|
||||
}
|
||||
|
||||
return $this->send_request('POST', 'chat-messages', $data, null, $response_mode === 'streaming');
|
||||
}
|
||||
|
||||
public function get_suggestions($message_id, $user) {
|
||||
$params = [
|
||||
'user' => $user
|
||||
];
|
||||
return $this->send_request('GET', "messages/{$message_id}/suggested", null, $params);
|
||||
}
|
||||
|
||||
public function stop_message($task_id, $user) {
|
||||
$data = ['user' => $user];
|
||||
return $this->send_request('POST', "chat-messages/{$task_id}/stop", $data);
|
||||
}
|
||||
|
||||
public function get_conversations($user, $first_id = null, $limit = null, $pinned = null) {
|
||||
$params = [
|
||||
'user' => $user,
|
||||
'first_id' => $first_id,
|
||||
'limit' => $limit,
|
||||
'pinned'=> $pinned,
|
||||
];
|
||||
return $this->send_request('GET', 'conversations', null, $params);
|
||||
}
|
||||
|
||||
public function get_conversation_messages($user, $conversation_id = null, $first_id = null, $limit = null) {
|
||||
$params = ['user' => $user];
|
||||
|
||||
if ($conversation_id) {
|
||||
$params['conversation_id'] = $conversation_id;
|
||||
}
|
||||
if ($first_id) {
|
||||
$params['first_id'] = $first_id;
|
||||
}
|
||||
if ($limit) {
|
||||
$params['limit'] = $limit;
|
||||
}
|
||||
|
||||
return $this->send_request('GET', 'messages', null, $params);
|
||||
}
|
||||
|
||||
public function rename_conversation($conversation_id, $name,$auto_generate, $user) {
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'user' => $user,
|
||||
'auto_generate' => $auto_generate
|
||||
];
|
||||
return $this->send_request('PATCH', "conversations/{$conversation_id}", $data);
|
||||
}
|
||||
|
||||
public function delete_conversation($conversation_id, $user) {
|
||||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
return $this->send_request('DELETE', "conversations/{$conversation_id}", $data);
|
||||
}
|
||||
|
||||
public function audio_to_text($audio_file, $user) {
|
||||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
$options = [
|
||||
'multipart' => $this->prepareMultipart($data, $audio_file)
|
||||
];
|
||||
return $this->client->request('POST', 'audio-to-text', $options);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class WorkflowClient extends DifyClient{
|
||||
public function run($inputs, $response_mode, $user) {
|
||||
$data = [
|
||||
'inputs' => $inputs,
|
||||
'response_mode' => $response_mode,
|
||||
'user' => $user,
|
||||
];
|
||||
return $this->send_request('POST', 'workflows/run', $data);
|
||||
}
|
||||
|
||||
public function stop($task_id, $user) {
|
||||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
return $this->send_request('POST', "workflows/tasks/{$task_id}/stop",$data);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user