Skip to content

Commit

Permalink
Add usage on streamed chat response (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
punyflash authored May 27, 2024
1 parent 7ec1207 commit 769be96
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Responses/Chat/CreateStreamedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private function __construct(
public readonly int $created,
public readonly string $model,
public readonly array $choices,
public readonly ?CreateResponseUsage $usage,
) {
}

Expand All @@ -49,6 +50,7 @@ public static function from(array $attributes): self
$attributes['created'],
$attributes['model'],
$choices,
isset($attributes['usage']) ? CreateResponseUsage::from($attributes['usage']) : null,

Check failure on line 53 in src/Responses/Chat/CreateStreamedResponse.php

View workflow job for this annotation

GitHub Actions / Formats P8.1 - ubuntu-latest - prefer-lowest

Offset 'usage' on array{id: string, object: string, created: int, model: string, choices: array<int, array{index: int, delta: array{role?: string, content?: string}, finish_reason: string|null}>} in isset() does not exist.

Check failure on line 53 in src/Responses/Chat/CreateStreamedResponse.php

View workflow job for this annotation

GitHub Actions / Formats P8.1 - ubuntu-latest - prefer-stable

Offset 'usage' on array{id: string, object: string, created: int, model: string, choices: array<int, array{index: int, delta: array{role?: string, content?: string}, finish_reason: string|null}>} in isset() does not exist.
);
}

Expand All @@ -66,6 +68,7 @@ public function toArray(): array
static fn (CreateStreamedResponseChoice $result): array => $result->toArray(),
$this->choices,
),
'usage' => $this->usage?->toArray() ?? null,
];
}
}

0 comments on commit 769be96

Please sign in to comment.