Skip to content

Commit 3e6c593

Browse files
fix(OpenAI): correct missing sequenceNumbers in streaming (#764)
1 parent 12e3513 commit 3e6c593

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/Responses/Responses/Streaming/ContentPart.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* @phpstan-import-type OutputTextType from OutputMessageContentOutputText
1818
* @phpstan-import-type ContentRefusalType from OutputMessageContentRefusal
1919
*
20-
* @phpstan-type ContentPartType array{type: string, content_index: int, item_id: string, output_index: int, part: OutputTextType|ContentRefusalType}
20+
* @phpstan-type ContentPartType array{type: string, content_index: int, item_id: string, output_index: int, sequence_number: int, part: OutputTextType|ContentRefusalType}
2121
*
2222
* @implements ResponseContract<ContentPartType>
2323
*/
@@ -36,6 +36,7 @@ private function __construct(
3636
public readonly int $contentIndex,
3737
public readonly string $itemId,
3838
public readonly int $outputIndex,
39+
public readonly int $sequenceNumber,
3940
public readonly OutputMessageContentOutputText|OutputMessageContentRefusal $part,
4041
private readonly MetaInformation $meta,
4142
) {}
@@ -55,6 +56,7 @@ public static function from(array $attributes, MetaInformation $meta): self
5556
contentIndex: $attributes['content_index'],
5657
itemId: $attributes['item_id'],
5758
outputIndex: $attributes['output_index'],
59+
sequenceNumber: $attributes['sequence_number'],
5860
part: $part,
5961
meta: $meta,
6062
);
@@ -70,6 +72,7 @@ public function toArray(): array
7072
'content_index' => $this->contentIndex,
7173
'item_id' => $this->itemId,
7274
'output_index' => $this->outputIndex,
75+
'sequence_number' => $this->sequenceNumber,
7376
'part' => $this->part->toArray(),
7477
];
7578
}

src/Responses/Responses/Streaming/OutputItem.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* @phpstan-import-type OutputMcpCallType from OutputMcpCall
3636
* @phpstan-import-type OutputCodeInterpreterToolCallType from OutputCodeInterpreterToolCall
3737
*
38-
* @phpstan-type OutputItemType array{type: string, output_index: int, item: OutputCodeInterpreterToolCallType|OutputComputerToolCallType|OutputFileSearchToolCallType|OutputFunctionToolCallType|OutputMessageType|OutputReasoningType|OutputWebSearchToolCallType|OutputMcpListToolsType|OutputMcpApprovalRequestType|OutputMcpCallType|OutputImageGenerationToolCallType}
38+
* @phpstan-type OutputItemType array{type: string, output_index: int, sequence_number: int, item: OutputCodeInterpreterToolCallType|OutputComputerToolCallType|OutputFileSearchToolCallType|OutputFunctionToolCallType|OutputMessageType|OutputReasoningType|OutputWebSearchToolCallType|OutputMcpListToolsType|OutputMcpApprovalRequestType|OutputMcpCallType|OutputImageGenerationToolCallType}
3939
*
4040
* @implements ResponseContract<OutputItemType>
4141
*/
@@ -52,6 +52,7 @@ final class OutputItem implements ResponseContract, ResponseHasMetaInformationCo
5252
private function __construct(
5353
public readonly string $type,
5454
public readonly int $outputIndex,
55+
public readonly int $sequenceNumber,
5556
public readonly OutputMessage|OutputCodeInterpreterToolCall|OutputFileSearchToolCall|OutputFunctionToolCall|OutputWebSearchToolCall|OutputComputerToolCall|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall $item,
5657
private readonly MetaInformation $meta,
5758
) {}
@@ -78,6 +79,7 @@ public static function from(array $attributes, MetaInformation $meta): self
7879
return new self(
7980
type: $attributes['type'],
8081
outputIndex: $attributes['output_index'],
82+
sequenceNumber: $attributes['sequence_number'],
8183
item: $item,
8284
meta: $meta,
8385
);
@@ -91,6 +93,7 @@ public function toArray(): array
9193
return [
9294
'type' => $this->type,
9395
'output_index' => $this->outputIndex,
96+
'sequence_number' => $this->sequenceNumber,
9497
'item' => $this->item->toArray(),
9598
];
9699
}

src/Responses/Responses/Streaming/OutputTextDone.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use OpenAI\Testing\Responses\Concerns\Fakeable;
1313

1414
/**
15-
* @phpstan-type OutputTextDoneType array{type: string, content_index: int, item_id: string, output_index: int, text: string}
15+
* @phpstan-type OutputTextDoneType array{type: string, content_index: int, item_id: string, output_index: int, sequence_number: int, text: string}
1616
*
1717
* @implements ResponseContract<OutputTextDoneType>
1818
*/
@@ -31,6 +31,7 @@ private function __construct(
3131
public readonly int $contentIndex,
3232
public readonly string $itemId,
3333
public readonly int $outputIndex,
34+
public readonly int $sequenceNumber,
3435
public readonly string $text,
3536
private readonly MetaInformation $meta,
3637
) {}
@@ -45,6 +46,7 @@ public static function from(array $attributes, MetaInformation $meta): self
4546
contentIndex: $attributes['content_index'],
4647
itemId: $attributes['item_id'],
4748
outputIndex: $attributes['output_index'],
49+
sequenceNumber: $attributes['sequence_number'],
4850
text: $attributes['text'],
4951
meta: $meta,
5052
);
@@ -60,6 +62,7 @@ public function toArray(): array
6062
'content_index' => $this->contentIndex,
6163
'item_id' => $this->itemId,
6264
'output_index' => $this->outputIndex,
65+
'sequence_number' => $this->sequenceNumber,
6366
'text' => $this->text,
6467
];
6568
}

0 commit comments

Comments
 (0)