@@ -202,3 +202,118 @@ public struct FunctionResponsePart: Part {
202
202
self . thoughtSignature = thoughtSignature
203
203
}
204
204
}
205
+
206
+ /// A part containing code that was executed by the model.
207
+ @available ( iOS 15 . 0 , macOS 12 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
208
+ public struct ExecutableCodePart : Part {
209
+ /// The language of the code in an ``ExecutableCodePart``.
210
+ public struct Language : Sendable , Equatable , CustomStringConvertible {
211
+ let internalLanguage : ExecutableCode . Language
212
+
213
+ /// The Python programming language.
214
+ public static let python = ExecutableCodePart . Language ( ExecutableCode . Language ( kind: . python) )
215
+
216
+ public var description : String { internalLanguage. rawValue }
217
+
218
+ init ( _ language: ExecutableCode . Language ) {
219
+ internalLanguage = language
220
+ }
221
+ }
222
+
223
+ let executableCode : ExecutableCode
224
+ let _isThought : Bool ?
225
+ let thoughtSignature : String ?
226
+
227
+ /// The language of the code.
228
+ public var language : ExecutableCodePart . Language {
229
+ ExecutableCodePart . Language (
230
+ // Fallback to "LANGUAGE_UNSPECIFIED" if the value is ever omitted by the backend; this should
231
+ // never happen.
232
+ AILog . safeUnwrap (
233
+ executableCode. language, fallback: ExecutableCode . Language ( kind: . unspecified)
234
+ )
235
+ )
236
+ }
237
+
238
+ /// The code that was executed.
239
+ public var code : String {
240
+ // Fallback to empty string if `code` is ever omitted by the backend; this should never happen.
241
+ AILog . safeUnwrap ( executableCode. code, fallback: " " )
242
+ }
243
+
244
+ public var isThought : Bool { _isThought ?? false }
245
+
246
+ public init ( language: ExecutableCodePart . Language , code: String ) {
247
+ self . init (
248
+ ExecutableCode ( language: language. internalLanguage, code: code) ,
249
+ isThought: nil ,
250
+ thoughtSignature: nil
251
+ )
252
+ }
253
+
254
+ init ( _ executableCode: ExecutableCode , isThought: Bool ? , thoughtSignature: String ? ) {
255
+ self . executableCode = executableCode
256
+ _isThought = isThought
257
+ self . thoughtSignature = thoughtSignature
258
+ }
259
+ }
260
+
261
+ /// The result of executing code.
262
+ @available ( iOS 15 . 0 , macOS 12 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
263
+ public struct CodeExecutionResultPart : Part {
264
+ /// The outcome of a code execution.
265
+ public struct Outcome : Sendable , Equatable , CustomStringConvertible {
266
+ let internalOutcome : CodeExecutionResult . Outcome
267
+
268
+ /// The code executed without errors.
269
+ public static let ok = CodeExecutionResultPart . Outcome ( CodeExecutionResult . Outcome ( kind: . ok) )
270
+
271
+ /// The code failed to execute.
272
+ public static let failed =
273
+ CodeExecutionResultPart . Outcome ( CodeExecutionResult . Outcome ( kind: . failed) )
274
+
275
+ /// The code took too long to execute.
276
+ public static let deadlineExceeded =
277
+ CodeExecutionResultPart . Outcome ( CodeExecutionResult . Outcome ( kind: . deadlineExceeded) )
278
+
279
+ public var description : String { internalOutcome. rawValue }
280
+
281
+ init ( _ outcome: CodeExecutionResult . Outcome ) {
282
+ internalOutcome = outcome
283
+ }
284
+ }
285
+
286
+ let codeExecutionResult : CodeExecutionResult
287
+ let _isThought : Bool ?
288
+ let thoughtSignature : String ?
289
+
290
+ /// The outcome of the code execution.
291
+ public var outcome : CodeExecutionResultPart . Outcome {
292
+ CodeExecutionResultPart . Outcome (
293
+ // Fallback to "OUTCOME_UNSPECIFIED" if this value is ever omitted by the backend; this should
294
+ // never happen.
295
+ AILog . safeUnwrap (
296
+ codeExecutionResult. outcome, fallback: CodeExecutionResult . Outcome ( kind: . unspecified)
297
+ )
298
+ )
299
+ }
300
+
301
+ /// The output of the code execution.
302
+ public var output : String ? { codeExecutionResult. output }
303
+
304
+ public var isThought : Bool { _isThought ?? false }
305
+
306
+ public init ( outcome: CodeExecutionResultPart . Outcome , output: String ) {
307
+ self . init (
308
+ codeExecutionResult: CodeExecutionResult ( outcome: outcome. internalOutcome, output: output) ,
309
+ isThought: nil ,
310
+ thoughtSignature: nil
311
+ )
312
+ }
313
+
314
+ init ( codeExecutionResult: CodeExecutionResult , isThought: Bool ? , thoughtSignature: String ? ) {
315
+ self . codeExecutionResult = codeExecutionResult
316
+ _isThought = isThought
317
+ self . thoughtSignature = thoughtSignature
318
+ }
319
+ }
0 commit comments