12
12
use OpenAI \Testing \Responses \Concerns \Fakeable ;
13
13
14
14
/**
15
- * @implements ResponseContract<array{id: string, object: string, model: string, created_at: int, finished_at: ?int, fine_tuned_model: ?string, hyperparameters: array{n_epochs: int|string, batch_size: int|string|null, learning_rate_multiplier: float|string|null}, organization_id: string, result_files: array<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int, error: ?array{code: string, param: ?string, message: string}}>
15
+ * @implements ResponseContract<array{id: string, object: string, model: string, created_at: int, finished_at: ?int, fine_tuned_model: ?string, hyperparameters? : array{n_epochs: int|string, batch_size: int|string|null, learning_rate_multiplier: float|string|null}, organization_id: string, result_files: array<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int, error: ?array{code: string, param: ?string, message: string}}>
16
16
*/
17
17
final class RetrieveJobResponse implements ResponseContract, ResponseHasMetaInformationContract
18
18
{
19
19
/**
20
- * @use ArrayAccessible<array{id: string, object: string, model: string, created_at: int, finished_at: ?int, fine_tuned_model: ?string, hyperparameters: array{n_epochs: int|string, batch_size: int|string|null, learning_rate_multiplier: float|string|null}, organization_id: string, result_files: array<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int, error: ?array{code: string, param: ?string, message: string}}>
20
+ * @use ArrayAccessible<array{id: string, object: string, model: string, created_at: int, finished_at: ?int, fine_tuned_model: ?string, hyperparameters? : array{n_epochs: int|string, batch_size: int|string|null, learning_rate_multiplier: float|string|null}, organization_id: string, result_files: array<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int, error: ?array{code: string, param: ?string, message: string}}>
21
21
*/
22
22
use ArrayAccessible;
23
23
@@ -34,7 +34,7 @@ private function __construct(
34
34
public readonly int $ createdAt ,
35
35
public readonly ?int $ finishedAt ,
36
36
public readonly ?string $ fineTunedModel ,
37
- public readonly RetrieveJobResponseHyperparameters $ hyperparameters ,
37
+ public readonly ? RetrieveJobResponseHyperparameters $ hyperparameters ,
38
38
public readonly string $ organizationId ,
39
39
public readonly array $ resultFiles ,
40
40
public readonly string $ status ,
@@ -48,7 +48,7 @@ private function __construct(
48
48
/**
49
49
* Acts as static factory, and returns a new Response instance.
50
50
*
51
- * @param array{id: string, object: string, model: string, created_at: int, finished_at: ?int, fine_tuned_model: ?string, hyperparameters: array{n_epochs: int|string, batch_size: int|string|null, learning_rate_multiplier: float|string|null}, organization_id: string, result_files: array<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int, error: ?array{code?: string, param?: ?string, message?: string}} $attributes
51
+ * @param array{id: string, object: string, model: string, created_at: int, finished_at: ?int, fine_tuned_model: ?string, hyperparameters? : array{n_epochs: int|string, batch_size: int|string|null, learning_rate_multiplier: float|string|null}, organization_id: string, result_files: array<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int, error: ?array{code?: string, param?: ?string, message?: string}} $attributes
52
52
*/
53
53
public static function from (array $ attributes , MetaInformation $ meta ): self
54
54
{
@@ -59,7 +59,9 @@ public static function from(array $attributes, MetaInformation $meta): self
59
59
$ attributes ['created_at ' ],
60
60
$ attributes ['finished_at ' ],
61
61
$ attributes ['fine_tuned_model ' ],
62
- RetrieveJobResponseHyperparameters::from ($ attributes ['hyperparameters ' ]),
62
+ isset ($ attributes ['hyperparameters ' ])
63
+ ? RetrieveJobResponseHyperparameters::from ($ attributes ['hyperparameters ' ])
64
+ : null ,
63
65
$ attributes ['organization_id ' ],
64
66
$ attributes ['result_files ' ],
65
67
$ attributes ['status ' ],
@@ -81,14 +83,13 @@ public static function from(array $attributes, MetaInformation $meta): self
81
83
*/
82
84
public function toArray (): array
83
85
{
84
- return [
86
+ $ result = [
85
87
'id ' => $ this ->id ,
86
88
'object ' => $ this ->object ,
87
89
'model ' => $ this ->model ,
88
90
'created_at ' => $ this ->createdAt ,
89
91
'finished_at ' => $ this ->finishedAt ,
90
92
'fine_tuned_model ' => $ this ->fineTunedModel ,
91
- 'hyperparameters ' => $ this ->hyperparameters ->toArray (),
92
93
'organization_id ' => $ this ->organizationId ,
93
94
'result_files ' => $ this ->resultFiles ,
94
95
'status ' => $ this ->status ,
@@ -97,5 +98,11 @@ public function toArray(): array
97
98
'trained_tokens ' => $ this ->trainedTokens ,
98
99
'error ' => $ this ->error ?->toArray(),
99
100
];
101
+
102
+ if ($ this ->hyperparameters ) {
103
+ $ result ['hyperparameters ' ] = $ this ->hyperparameters ->toArray ();
104
+ }
105
+
106
+ return $ result ;
100
107
}
101
108
}
0 commit comments