Skip to content

Commit 127f96d

Browse files
committed
sanitize docs
1 parent e5940b1 commit 127f96d

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

README.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -364,27 +364,20 @@ $stream = $client->chat()->createStreamed([
364364
['role' => 'user', 'content' => 'Hello!'],
365365
],
366366
'stream_options'=>[
367-
'include_usage'=>true
367+
'include_usage' => true,
368368
]
369369
]);
370370

371371
foreach($stream as $response){
372-
if($response->usage){
372+
if($response->usage !== null){
373373
$response->usage->promptTokens; // 9,
374374
$response->usage->completionTokens; // 12,
375375
$response->usage->totalTokens; // 21
376-
}else{
377-
$response->choices[0]->toArray();
378376
}
379-
380377
}
381-
// 1. iteration => ['index' => 0, 'delta' => ['role' => 'assistant'], 'finish_reason' => null]
382-
// 2. iteration => ['index' => 0, 'delta' => ['content' => 'Hello'], 'finish_reason' => null]
383-
// 3. iteration => ['index' => 0, 'delta' => ['content' => '!'], 'finish_reason' => null]
384-
// ...
385378
```
386379

387-
When present, it contains a null value except for the last chunk which contains the token usage statistics for the entire request.
380+
`usage` is always `null` except for the last chunk which contains the token usage statistics for the entire request.
388381

389382
### `Audio` Resource
390383

0 commit comments

Comments
 (0)