18
18
use OpenAI \Responses \Responses \Output \OutputMcpCall ;
19
19
use OpenAI \Responses \Responses \Output \OutputMcpListTools ;
20
20
use OpenAI \Responses \Responses \Output \OutputMessage ;
21
+ use OpenAI \Responses \Responses \Output \OutputMessageContentOutputText ;
21
22
use OpenAI \Responses \Responses \Output \OutputReasoning ;
22
23
use OpenAI \Responses \Responses \Output \OutputWebSearchToolCall ;
23
24
use OpenAI \Responses \Responses \Tool \CodeInterpreterTool ;
64
65
* @phpstan-type ToolChoiceType 'none'|'auto'|'required'|FunctionToolChoiceType|HostedToolChoiceType
65
66
* @phpstan-type ToolsType array<int, ComputerUseToolType|FileSearchToolType|FunctionToolType|WebSearchToolType|ImageGenerationToolType|RemoteMcpToolType|CodeInterpreterToolType>
66
67
* @phpstan-type OutputType array<int, OutputComputerToolCallType|OutputFileSearchToolCallType|OutputFunctionToolCallType|OutputMessageType|OutputReasoningType|OutputWebSearchToolCallType|OutputMcpListToolsType|OutputMcpApprovalRequestType|OutputMcpCallType|OutputImageGenerationToolCallType|OutputCodeInterpreterToolCallType>
67
- * @phpstan-type RetrieveResponseType array{id: string, object: 'response', created_at: int, status: 'completed'|'failed'|'in_progress'|'incomplete', error: ErrorType|null, incomplete_details: IncompleteDetailsType|null, instructions: InstructionsType, max_output_tokens: int|null, model: string, output: OutputType, parallel_tool_calls: bool, previous_response_id: string|null, prompt: ReferencePromptObjectType|null, reasoning: ReasoningType|null, store: bool, temperature: float|null, text: ResponseFormatType, tool_choice: ToolChoiceType, tools: ToolsType, top_p: float|null, truncation: 'auto'|'disabled'|null, usage: UsageType|null, user: string|null, metadata: array<string, string>|null}
68
+ * @phpstan-type RetrieveResponseType array{id: string, background?: bool|null, object: 'response', created_at: int, status: 'completed'|'failed'|'in_progress'|'incomplete', error: ErrorType|null, incomplete_details: IncompleteDetailsType|null, instructions: InstructionsType, max_output_tokens: int|null, max_tool_calls?: int|null, model: string, output: OutputType, output_text: string|null, parallel_tool_calls: bool, previous_response_id: string|null, prompt: ReferencePromptObjectType|null, prompt_cache_key?: string|null, reasoning: ReasoningType|null, safety_identifier?: string|null, service_tier?: string|null, store: bool, temperature: float|null, text: ResponseFormatType, tool_choice: ToolChoiceType, tools: ToolsType, top_logprobs?: int|null, top_p: float|null, truncation: 'auto'|'disabled'|null, usage: UsageType|null, user: string|null, verbosity : string|null, metadata: array<string, string>|null}
68
69
*
69
70
* @implements ResponseContract<RetrieveResponseType>
70
71
*/
@@ -89,28 +90,36 @@ final class RetrieveResponse implements ResponseContract, ResponseHasMetaInforma
89
90
*/
90
91
private function __construct (
91
92
public readonly string $ id ,
93
+ public readonly ?bool $ background ,
92
94
public readonly string $ object ,
93
95
public readonly int $ createdAt ,
94
96
public readonly string $ status ,
95
97
public readonly ?CreateResponseError $ error ,
96
98
public readonly ?CreateResponseIncompleteDetails $ incompleteDetails ,
97
99
public readonly array |string |null $ instructions ,
100
+ public readonly ?int $ maxToolCalls ,
98
101
public readonly ?int $ maxOutputTokens ,
99
102
public readonly string $ model ,
100
103
public readonly array $ output ,
104
+ public readonly ?string $ outputText ,
101
105
public readonly bool $ parallelToolCalls ,
102
106
public readonly ?string $ previousResponseId ,
103
107
public readonly ?ReferencePromptObject $ prompt ,
108
+ public readonly ?string $ promptCacheKey ,
109
+ public readonly ?string $ safetyIdentifier ,
110
+ public readonly ?string $ serviceTier ,
104
111
public readonly ?CreateResponseReasoning $ reasoning ,
105
112
public readonly bool $ store ,
106
113
public readonly ?float $ temperature ,
107
114
public readonly CreateResponseFormat $ text ,
108
115
public readonly string |FunctionToolChoice |HostedToolChoice $ toolChoice ,
109
116
public readonly array $ tools ,
117
+ public readonly ?int $ topLogProbs ,
110
118
public readonly ?float $ topP ,
111
119
public readonly ?string $ truncation ,
112
120
public readonly ?CreateResponseUsage $ usage ,
113
121
public readonly ?string $ user ,
122
+ public readonly ?string $ verbosity ,
114
123
public array $ metadata ,
115
124
private readonly MetaInformation $ meta ,
116
125
) {}
@@ -157,8 +166,21 @@ public static function from(array $attributes, MetaInformation $meta): self
157
166
$ attributes ['tools ' ],
158
167
);
159
168
169
+ // Remake the sdk only property output_text.
170
+ $ texts = [];
171
+ foreach ($ output as $ item ) {
172
+ if ($ item instanceof OutputMessage) {
173
+ foreach ($ item ->content as $ content ) {
174
+ if ($ content instanceof OutputMessageContentOutputText) {
175
+ $ texts [] = $ content ->text ;
176
+ }
177
+ }
178
+ }
179
+ }
180
+
160
181
return new self (
161
182
id: $ attributes ['id ' ],
183
+ background: $ attributes ['background ' ] ?? null ,
162
184
object: $ attributes ['object ' ],
163
185
createdAt: $ attributes ['created_at ' ],
164
186
status: $ attributes ['status ' ],
@@ -169,14 +191,19 @@ public static function from(array $attributes, MetaInformation $meta): self
169
191
? CreateResponseIncompleteDetails::from ($ attributes ['incomplete_details ' ])
170
192
: null ,
171
193
instructions: $ attributes ['instructions ' ],
194
+ maxToolCalls: $ attributes ['max_tool_calls ' ] ?? null ,
172
195
maxOutputTokens: $ attributes ['max_output_tokens ' ],
173
196
model: $ attributes ['model ' ],
174
197
output: $ output ,
198
+ outputText: empty ($ texts ) ? null : implode (' ' , $ texts ),
175
199
parallelToolCalls: $ attributes ['parallel_tool_calls ' ],
176
200
previousResponseId: $ attributes ['previous_response_id ' ],
177
201
prompt: isset ($ attributes ['prompt ' ])
178
202
? ReferencePromptObject::from ($ attributes ['prompt ' ])
179
203
: null ,
204
+ promptCacheKey: $ attributes ['prompt_cache_key ' ] ?? null ,
205
+ safetyIdentifier: $ attributes ['safety_identifier ' ] ?? null ,
206
+ serviceTier: $ attributes ['service_tier ' ] ?? null ,
180
207
reasoning: isset ($ attributes ['reasoning ' ])
181
208
? CreateResponseReasoning::from ($ attributes ['reasoning ' ])
182
209
: null ,
@@ -185,12 +212,14 @@ public static function from(array $attributes, MetaInformation $meta): self
185
212
text: CreateResponseFormat::from ($ attributes ['text ' ]),
186
213
toolChoice: $ toolChoice ,
187
214
tools: $ tools ,
215
+ topLogProbs: $ attributes ['top_logprobs ' ] ?? null ,
188
216
topP: $ attributes ['top_p ' ],
189
217
truncation: $ attributes ['truncation ' ],
190
218
usage: isset ($ attributes ['usage ' ])
191
219
? CreateResponseUsage::from ($ attributes ['usage ' ])
192
220
: null ,
193
221
user: $ attributes ['user ' ] ?? null ,
222
+ verbosity: $ attributes ['verbosity ' ] ?? null ,
194
223
metadata: $ attributes ['metadata ' ] ?? [],
195
224
meta: $ meta ,
196
225
);
@@ -205,22 +234,28 @@ public function toArray(): array
205
234
// @phpstan-ignore-next-line
206
235
return [
207
236
'id ' => $ this ->id ,
237
+ 'background ' => $ this ->background ,
208
238
'object ' => $ this ->object ,
209
239
'created_at ' => $ this ->createdAt ,
210
240
'status ' => $ this ->status ,
211
241
'error ' => $ this ->error ?->toArray(),
212
242
'incomplete_details ' => $ this ->incompleteDetails ?->toArray(),
213
243
'instructions ' => $ this ->instructions ,
244
+ 'max_tool_calls ' => $ this ->maxToolCalls ,
214
245
'max_output_tokens ' => $ this ->maxOutputTokens ,
215
246
'metadata ' => $ this ->metadata ?? [],
216
247
'model ' => $ this ->model ,
217
248
'output ' => array_map (
218
- fn (OutputMessage |OutputComputerToolCall |OutputFileSearchToolCall |OutputWebSearchToolCall |OutputFunctionToolCall |OutputReasoning |OutputMcpListTools |OutputMcpCall | OutputMcpApprovalRequest |OutputImageGenerationToolCall |OutputCodeInterpreterToolCall $ output ): array => $ output ->toArray (),
249
+ fn (OutputMessage |OutputComputerToolCall |OutputFileSearchToolCall |OutputWebSearchToolCall |OutputFunctionToolCall |OutputReasoning |OutputMcpListTools |OutputMcpApprovalRequest | OutputMcpCall |OutputImageGenerationToolCall |OutputCodeInterpreterToolCall $ output ): array => $ output ->toArray (),
219
250
$ this ->output
220
251
),
252
+ 'output_text ' => $ this ->outputText ,
221
253
'parallel_tool_calls ' => $ this ->parallelToolCalls ,
222
254
'previous_response_id ' => $ this ->previousResponseId ,
223
255
'prompt ' => $ this ->prompt ?->toArray(),
256
+ 'prompt_cache_key ' => $ this ->promptCacheKey ,
257
+ 'safety_identifier ' => $ this ->safetyIdentifier ,
258
+ 'service_tier ' => $ this ->serviceTier ,
224
259
'reasoning ' => $ this ->reasoning ?->toArray(),
225
260
'store ' => $ this ->store ,
226
261
'temperature ' => $ this ->temperature ,
@@ -232,10 +267,12 @@ public function toArray(): array
232
267
fn (ComputerUseTool |FileSearchTool |FunctionTool |WebSearchTool |ImageGenerationTool |RemoteMcpTool |CodeInterpreterTool $ tool ): array => $ tool ->toArray (),
233
268
$ this ->tools
234
269
),
270
+ 'top_logprobs ' => $ this ->topLogProbs ,
235
271
'top_p ' => $ this ->topP ,
236
272
'truncation ' => $ this ->truncation ,
237
273
'usage ' => $ this ->usage ?->toArray(),
238
274
'user ' => $ this ->user ,
275
+ 'verbosity ' => $ this ->verbosity ,
239
276
];
240
277
}
241
278
}
0 commit comments