use think\ai\Client;
$client = new Client('YOUR_TOKEN');
$result = $client->chat()->completions([
'model' => 'gpt-4',
'messages' => [['role' => 'user', 'content' => 'Hello!']],
'stream' => true,
]);
foreach ($result as $chunk) {
dump($chunk);
}
$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', 'criteria' => ['billing' => '…', 'technical' => '…']],
],
]);
// $result['answers']['is_urgent']['noul'] => 0.95
// $result['answers']['department']['choice'] => 'billing'
import { Client } from '@topthink/ai';
const client = new Client({ apiKey: 'sk-...' });
const stream = await client.chat.completions({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello!' }],
stream: true,
});
for await (const event of stream) {
process.stdout.write(event.delta.content);
}
const result = await client.image.generations({
model: 'dall-e-3',
prompt: 'A cat in a spacesuit',
size: '1024x1024',
});
console.log(result.images[0].url);