Skip to content

Commit c668b0a

Browse files
committed
Adjust model response object to the latest API changes
1 parent f368311 commit c668b0a

File tree

10 files changed

+12
-208
lines changed

10 files changed

+12
-208
lines changed

README.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,6 @@ $response->id; // 'gpt-3.5-turbo-instruct'
115115
$response->object; // 'model'
116116
$response->created; // 1642018370
117117
$response->ownedBy; // 'openai'
118-
$response->root; // 'gpt-3.5-turbo-instruct'
119-
$response->parent; // null
120-
121-
foreach ($response->permission as $result) {
122-
$result->id; // 'modelperm-7E53j9OtnMZggjqlwMxW4QG7'
123-
$result->object; // 'model_permission'
124-
$result->created; // 1664307523
125-
$result->allowCreateEngine; // false
126-
$result->allowSampling; // true
127-
$result->allowLogprobs; // true
128-
$result->allowSearchIndices; // false
129-
$result->allowView; // true
130-
$result->allowFineTuning; // false
131-
$result->organization; // '*'
132-
$result->group; // null
133-
$result->isBlocking; // false
134-
}
135118

136119
$response->toArray(); // ['id' => 'gpt-3.5-turbo-instruct', ...]
137120
```

src/Resources/Models.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function list(): ListResponse
2424
{
2525
$payload = Payload::list('models');
2626

27-
/** @var Response<array{object: string, data: array<int, array{id: string, object: string, created: int, owned_by: string, permission: array<int, array{id: string, object: string, created: int, allow_create_engine: bool, allow_sampling: bool, allow_logprobs: bool, allow_search_indices: bool, allow_view: bool, allow_fine_tuning: bool, organization: string, group: ?string, is_blocking: bool}>, root: string, parent: ?string}>}> $response */
27+
/** @var Response<array{object: string, data: array<int, array{id: string, object: string, created: int, owned_by: string}>}> $response */
2828
$response = $this->transporter->requestObject($payload);
2929

3030
return ListResponse::from($response->data(), $response->meta());
@@ -39,7 +39,7 @@ public function retrieve(string $model): RetrieveResponse
3939
{
4040
$payload = Payload::retrieve('models', $model);
4141

42-
/** @var Response<array{id: string, object: string, created: int, owned_by: string, permission: array<int, array{id: string, object: string, created: int, allow_create_engine: bool, allow_sampling: bool, allow_logprobs: bool, allow_search_indices: bool, allow_view: bool, allow_fine_tuning: bool, organization: string, group: ?string, is_blocking: bool}>, root: string, parent: ?string}> $response */
42+
/** @var Response<array{id: string, object: string, created: int, owned_by: string}> $response */
4343
$response = $this->transporter->requestObject($payload);
4444

4545
return RetrieveResponse::from($response->data(), $response->meta());

src/Responses/Models/ListResponse.php

Lines changed: 3 additions & 3 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, permission: array<int, array{id: string, object: string, created: int, allow_create_engine: bool, allow_sampling: bool, allow_logprobs: bool, allow_search_indices: bool, allow_view: bool, allow_fine_tuning: bool, organization: string, group: ?string, is_blocking: bool}>, root: string, parent: ?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, permission: array<int, array{id: string, object: string, created: int, allow_create_engine: bool, allow_sampling: bool, allow_logprobs: bool, allow_search_indices: bool, allow_view: bool, allow_fine_tuning: bool, organization: string, group: ?string, is_blocking: bool}>, root: string, parent: ?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

@@ -37,7 +37,7 @@ private function __construct(
3737
/**
3838
* Acts as static factory, and returns a new Response instance.
3939
*
40-
* @param array{object: string, data: array<int, array{id: string, object: string, created: int, owned_by: string, permission: array<int, array{id: string, object: string, created: int, allow_create_engine: bool, allow_sampling: bool, allow_logprobs: bool, allow_search_indices: bool, allow_view: bool, allow_fine_tuning: bool, organization: string, group: ?string, is_blocking: bool}>, root: string, parent: ?string}>} $attributes
40+
* @param array{object: string, data: array<int, array{id: string, object: string, created: int, owned_by: string}>} $attributes
4141
*/
4242
public static function from(array $attributes, MetaInformation $meta): self
4343
{

src/Responses/Models/RetrieveResponse.php

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

1414
/**
15-
* @implements ResponseContract<array{id: string, object: string, created: int, owned_by: string, permission: array<int, array{id: string, object: string, created: int, allow_create_engine: bool, allow_sampling: bool, allow_logprobs: bool, allow_search_indices: bool, allow_view: bool, allow_fine_tuning: bool, organization: string, group: ?string, is_blocking: bool}>, root: string, parent: ?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, permission: array<int, array{id: string, object: string, created: int, allow_create_engine: bool, allow_sampling: bool, allow_logprobs: bool, allow_search_indices: bool, allow_view: bool, allow_fine_tuning: bool, organization: string, group: ?string, is_blocking: bool}>, root: string, parent: ?string}>
20+
* @use ArrayAccessible<array{id: string, object: string, created: int, owned_by: string}>
2121
*/
2222
use ArrayAccessible;
2323

2424
use Fakeable;
2525
use HasMetaInformation;
2626

27-
/**
28-
* @param array<int, RetrieveResponsePermission> $permission
29-
*/
3027
private function __construct(
3128
public readonly string $id,
3229
public readonly string $object,
3330
public readonly int $created,
3431
public readonly string $ownedBy,
35-
public readonly array $permission,
36-
public readonly string $root,
37-
public readonly ?string $parent,
3832
private readonly MetaInformation $meta,
3933
) {
4034
}
4135

4236
/**
4337
* Acts as static factory, and returns a new Response instance.
4438
*
45-
* @param array{id: string, object: string, created: int, owned_by: string, permission: array<int, array{id: string, object: string, created: int, allow_create_engine: bool, allow_sampling: bool, allow_logprobs: bool, allow_search_indices: bool, allow_view: bool, allow_fine_tuning: bool, organization: string, group: ?string, is_blocking: bool}>, root: string, parent: ?string} $attributes
39+
* @param array{id: string, object: string, created: int, owned_by: string} $attributes
4640
*/
4741
public static function from(array $attributes, MetaInformation $meta): self
4842
{
49-
$permission = array_map(fn (array $result): RetrieveResponsePermission => RetrieveResponsePermission::from(
50-
$result
51-
), $attributes['permission']);
52-
5343
return new self(
5444
$attributes['id'],
5545
$attributes['object'],
5646
$attributes['created'],
5747
$attributes['owned_by'],
58-
$permission,
59-
$attributes['root'],
60-
$attributes['parent'],
6148
$meta,
6249
);
6350
}
@@ -72,12 +59,6 @@ public function toArray(): array
7259
'object' => $this->object,
7360
'created' => $this->created,
7461
'owned_by' => $this->ownedBy,
75-
'permission' => array_map(
76-
static fn (RetrieveResponsePermission $result): array => $result->toArray(),
77-
$this->permission,
78-
),
79-
'root' => $this->root,
80-
'parent' => $this->parent,
8162
];
8263
}
8364
}

src/Responses/Models/RetrieveResponsePermission.php

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/Testing/Responses/Fixtures/Models/RetrieveResponseFixture.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,5 @@ final class RetrieveResponseFixture
99
'object' => 'model',
1010
'created' => 1_642_018_370,
1111
'owned_by' => 'openai',
12-
'permission' => [
13-
[
14-
'id' => 'snapperm-7oP3WFr9x7qf5xb3eZrVABAH',
15-
'object' => 'model_permission',
16-
'created' => 1_642_018_480,
17-
'allow_create_engine' => false,
18-
'allow_sampling' => true,
19-
'allow_logprobs' => true,
20-
'allow_search_indices' => false,
21-
'allow_view' => true,
22-
'allow_fine_tuning' => false,
23-
'organization' => '*',
24-
'group' => null,
25-
'is_blocking' => false,
26-
],
27-
],
28-
'root' => 'text-babbage:001',
29-
'parent' => null,
3012
];
3113
}

tests/Fixtures/Model.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,6 @@ function model(): array
1010
'object' => 'model',
1111
'created' => 1642018370,
1212
'owned_by' => 'openai',
13-
'permission' => [
14-
[
15-
'id' => 'snapperm-7oP3WFr9x7qf5xb3eZrVABAH',
16-
'object' => 'model_permission',
17-
'created' => 1642018480,
18-
'allow_create_engine' => false,
19-
'allow_sampling' => true,
20-
'allow_logprobs' => true,
21-
'allow_search_indices' => false,
22-
'allow_view' => true,
23-
'allow_fine_tuning' => false,
24-
'organization' => '*',
25-
'group' => null,
26-
'is_blocking' => false,
27-
],
28-
],
29-
'root' => 'text-babbage:001',
30-
'parent' => null,
3113
];
3214
}
3315

tests/Resources/Models.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use OpenAI\Responses\Models\DeleteResponse;
55
use OpenAI\Responses\Models\ListResponse;
66
use OpenAI\Responses\Models\RetrieveResponse;
7-
use OpenAI\Responses\Models\RetrieveResponsePermission;
87

98
test('list', function () {
109
$client = mockClient('GET', 'models', [], \OpenAI\ValueObjects\Transporter\Response::from(modelList(), metaHeaders()));
@@ -34,25 +33,7 @@
3433
->id->toBe('text-babbage:001')
3534
->object->toBe('model')
3635
->created->toBe(1642018370)
37-
->ownedBy->toBe('openai')
38-
->permission->toBeArray()->toHaveCount(1)
39-
->permission->each->toBeInstanceOf(RetrieveResponsePermission::class)
40-
->root->toBe('text-babbage:001')
41-
->parent->toBe(null);
42-
43-
expect($result->permission[0])
44-
->id->toBe('snapperm-7oP3WFr9x7qf5xb3eZrVABAH')
45-
->object->toBe('model_permission')
46-
->created->toBe(1642018480)
47-
->allowCreateEngine->toBe(false)
48-
->allowSampling->toBe(true)
49-
->allowLogprobs->toBe(true)
50-
->allowSearchIndices->toBe(false)
51-
->allowView->toBe(true)
52-
->allowFineTuning->toBe(false)
53-
->organization->toBe('*')
54-
->group->toBe(null)
55-
->isBlocking->toBe(false);
36+
->ownedBy->toBe('openai');
5637

5738
expect($result->meta())
5839
->toBeInstanceOf(MetaInformation::class);

tests/Responses/Models/RetrieveResponse.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use OpenAI\Responses\Meta\MetaInformation;
44
use OpenAI\Responses\Models\RetrieveResponse;
5-
use OpenAI\Responses\Models\RetrieveResponsePermission;
65

76
test('from', function () {
87
$result = RetrieveResponse::from(model(), meta());
@@ -13,10 +12,6 @@
1312
->object->toBe('model')
1413
->created->toBe(1642018370)
1514
->ownedBy->toBe('openai')
16-
->permission->toBeArray()->toHaveCount(1)
17-
->permission->each->toBeInstanceOf(RetrieveResponsePermission::class)
18-
->root->toBe('text-babbage:001')
19-
->parent->toBe(null)
2015
->meta()->toBeInstanceOf(MetaInformation::class);
2116
});
2217

@@ -38,22 +33,16 @@
3833

3934
expect($response)
4035
->id->toBe('text-babbage:001')
41-
->and($response->permission[0])
42-
->allowCreateEngine->toBeFalse();
36+
->ownedBy->toBe('openai');
4337
});
4438

4539
test('fake with override', function () {
4640
$response = RetrieveResponse::fake([
4741
'id' => 'text-1234',
48-
'permission' => [
49-
[
50-
'allow_create_engine' => true,
51-
],
52-
],
42+
'owned_by' => 'xyz-dev',
5343
]);
5444

5545
expect($response)
5646
->id->toBe('text-1234')
57-
->and($response->permission[0])
58-
->allowCreateEngine->toBeTrue();
47+
->ownedBy->toBe('xyz-dev');
5948
});

tests/Responses/Models/RetrieveResponsePermission.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)