@@ -68,7 +68,7 @@ public async Task GetChatCompletionsWithPagination()
6868 completionIds . Add ( completion . Id ) ;
6969 }
7070
71- await Task . Delay ( s_delayInMilliseconds ) ; // Wait for completions to be stored
71+ await DelayIfNotInPlaybackAsync ( s_delayInMilliseconds ) ; // Wait for completions to be stored
7272
7373 // Test pagination with limit
7474 ChatCompletionCollectionOptions paginationOptions = new ( )
@@ -125,20 +125,20 @@ public async Task GetChatCompletionsWithPagination_PM()
125125 completionIds . Add ( completion . Id ) ;
126126 }
127127
128- await Task . Delay ( s_delayInMilliseconds ) ; // Wait for completions to be stored
128+ await DelayIfNotInPlaybackAsync ( s_delayInMilliseconds ) ; // Wait for completions to be stored
129129
130130 // Test pagination with limit
131131 ChatCompletionCollectionOptions paginationOptions = new ( )
132132 {
133- PageSizeLimit = 2
133+ PageSizeLimit = 2 ,
134134 } ;
135135
136136 int totalCount = 0 ;
137137 string lastId = null ;
138138
139- // await foreach (var fetchedCompletion in client.GetChatCompletionsAsync(after: null, limit: 2, order: null, metadata: null))
140139 var getOptions = GetChatCompletionsOptions . Create ( client ) ;
141140 getOptions . Limit = 2 ;
141+ getOptions . Model = "gpt-4o-mini-2024-07-18" ;
142142 ChatCompletionList result ;
143143 do
144144 {
@@ -150,11 +150,9 @@ public async Task GetChatCompletionsWithPagination_PM()
150150 lastId = fetchedCompletion . Id ;
151151 Assert . That ( fetchedCompletion . Id , Is . Not . Null . And . Not . Empty ) ;
152152 Assert . That ( fetchedCompletion . Choices [ 0 ] . Message . Content , Is . Not . Null ) ;
153-
154- if ( totalCount >= 2 ) break ; // Stop after getting 2 items
155153 }
156154
157- } while ( result . HasMore ) ;
155+ } while ( result . HasMore && totalCount < 2 ) ;
158156
159157
160158 Assert . That ( totalCount , Is . EqualTo ( 2 ) ) ;
@@ -193,7 +191,7 @@ public async Task GetChatCompletionsWithPagination_PMwRequestOptions()
193191 completionIds . Add ( completion . Id ) ;
194192 }
195193
196- await Task . Delay ( s_delayInMilliseconds ) ; // Wait for completions to be stored
194+ await DelayIfNotInPlaybackAsync ( s_delayInMilliseconds ) ; // Wait for completions to be stored
197195
198196 // Test pagination with limit
199197 ChatCompletionCollectionOptions paginationOptions = new ( )
@@ -205,6 +203,7 @@ public async Task GetChatCompletionsWithPagination_PMwRequestOptions()
205203 string lastId = null ;
206204 var getOptions = GetChatCompletionsOptions . Create ( client ) ;
207205 getOptions . Limit = 2 ;
206+ getOptions . Model = "gpt-4o-mini-2024-07-18" ;
208207
209208 AsyncCollectionResult foo = client . GetChatCompletionsAsync ( getOptions , requestOptions : new RequestOptions ( ) ) ;
210209
@@ -258,7 +257,7 @@ public async Task GetChatCompletionsWithAfterIdPagination()
258257 completionIds . Add ( completion . Id ) ;
259258 }
260259
261- await Task . Delay ( s_delayInMilliseconds ) ; // Wait for completions to be stored
260+ await DelayIfNotInPlaybackAsync ( s_delayInMilliseconds ) ; // Wait for completions to be stored
262261
263262 // Get first completion to use as afterId
264263 string afterId = null ;
@@ -317,10 +316,10 @@ public async Task GetChatCompletionsWithOrderFiltering()
317316 createOptions ) ;
318317
319318 completionIds . Add ( completion . Id ) ;
320- await Task . Delay ( 1000 ) ; // Ensure different timestamps
319+ await DelayIfNotInPlaybackAsync ( 1000 ) ; // Ensure different timestamps
321320 }
322321
323- await Task . Delay ( s_delayInMilliseconds ) ; // Wait for completions to be stored
322+ await DelayIfNotInPlaybackAsync ( s_delayInMilliseconds ) ; // Wait for completions to be stored
324323
325324 // Test ascending order
326325 ChatCompletionCollectionOptions ascOptions = new ( )
@@ -403,7 +402,7 @@ public async Task GetChatCompletionsWithMetadataFiltering()
403402 options2 ) ;
404403 completionIds . Add ( otherCompletion . Id ) ;
405404
406- await Task . Delay ( s_delayInMilliseconds ) ; // Wait for completions to be stored
405+ await DelayIfNotInPlaybackAsync ( s_delayInMilliseconds ) ; // Wait for completions to be stored
407406
408407 // Filter by specific metadata
409408 ChatCompletionCollectionOptions filterOptions = new ( )
@@ -451,7 +450,7 @@ public async Task GetChatCompletionsWithModelFiltering()
451450 [ "Model filter test: Say 'Hello'" ] ,
452451 createOptions ) ;
453452
454- await Task . Delay ( s_delayInMilliseconds ) ; // Wait for completions to be stored
453+ await DelayIfNotInPlaybackAsync ( s_delayInMilliseconds ) ; // Wait for completions to be stored
455454
456455 // Filter by the model used by the test client
457456 ChatCompletionCollectionOptions filterOptions = new ( )
@@ -494,7 +493,7 @@ public async Task GetChatCompletionsWithEmptyOptions()
494493 [ "Empty options test: Say 'Hello'" ] ,
495494 createOptions ) ;
496495
497- await Task . Delay ( s_delayInMilliseconds ) ; // Wait for completions to be stored
496+ await DelayIfNotInPlaybackAsync ( s_delayInMilliseconds ) ; // Wait for completions to be stored
498497
499498 // Test with default/empty options
500499 int count = 0 ;
@@ -538,7 +537,7 @@ public async Task GetChatCompletionsWithCombinedFilters()
538537 [ "Combined filters test: Say 'Combined test'" ] ,
539538 createOptions ) ;
540539
541- await Task . Delay ( s_delayInMilliseconds ) ; // Wait for completions to be stored
540+ await DelayIfNotInPlaybackAsync ( s_delayInMilliseconds ) ; // Wait for completions to be stored
542541
543542 // Test with combined filters
544543 ChatCompletionCollectionOptions combinedOptions = new ( )
@@ -595,7 +594,7 @@ await TestHelpers.RetryWithExponentialBackoffAsync(async () =>
595594 Assert . That ( deletionResult . Deleted , Is . True ) ;
596595 } ) ;
597596
598- await Task . Delay ( s_delayInMilliseconds ) ;
597+ await DelayIfNotInPlaybackAsync ( s_delayInMilliseconds ) ;
599598
600599 Assert . ThrowsAsync < ClientResultException > ( async ( ) =>
601600 {
@@ -661,7 +660,7 @@ public async Task UpdateChatCompletionWorks_PM()
661660 [ new UserChatMessage ( "Say `this is a test`." ) ] ,
662661 initialOptions ) ;
663662
664- await Task . Delay ( s_delayInMilliseconds ) ; // Wait for completions to be stored
663+ await DelayIfNotInPlaybackAsync ( s_delayInMilliseconds ) ; // Wait for completions to be stored
665664
666665 var updateOptions = new UpdateChatCompletionOptions ( )
667666 {
@@ -672,15 +671,15 @@ [new UserChatMessage("Say `this is a test`.")],
672671
673672 ChatCompletionResult updated = await client . UpdateChatCompletionAsync ( updateOptions ) ;
674673
675- await Task . Delay ( s_delayInMilliseconds ) ; // Wait for completions to be updated
674+ await DelayIfNotInPlaybackAsync ( s_delayInMilliseconds ) ; // Wait for completions to be updated
676675
677676 Assert . That ( updated , Is . Not . Null ) ;
678677 Assert . That ( updated . Id , Is . EqualTo ( chatCompletion . Id ) ) ;
679678
680679 ChatCompletionDeletionResult deletionResult = await client . DeleteChatCompletionAsync ( chatCompletion . Id ) ;
681680 Assert . That ( deletionResult . Deleted , Is . True ) ;
682681
683- await Task . Delay ( s_delayInMilliseconds ) ; // Wait for completions to be deleted
682+ await DelayIfNotInPlaybackAsync ( s_delayInMilliseconds ) ; // Wait for completions to be deleted
684683
685684 Assert . ThrowsAsync < ClientResultException > ( async ( ) =>
686685 {
@@ -704,7 +703,7 @@ public async Task GetChatCompletionsValidatesCollectionEnumeration()
704703 [ "Enumeration test: Say 'Test enumeration'" ] ,
705704 createOptions ) ;
706705
707- await Task . Delay ( 5000 ) ; // Wait for completion to be stored
706+ await DelayIfNotInPlaybackAsync ( 5000 ) ; // Wait for completion to be stored
708707
709708 // Test that we can enumerate multiple times
710709 ChatCompletionCollectionOptions collectionOptions = new ( )
@@ -758,7 +757,7 @@ public async Task GetChatCompletionsHandlesLargeLimits()
758757 [ "Large limit test: Say 'Testing large limits'" ] ,
759758 createOptions ) ;
760759
761- await Task . Delay ( s_delayInMilliseconds ) ; // Wait for completions to be stored
760+ await DelayIfNotInPlaybackAsync ( s_delayInMilliseconds ) ; // Wait for completions to be stored
762761
763762 // Test with a large page size limit
764763 ChatCompletionCollectionOptions largeOptions = new ( )
@@ -799,7 +798,7 @@ public async Task GetChatCompletionsWithMinimalLimits()
799798 [ "Minimal limit test: Say 'Testing minimal limits'" ] ,
800799 createOptions ) ;
801800
802- await Task . Delay ( s_delayInMilliseconds ) ; // Wait for completions to be stored
801+ await DelayIfNotInPlaybackAsync ( s_delayInMilliseconds ) ; // Wait for completions to be stored
803802
804803 // Test with minimal page size
805804 ChatCompletionCollectionOptions minimalOptions = new ( )
0 commit comments