|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace OpenAI\Responses\Responses\Streaming; |
| 6 | + |
| 7 | +use OpenAI\Contracts\ResponseContract; |
| 8 | +use OpenAI\Contracts\ResponseHasMetaInformationContract; |
| 9 | +use OpenAI\Responses\Concerns\ArrayAccessible; |
| 10 | +use OpenAI\Responses\Concerns\HasMetaInformation; |
| 11 | +use OpenAI\Responses\Meta\MetaInformation; |
| 12 | +use OpenAI\Testing\Responses\Concerns\Fakeable; |
| 13 | + |
| 14 | +/** |
| 15 | + * @phpstan-type ReasoningTextDeltaType array{content_index: int, delta: string, item_id: string, output_index: int, sequence_number: int} |
| 16 | + * |
| 17 | + * @implements ResponseContract<ReasoningTextDeltaType> |
| 18 | + */ |
| 19 | +final class ReasoningTextDelta implements ResponseContract, ResponseHasMetaInformationContract |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @use ArrayAccessible<ReasoningTextDeltaType> |
| 23 | + */ |
| 24 | + use ArrayAccessible; |
| 25 | + |
| 26 | + use Fakeable; |
| 27 | + use HasMetaInformation; |
| 28 | + |
| 29 | + private function __construct( |
| 30 | + public readonly int $contentIndex, |
| 31 | + public readonly string $delta, |
| 32 | + public readonly string $itemId, |
| 33 | + public readonly int $outputIndex, |
| 34 | + public readonly int $sequenceNumber, |
| 35 | + private readonly MetaInformation $meta, |
| 36 | + ) {} |
| 37 | + |
| 38 | + /** |
| 39 | + * @param ReasoningTextDeltaType $attributes |
| 40 | + */ |
| 41 | + public static function from(array $attributes, MetaInformation $meta): self |
| 42 | + { |
| 43 | + return new self( |
| 44 | + contentIndex: $attributes['content_index'], |
| 45 | + delta: $attributes['delta'], |
| 46 | + itemId: $attributes['item_id'], |
| 47 | + outputIndex: $attributes['output_index'], |
| 48 | + sequenceNumber: $attributes['sequence_number'], |
| 49 | + meta: $meta, |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * {@inheritDoc} |
| 55 | + */ |
| 56 | + public function toArray(): array |
| 57 | + { |
| 58 | + return [ |
| 59 | + 'content_index' => $this->contentIndex, |
| 60 | + 'delta' => $this->delta, |
| 61 | + 'item_id' => $this->itemId, |
| 62 | + 'output_index' => $this->outputIndex, |
| 63 | + 'sequence_number' => $this->sequenceNumber, |
| 64 | + ]; |
| 65 | + } |
| 66 | +} |
0 commit comments