Skip to content

Commit c22f107

Browse files
fix(Gemini): correct list models call (openai-php#567)
* fix: Adjusts Model\RetrieveResponse to handle Gemini API calls * fix: Adjusts PHPdoc to account for nullable 'created' field
1 parent 205be4a commit c22f107

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

src/Responses/Models/ListResponse.php

+3-3
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, 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, owned_by: string}>}>
2121
*/
2222
use ArrayAccessible;
2323

@@ -36,7 +36,7 @@ private function __construct(
3636
/**
3737
* Acts as static factory, and returns a new Response instance.
3838
*
39-
* @param array{object: string, data: array<int, array{id: string, object: string, created: int, owned_by: string}>} $attributes
39+
* @param array{object: string, data: array<int, array{id: string, object: string, created: ?int, owned_by: string}>} $attributes
4040
*/
4141
public static function from(array $attributes, MetaInformation $meta): self
4242
{

src/Responses/Models/RetrieveResponse.php

+5-5
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, 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

@@ -27,22 +27,22 @@ final class RetrieveResponse implements ResponseContract, ResponseHasMetaInforma
2727
private function __construct(
2828
public readonly string $id,
2929
public readonly string $object,
30-
public readonly int $created,
30+
public readonly ?int $created,
3131
public readonly string $ownedBy,
3232
private readonly MetaInformation $meta,
3333
) {}
3434

3535
/**
3636
* Acts as static factory, and returns a new Response instance.
3737
*
38-
* @param array{id: string, object: string, created: int, owned_by: string} $attributes
38+
* @param array{id: string, object: string, created: ?int, owned_by: string} $attributes
3939
*/
4040
public static function from(array $attributes, MetaInformation $meta): self
4141
{
4242
return new self(
4343
$attributes['id'],
4444
$attributes['object'],
45-
$attributes['created'],
45+
$attributes['created'] ?? null,
4646
$attributes['owned_by'],
4747
$meta,
4848
);

tests/Fixtures/Model.php

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ function model(): array
1313
];
1414
}
1515

16+
/**
17+
* @return array<string, string>
18+
*/
19+
function googleModel(): array
20+
{
21+
return [
22+
'id' => 'text-davinci-003',
23+
'object' => 'model',
24+
'owned_by' => 'google',
25+
];
26+
}
27+
1628
/**
1729
* @return array<string, mixed>
1830
*/

tests/Responses/Models/RetrieveResponse.php

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
->meta()->toBeInstanceOf(MetaInformation::class);
1616
});
1717

18+
test('from google', function () {
19+
$result = RetrieveResponse::from(googleModel(), meta());
20+
21+
expect($result)
22+
->toBeInstanceOf(RetrieveResponse::class)
23+
->id->toBe('text-davinci-003')
24+
->object->toBe('model')
25+
->ownedBy->toBe('google')
26+
->meta()->toBeInstanceOf(MetaInformation::class);
27+
});
28+
1829
test('as array accessible', function () {
1930
$result = RetrieveResponse::from(model(), meta());
2031

0 commit comments

Comments
 (0)