PHP code example of topthink / think-ai
1. Go to this page and download the library: Download topthink/think-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/ */
topthink / think-ai example snippets
use think\ai\Client;
$client = new Client('YOUR_TOKEN');
//非流式输出
$result = $client->chat()->completions([
'model' => 'gpt-3.5-turbo',
'messages' => [
['role' => 'user', 'content' => 'Hello!'],
],
'stream'=>false,
]);
dump($result);
//流式输出
$result = $client->chat()->completions([
'model' => 'gpt-3.5-turbo',
'messages' => [
['role' => 'user', 'content' => 'Hello!'],
],
'stream'=>true,
]);
foreach($result as $chunk){
dump($chunk);
}
use think\ai\Client;
$client = new Client('YOUR_TOKEN');
//画图
$client->images()->generations($params);
//涂抹编辑
$client->images()->inpainting($params);
//图像扩展
$client->images()->outpainting($params);
use think\ai\Client;
$client = new Client('YOUR_TOKEN');
$result = $client->decision()->evaluate([
'model' => 'jev-latest',
'state' => 'Help! My payouts have been failing for 3 days.',
'questions' => [
'is_urgent' => [
'type' => 'noul',
'instructions' => 'Does this convey urgency?',
],
'department' => [
'type' => 'choice',
'instructions' => 'Which team should handle this?',
'criteria' => [
'billing' => 'Payments, invoicing, refunds',
'technical' => 'Bugs, outages, integrations',
],
],
],
]);
// $result['answers']['is_urgent']['noul'] => 0.95
// $result['answers']['department']['choice'] => 'billing'