@@ -12,20 +12,24 @@ final public class DefaultOpenAIAzureService: OpenAIService {
12
12
public init (
13
13
azureConfiguration: AzureOpenAIConfiguration ,
14
14
urlSessionConfiguration: URLSessionConfiguration = . default,
15
- decoder: JSONDecoder = . init( ) )
15
+ decoder: JSONDecoder = . init( ) ,
16
+ debugEnabled: Bool )
16
17
{
17
18
session = URLSession ( configuration: urlSessionConfiguration)
18
19
self . decoder = decoder
19
20
AzureOpenAIAPI . azureOpenAIResource = azureConfiguration. resourceName
20
21
apiKey = azureConfiguration. openAIAPIKey
21
22
extraHeaders = azureConfiguration. extraHeaders
22
23
initialQueryItems = [ . init( name: " api-version " , value: azureConfiguration. apiVersion) ]
24
+ self . debugEnabled = debugEnabled
23
25
}
24
26
25
27
public let session : URLSession
26
28
public let decoder : JSONDecoder
27
29
private let apiKey : Authorization
28
30
private let initialQueryItems : [ URLQueryItem ]
31
+ /// Set this flag to TRUE if you need to print request events in DEBUG builds.
32
+ private let debugEnabled : Bool
29
33
30
34
// Assistants API
31
35
private let extraHeaders : [ String : String ] ?
@@ -52,7 +56,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
52
56
method: . post,
53
57
params: chatParameters,
54
58
queryItems: initialQueryItems)
55
- return try await fetch ( type: ChatCompletionObject . self, with: request)
59
+ return try await fetch ( debugEnabled : debugEnabled , type: ChatCompletionObject . self, with: request)
56
60
}
57
61
58
62
public func startStreamedChat( parameters: ChatCompletionParameters ) async throws -> AsyncThrowingStream < ChatCompletionChunkObject , Error > {
@@ -66,7 +70,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
66
70
params: chatParameters,
67
71
queryItems: initialQueryItems
68
72
)
69
- return try await fetchStream ( type: ChatCompletionChunkObject . self, with: request)
73
+ return try await fetchStream ( debugEnabled : debugEnabled , type: ChatCompletionChunkObject . self, with: request)
70
74
}
71
75
72
76
public func createEmbeddings( parameters: EmbeddingParameter ) async throws -> OpenAIResponse < EmbeddingObject > {
@@ -155,7 +159,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
155
159
betaHeaderField: Self . assistantsBetaV2,
156
160
extraHeaders: extraHeaders
157
161
)
158
- return try await fetch ( type: AssistantObject . self, with: request)
162
+ return try await fetch ( debugEnabled : debugEnabled , type: AssistantObject . self, with: request)
159
163
}
160
164
161
165
public func retrieveAssistant( id: String ) async throws -> AssistantObject {
@@ -167,7 +171,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
167
171
betaHeaderField: Self . assistantsBetaV2,
168
172
extraHeaders: extraHeaders
169
173
)
170
- return try await fetch ( type: AssistantObject . self, with: request)
174
+ return try await fetch ( debugEnabled : debugEnabled , type: AssistantObject . self, with: request)
171
175
}
172
176
173
177
public func modifyAssistant( id: String , parameters: AssistantParameters ) async throws -> AssistantObject {
@@ -180,7 +184,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
180
184
betaHeaderField: Self . assistantsBetaV2,
181
185
extraHeaders: extraHeaders
182
186
)
183
- return try await fetch ( type: AssistantObject . self, with: request)
187
+ return try await fetch ( debugEnabled : debugEnabled , type: AssistantObject . self, with: request)
184
188
}
185
189
186
190
public func deleteAssistant( id: String ) async throws -> DeletionStatus {
@@ -192,7 +196,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
192
196
betaHeaderField: Self . assistantsBetaV2,
193
197
extraHeaders: extraHeaders
194
198
)
195
- return try await fetch ( type: DeletionStatus . self, with: request)
199
+ return try await fetch ( debugEnabled : debugEnabled , type: DeletionStatus . self, with: request)
196
200
}
197
201
198
202
public func listAssistants( limit: Int ? , order: String ? , after: String ? , before: String ? ) async throws -> OpenAIResponse < AssistantObject > {
@@ -217,7 +221,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
217
221
betaHeaderField: Self . assistantsBetaV2,
218
222
extraHeaders: extraHeaders
219
223
)
220
- return try await fetch ( type: OpenAIResponse< AssistantObject> . self , with: request)
224
+ return try await fetch ( debugEnabled : debugEnabled , type: OpenAIResponse< AssistantObject> . self , with: request)
221
225
}
222
226
223
227
public func createThread( parameters: CreateThreadParameters ) async throws -> ThreadObject {
@@ -229,7 +233,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
229
233
queryItems: initialQueryItems,
230
234
betaHeaderField: Self . assistantsBetaV2,
231
235
extraHeaders: extraHeaders)
232
- return try await fetch ( type: ThreadObject . self, with: request)
236
+ return try await fetch ( debugEnabled : debugEnabled , type: ThreadObject . self, with: request)
233
237
}
234
238
235
239
public func retrieveThread( id: String ) async throws -> ThreadObject {
@@ -240,7 +244,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
240
244
queryItems: initialQueryItems,
241
245
betaHeaderField: Self . assistantsBetaV2,
242
246
extraHeaders: extraHeaders)
243
- return try await fetch ( type: ThreadObject . self, with: request)
247
+ return try await fetch ( debugEnabled : debugEnabled , type: ThreadObject . self, with: request)
244
248
}
245
249
246
250
public func modifyThread( id: String , parameters: ModifyThreadParameters ) async throws -> ThreadObject {
@@ -252,7 +256,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
252
256
queryItems: initialQueryItems,
253
257
betaHeaderField: Self . assistantsBetaV2,
254
258
extraHeaders: extraHeaders)
255
- return try await fetch ( type: ThreadObject . self, with: request)
259
+ return try await fetch ( debugEnabled : debugEnabled , type: ThreadObject . self, with: request)
256
260
}
257
261
258
262
public func deleteThread( id: String ) async throws -> DeletionStatus {
@@ -263,7 +267,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
263
267
queryItems: initialQueryItems,
264
268
betaHeaderField: Self . assistantsBetaV2,
265
269
extraHeaders: extraHeaders)
266
- return try await fetch ( type: DeletionStatus . self, with: request)
270
+ return try await fetch ( debugEnabled : debugEnabled , type: DeletionStatus . self, with: request)
267
271
}
268
272
269
273
public func createMessage( threadID: String , parameters: MessageParameter ) async throws -> MessageObject {
@@ -275,7 +279,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
275
279
queryItems: initialQueryItems,
276
280
betaHeaderField: Self . assistantsBetaV2,
277
281
extraHeaders: extraHeaders)
278
- return try await fetch ( type: MessageObject . self, with: request)
282
+ return try await fetch ( debugEnabled : debugEnabled , type: MessageObject . self, with: request)
279
283
}
280
284
281
285
public func retrieveMessage( threadID: String , messageID: String ) async throws -> MessageObject {
@@ -286,7 +290,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
286
290
queryItems: initialQueryItems,
287
291
betaHeaderField: Self . assistantsBetaV2,
288
292
extraHeaders: extraHeaders)
289
- return try await fetch ( type: MessageObject . self, with: request)
293
+ return try await fetch ( debugEnabled : debugEnabled , type: MessageObject . self, with: request)
290
294
}
291
295
292
296
public func modifyMessage( threadID: String , messageID: String , parameters: ModifyMessageParameters ) async throws -> MessageObject {
@@ -298,7 +302,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
298
302
queryItems: initialQueryItems,
299
303
betaHeaderField: Self . assistantsBetaV2,
300
304
extraHeaders: extraHeaders)
301
- return try await fetch ( type: MessageObject . self, with: request)
305
+ return try await fetch ( debugEnabled : debugEnabled , type: MessageObject . self, with: request)
302
306
}
303
307
304
308
public func listMessages( threadID: String , limit: Int ? , order: String ? , after: String ? , before: String ? , runID: String ? ) async throws -> OpenAIResponse < MessageObject > {
@@ -325,7 +329,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
325
329
queryItems: queryItems,
326
330
betaHeaderField: Self . assistantsBetaV2,
327
331
extraHeaders: extraHeaders)
328
- return try await fetch ( type: OpenAIResponse< MessageObject> . self , with: request)
332
+ return try await fetch ( debugEnabled : debugEnabled , type: OpenAIResponse< MessageObject> . self , with: request)
329
333
}
330
334
331
335
public func createRun( threadID: String , parameters: RunParameter ) async throws -> RunObject {
@@ -337,7 +341,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
337
341
queryItems: initialQueryItems,
338
342
betaHeaderField: Self . assistantsBetaV2,
339
343
extraHeaders: extraHeaders)
340
- return try await fetch ( type: RunObject . self, with: request)
344
+ return try await fetch ( debugEnabled : debugEnabled , type: RunObject . self, with: request)
341
345
}
342
346
343
347
public func retrieveRun( threadID: String , runID: String ) async throws -> RunObject {
@@ -348,7 +352,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
348
352
queryItems: initialQueryItems,
349
353
betaHeaderField: Self . assistantsBetaV2,
350
354
extraHeaders: extraHeaders)
351
- return try await fetch ( type: RunObject . self, with: request)
355
+ return try await fetch ( debugEnabled : debugEnabled , type: RunObject . self, with: request)
352
356
}
353
357
354
358
public func modifyRun( threadID: String , runID: String , parameters: ModifyRunParameters ) async throws -> RunObject {
@@ -360,7 +364,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
360
364
queryItems: initialQueryItems,
361
365
betaHeaderField: Self . assistantsBetaV2,
362
366
extraHeaders: extraHeaders)
363
- return try await fetch ( type: RunObject . self, with: request)
367
+ return try await fetch ( debugEnabled : debugEnabled , type: RunObject . self, with: request)
364
368
}
365
369
366
370
public func listRuns( threadID: String , limit: Int ? , order: String ? , after: String ? , before: String ? ) async throws -> OpenAIResponse < RunObject > {
@@ -384,7 +388,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
384
388
queryItems: queryItems,
385
389
betaHeaderField: Self . assistantsBetaV2,
386
390
extraHeaders: extraHeaders)
387
- return try await fetch ( type: OpenAIResponse< RunObject> . self , with: request)
391
+ return try await fetch ( debugEnabled : debugEnabled , type: OpenAIResponse< RunObject> . self , with: request)
388
392
}
389
393
390
394
public func cancelRun( threadID: String , runID: String ) async throws -> RunObject {
@@ -395,7 +399,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
395
399
queryItems: initialQueryItems,
396
400
betaHeaderField: Self . assistantsBetaV2,
397
401
extraHeaders: extraHeaders)
398
- return try await fetch ( type: RunObject . self, with: request)
402
+ return try await fetch ( debugEnabled : debugEnabled , type: RunObject . self, with: request)
399
403
}
400
404
401
405
public func submitToolOutputsToRun( threadID: String , runID: String , parameters: RunToolsOutputParameter ) async throws -> RunObject {
@@ -407,7 +411,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
407
411
queryItems: initialQueryItems,
408
412
betaHeaderField: Self . assistantsBetaV2,
409
413
extraHeaders: extraHeaders)
410
- return try await fetch ( type: RunObject . self, with: request)
414
+ return try await fetch ( debugEnabled : debugEnabled , type: RunObject . self, with: request)
411
415
}
412
416
413
417
public func createThreadAndRun( parameters: CreateThreadAndRunParameter ) async throws -> RunObject {
@@ -419,7 +423,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
419
423
queryItems: initialQueryItems,
420
424
betaHeaderField: Self . assistantsBetaV2,
421
425
extraHeaders: extraHeaders)
422
- return try await fetch ( type: RunObject . self, with: request)
426
+ return try await fetch ( debugEnabled : debugEnabled , type: RunObject . self, with: request)
423
427
}
424
428
425
429
public func retrieveRunstep( threadID: String , runID: String , stepID: String ) async throws -> RunStepObject {
@@ -430,7 +434,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
430
434
queryItems: initialQueryItems,
431
435
betaHeaderField: Self . assistantsBetaV2,
432
436
extraHeaders: extraHeaders)
433
- return try await fetch ( type: RunStepObject . self, with: request)
437
+ return try await fetch ( debugEnabled : debugEnabled , type: RunStepObject . self, with: request)
434
438
}
435
439
436
440
public func listRunSteps( threadID: String , runID: String , limit: Int ? , order: String ? , after: String ? , before: String ? ) async throws -> OpenAIResponse < RunStepObject > {
@@ -454,7 +458,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
454
458
queryItems: queryItems,
455
459
betaHeaderField: Self . assistantsBetaV2,
456
460
extraHeaders: extraHeaders)
457
- return try await fetch ( type: OpenAIResponse< RunStepObject> . self , with: request)
461
+ return try await fetch ( debugEnabled : debugEnabled , type: OpenAIResponse< RunStepObject> . self , with: request)
458
462
}
459
463
460
464
public func createThreadAndRunStream(
@@ -471,7 +475,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
471
475
queryItems: initialQueryItems,
472
476
betaHeaderField: Self . assistantsBetaV2,
473
477
extraHeaders: extraHeaders)
474
- return try await fetchAssistantStreamEvents ( with: request)
478
+ return try await fetchAssistantStreamEvents ( with: request, debugEnabled : debugEnabled )
475
479
}
476
480
477
481
public func createRunStream(
@@ -489,7 +493,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
489
493
queryItems: initialQueryItems,
490
494
betaHeaderField: Self . assistantsBetaV2,
491
495
extraHeaders: extraHeaders)
492
- return try await fetchAssistantStreamEvents ( with: request)
496
+ return try await fetchAssistantStreamEvents ( with: request, debugEnabled : debugEnabled )
493
497
}
494
498
495
499
public func submitToolOutputsToRunStream(
@@ -508,7 +512,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
508
512
queryItems: initialQueryItems,
509
513
betaHeaderField: Self . assistantsBetaV2,
510
514
extraHeaders: extraHeaders)
511
- return try await fetchAssistantStreamEvents ( with: request)
515
+ return try await fetchAssistantStreamEvents ( with: request, debugEnabled : debugEnabled )
512
516
}
513
517
514
518
// MARK: Batch
@@ -555,7 +559,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
555
559
queryItems: initialQueryItems,
556
560
betaHeaderField: Self . assistantsBetaV2,
557
561
extraHeaders: extraHeaders)
558
- return try await fetch ( type: VectorStoreObject . self, with: request)
562
+ return try await fetch ( debugEnabled : debugEnabled , type: VectorStoreObject . self, with: request)
559
563
}
560
564
561
565
public func listVectorStores(
@@ -585,7 +589,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
585
589
queryItems: queryItems,
586
590
betaHeaderField: Self . assistantsBetaV2,
587
591
extraHeaders: extraHeaders)
588
- return try await fetch ( type: OpenAIResponse< VectorStoreObject> . self , with: request)
592
+ return try await fetch ( debugEnabled : debugEnabled , type: OpenAIResponse< VectorStoreObject> . self , with: request)
589
593
}
590
594
591
595
public func retrieveVectorStore(
@@ -599,7 +603,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
599
603
queryItems: initialQueryItems,
600
604
betaHeaderField: Self . assistantsBetaV2,
601
605
extraHeaders: extraHeaders)
602
- return try await fetch ( type: VectorStoreObject . self, with: request)
606
+ return try await fetch ( debugEnabled : debugEnabled , type: VectorStoreObject . self, with: request)
603
607
}
604
608
605
609
public func modifyVectorStore(
@@ -615,7 +619,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
615
619
queryItems: initialQueryItems,
616
620
betaHeaderField: Self . assistantsBetaV2,
617
621
extraHeaders: extraHeaders)
618
- return try await fetch ( type: VectorStoreObject . self, with: request)
622
+ return try await fetch ( debugEnabled : debugEnabled , type: VectorStoreObject . self, with: request)
619
623
}
620
624
621
625
public func deleteVectorStore(
@@ -629,7 +633,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
629
633
queryItems: initialQueryItems,
630
634
betaHeaderField: Self . assistantsBetaV2,
631
635
extraHeaders: extraHeaders)
632
- return try await fetch ( type: DeletionStatus . self, with: request)
636
+ return try await fetch ( debugEnabled : debugEnabled , type: DeletionStatus . self, with: request)
633
637
}
634
638
635
639
// MARK: Vector Store Files
@@ -643,7 +647,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
643
647
queryItems: initialQueryItems,
644
648
betaHeaderField: Self . assistantsBetaV2,
645
649
extraHeaders: extraHeaders)
646
- return try await fetch ( type: VectorStoreFileObject . self, with: request)
650
+ return try await fetch ( debugEnabled : debugEnabled , type: VectorStoreFileObject . self, with: request)
647
651
}
648
652
649
653
public func listVectorStoreFiles( vectorStoreID: String , limit: Int ? , order: String ? , after: String ? , before: String ? , filter: String ? ) async throws -> OpenAIResponse < VectorStoreFileObject > {
@@ -670,7 +674,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
670
674
queryItems: queryItems,
671
675
betaHeaderField: Self . assistantsBetaV2,
672
676
extraHeaders: extraHeaders)
673
- return try await fetch ( type: OpenAIResponse< VectorStoreFileObject> . self , with: request)
677
+ return try await fetch ( debugEnabled : debugEnabled , type: OpenAIResponse< VectorStoreFileObject> . self , with: request)
674
678
}
675
679
676
680
public func retrieveVectorStoreFile( vectorStoreID: String , fileID: String ) async throws -> VectorStoreFileObject {
@@ -681,7 +685,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
681
685
queryItems: initialQueryItems,
682
686
betaHeaderField: Self . assistantsBetaV2,
683
687
extraHeaders: extraHeaders)
684
- return try await fetch ( type: VectorStoreFileObject . self, with: request)
688
+ return try await fetch ( debugEnabled : debugEnabled , type: VectorStoreFileObject . self, with: request)
685
689
}
686
690
687
691
public func deleteVectorStoreFile( vectorStoreID: String , fileID: String ) async throws -> DeletionStatus {
@@ -692,7 +696,7 @@ final public class DefaultOpenAIAzureService: OpenAIService {
692
696
queryItems: initialQueryItems,
693
697
betaHeaderField: Self . assistantsBetaV2,
694
698
extraHeaders: extraHeaders)
695
- return try await fetch ( type: DeletionStatus . self, with: request)
699
+ return try await fetch ( debugEnabled : debugEnabled , type: DeletionStatus . self, with: request)
696
700
}
697
701
698
702
public func createVectorStoreFileBatch( vectorStoreID: String , parameters: VectorStoreFileBatchParameter ) async throws -> VectorStoreFileBatchObject {
0 commit comments