PHP code example of jiannei / spark-ai

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

    

jiannei / spark-ai example snippets


use Jiannei\SparkAi\SparkAi;


$answer = SparkAi::getInstance()->withConfig([
    'url' => 'wss://spark-api.xf-yun.com/v3.1/chat',
    'app_id' => '',// 填入控制台中获取的 APPID
    'api_key' => '',// 填入控制台中获取的 APISecret
    'api_secret' => '',// 填入控制台中获取的 APIKey
])->chat()->create('你是谁?');

foreach ($answer as $item) {
    print_r($item);
}

use Jiannei\SparkAi\SparkAi;


$answer = SparkAi::getInstance()->withConfig([
    'url' => 'wss://spark-api.xf-yun.com/v3.1/chat',
    'app_id' => '',// 填入控制台中获取的 APPID
    'api_key' => '',// 填入控制台中获取的 APISecret
    'api_secret' => '',// 填入控制台中获取的 APIKey
])->chat()->answer('你是谁?');

print_r($answer);