PHP code example of jiannei / laravel-spark-ai

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


// config/services.php


return [
    // ...
    'xfyun' => [
        // 密钥信息,在开放平台-控制台中获取:https://console.xfyun.cn/services/cbm
        'url' => env('XFYUN_URL'),
        'app_id' => env('XFYUN_APP_ID'),
        'api_key' => env('XFYUN_API_KEY'),
        'api_secret' => env('XFYUN_API_SECRET'),
    ],
];

use Jiannei\LaravelSparkAi\Support\Facades\SparkAi;


$answer = SparkAi::chat()->create('你是谁?');

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

use Jiannei\LaravelSparkAi\Support\Facades\SparkAi;


$answer = SparkAi::chat()->answer('你是谁?');

print_r($answer);