PHP code example of icetalker / dashscope-php

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

    

icetalker / dashscope-php example snippets


use Dashscope\Dashscope;

$api_key = 'your-dashscope-api-key';

$parameters = [
    'api_key' => $api_key,
    'prompt' => 'Hello World!',
];

$response = Dashscope::imageSynthesis($parameters)->call();

echo $response->getBody()->getContents();

$api_key = 'your-dashscope-api-key';

$task_id = '******';

$response = Dashscope::fetchTask($task_id, $api_key);

echo $response->getBody()->getContents();


    $parameters = [
        'api_key'=>'your-dashscope-api-key',
        //... 
    ];

    Dashscope::imageSynthesis($parameters)//调用模型
        ->call();


$parameters = [
    'api_key' => $api_key, // api_key 为必填项
    'prompt' => 'A cat sitting on a park bench', // 其他必填项及可选参数请参考 Dashscope 文档
    //...
];

use GuzzleHttp\Client;

$client = new Client([
    //options ...
    'timeout' => 10,
    'proxy' => 'tcp://127.0.0.1:1080', // 使用代理
]);

$response = Dashscope::imageSynthesis($parameters)->withHttpClient($client)->call();

echo $response->getBody()->getContents();
bash
composer