Skip to content

Commit 4d70ddd

Browse files
iBotPeachestrandbert37
authored andcommitted
fix(Azure): support azure model.list (openai-php#599)
1 parent a4142fa commit 4d70ddd

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

src/Responses/Models/ListResponse.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
use OpenAI\Testing\Responses\Concerns\Fakeable;
1313

1414
/**
15-
* @implements ResponseContract<array{object: string, data: array<int, array{id: string, object: string, created: ?int, owned_by: string}>}>
15+
* @implements ResponseContract<array{object: string, data: array<int, array{id: string, object: string, created: ?int, created_at?: ?int, owned_by: ?string}>}>
1616
*/
1717
final class ListResponse implements ResponseContract, ResponseHasMetaInformationContract
1818
{
1919
/**
20-
* @use ArrayAccessible<array{object: string, data: array<int, array{id: string, object: string, created: ?int, owned_by: string}>}>
20+
* @use ArrayAccessible<array{object: string, data: array<int, array{id: string, object: string, created: ?int, created_at?: ?int, owned_by: ?string}>}>
2121
*/
2222
use ArrayAccessible;
2323

@@ -34,9 +34,7 @@ private function __construct(
3434
) {}
3535

3636
/**
37-
* Acts as static factory, and returns a new Response instance.
38-
*
39-
* @param array{object: string, data: array<int, array{id: string, object: string, created: ?int, owned_by: string}>} $attributes
37+
* @param array{object: string, data: array<int, array{id: string, object: string, created: ?int, created_at?: ?int, owned_by: ?string}>} $attributes
4038
*/
4139
public static function from(array $attributes, MetaInformation $meta): self
4240
{

src/Responses/Models/RetrieveResponse.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
use OpenAI\Testing\Responses\Concerns\Fakeable;
1313

1414
/**
15-
* @implements ResponseContract<array{id: string, object: string, created: ?int, owned_by: string}>
15+
* @implements ResponseContract<array{id: string, object: string, created: ?int, created_at?: ?int, owned_by: ?string}>
1616
*/
1717
final class RetrieveResponse implements ResponseContract, ResponseHasMetaInformationContract
1818
{
1919
/**
20-
* @use ArrayAccessible<array{id: string, object: string, created: ?int, owned_by: string}>
20+
* @use ArrayAccessible<array{id: string, object: string, created: ?int, owned_by: ?string}>
2121
*/
2222
use ArrayAccessible;
2323

@@ -28,23 +28,21 @@ private function __construct(
2828
public readonly string $id,
2929
public readonly string $object,
3030
public readonly ?int $created,
31-
public readonly string $ownedBy,
31+
public readonly ?string $ownedBy,
3232
private readonly MetaInformation $meta,
3333
) {}
3434

3535
/**
36-
* Acts as static factory, and returns a new Response instance.
37-
*
38-
* @param array{id: string, object: string, created: ?int, owned_by: string} $attributes
36+
* @param array{id: string, object: string, created: ?int, created_at?: ?int, owned_by: ?string} $attributes
3937
*/
4038
public static function from(array $attributes, MetaInformation $meta): self
4139
{
4240
return new self(
43-
$attributes['id'],
44-
$attributes['object'],
45-
$attributes['created'] ?? null,
46-
$attributes['owned_by'],
47-
$meta,
41+
id: $attributes['id'],
42+
object: $attributes['object'],
43+
created: $attributes['created'] ?? $attributes['created_at'] ?? null,
44+
ownedBy: $attributes['owned_by'] ?? null,
45+
meta: $meta,
4846
);
4947
}
5048

tests/Fixtures/Model.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ function googleModel(): array
2525
];
2626
}
2727

28+
/**
29+
* @return array<string, mixed>
30+
*/
31+
function azureModel(): array
32+
{
33+
return [
34+
'id' => 'gpt-35-turbo',
35+
'object' => 'model',
36+
'created_at' => 1700000000,
37+
];
38+
}
39+
2840
/**
2941
* @return array<string, mixed>
3042
*/

tests/Responses/Models/RetrieveResponse.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626
->meta()->toBeInstanceOf(MetaInformation::class);
2727
});
2828

29+
test('from azure', function () {
30+
$result = RetrieveResponse::from(azureModel(), meta());
31+
32+
expect($result)
33+
->toBeInstanceOf(RetrieveResponse::class)
34+
->id->toBe('gpt-35-turbo')
35+
->object->toBe('model')
36+
->created->toBe(1700000000)
37+
->ownedBy->toBeNull()
38+
->meta()->toBeInstanceOf(MetaInformation::class);
39+
});
40+
2941
test('as array accessible', function () {
3042
$result = RetrieveResponse::from(model(), meta());
3143

0 commit comments

Comments
 (0)