File tree Expand file tree Collapse file tree 1 file changed +3
-10
lines changed Expand file tree Collapse file tree 1 file changed +3
-10
lines changed Original file line number Diff line number Diff line change @@ -364,27 +364,20 @@ $stream = $client->chat()->createStreamed([
364
364
['role' => 'user', 'content' => 'Hello!'],
365
365
],
366
366
'stream_options'=>[
367
- 'include_usage'=> true
367
+ 'include_usage' => true,
368
368
]
369
369
]);
370
370
371
371
foreach($stream as $response){
372
- if($response->usage){
372
+ if($response->usage !== null ){
373
373
$response->usage->promptTokens; // 9,
374
374
$response->usage->completionTokens; // 12,
375
375
$response->usage->totalTokens; // 21
376
- }else{
377
- $response->choices[0]->toArray();
378
376
}
379
-
380
377
}
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
- // ...
385
378
```
386
379
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.
388
381
389
382
### ` Audio ` Resource
390
383
You can’t perform that action at this time.
0 commit comments